Skip to content

Commit

Permalink
fixed issue with schema relationship link fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hdosprazeres committed Aug 29, 2024
1 parent 0a22f95 commit 7391b18
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
6 changes: 3 additions & 3 deletions dinapy/schemas/BaseSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class BaseSchema(Schema):
id = fields.Str(dump_only=True,allow_none=True)
type = fields.Str(allow_none=True)

def create_relationship(type, key=None):
def create_relationship(parent_type, type, key=None):
return fields.Relationship(
self_url=f"/api/v1/material-sample/{{id}}/relationships/{key if key else type}",
self_url=f"/api/v1/{parent_type}/{{id}}/relationships/{key if key else type}",
self_url_kwargs={"id": "<id>"},
related_url=f"/api/v1/material-sample/{{id}}/{key if key else type}",
related_url=f"/api/v1/{parent_type}/{{id}}/{key if key else type}",
related_url_kwargs={"id": "<id>"},
allow_none=True,
include_resource_linkage=True,
Expand Down
23 changes: 19 additions & 4 deletions dinapy/schemas/collectingeventschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ class Protocol(BaseSchema):

class Meta:
type_ = 'protocol'

class CollectionMethod(BaseSchema):

class Meta:
type_ = 'collection-method'

class Collectors(BaseSchema):

class Meta:
type_ = 'collectors'

class Attachment(BaseSchema):

class Meta:
type_ = 'attachment'

class CollectingEventSchema(Schema):
'''Schema for a Collecting Event used for serializing and deserializing JSON.'''
Expand Down Expand Up @@ -55,10 +70,10 @@ class CollectingEventSchema(Schema):
managedAttributes = SkipUndefinedField(fields.Dict,attribute="attributes.managedAttributes")
remarks = SkipUndefinedField(fields.Str,allow_none=True, attribute="attributes.remarks")

collectionMethod = create_relationship("collectionMethod")
protocol = create_relationship("protocol")
collectors = create_relationship("collectors")
attachment = create_relationship("attachment")
collectionMethod = create_relationship("collecting-event","collectionMethod")
protocol = create_relationship("collecting-event","protocol")
collectors = create_relationship("collecting-event","collectors")
attachment = create_relationship("collecting-event","attachment")

meta = fields.DocumentMeta()

Expand Down
24 changes: 12 additions & 12 deletions dinapy/schemas/materialsampleschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ def object_deserialization(self, data, **kwargs):
del data['meta']
return MaterialSampleDTO(**data)

collection = create_relationship("collection")
collectingEvent = create_relationship("collectingEvent")
preparationType = create_relationship("preparationType")
preparationMethod = create_relationship("preparationMethod")
parentMaterialSample = create_relationship("parentMaterialSample")
preparedBy = create_relationship("preparedBy")
attachment = create_relationship("attachment")
preparationProtocol = create_relationship("preparationProtocol")
projects = create_relationship("projects")
assemblages = create_relationship("assemblages")
organism = create_relationship("organism")
storageUnit = create_relationship("storageUnit")
collection = create_relationship("material-sample","collection")
collectingEvent = create_relationship("material-sample","collectingEvent")
preparationType = create_relationship("material-sample","preparationType")
preparationMethod = create_relationship("material-sample","preparationMethod")
parentMaterialSample = create_relationship("material-sample","parentMaterialSample")
preparedBy = create_relationship("material-sample","preparedBy")
attachment = create_relationship("material-sample","attachment")
preparationProtocol = create_relationship("material-sample","preparationProtocol")
projects = create_relationship("material-sample","projects")
assemblages = create_relationship("material-sample","assemblages")
organism = create_relationship("material-sample","organism")
storageUnit = create_relationship("material-sample","storageUnit")

meta = fields.DocumentMeta()

Expand Down
6 changes: 3 additions & 3 deletions dinapy/schemas/metadata_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ class MetadataSchema(Schema):
)

# Relationships
acMetadataCreator = create_relationship("person", "acMetadataCreator")
acMetadataCreator = create_relationship("metadata","person", "acMetadataCreator")

derivatives = create_relationship("derivatives")
derivatives = create_relationship("metadata","derivatives")

dcCreator = create_relationship("person", "dcCreator")
dcCreator = create_relationship("metadata","person", "dcCreator")

@post_load
def set_none_to_undefined(self, data, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions dinapy/schemas/storageunitusageschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class StorageUnitUsage(Schema):
createdOn = SkipUndefinedField(fields.DateTime, load_only=True,attribute="attributes.createdOn")
createdBy = SkipUndefinedField(fields.Str, load_only=True,attribute="attributes.createdBy")

storageUnit = create_relationship("storageUnit")
storageUnitType = create_relationship("storageUnitType")
storageUnit = create_relationship("storage-unit-usage","storageUnit")
storageUnitType = create_relationship("storage-unit-usage","storageUnitType")

@post_load
def set_none_to_undefined(self, data, **kwargs):
Expand Down
6 changes: 5 additions & 1 deletion tests/collecting_event_schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@
"links": {
"self": "/api/v1/collecting-event/f08516e5-add2-4baa-89bc-5b8abd0ec8ba/relationships/collectionMethod",
"related": "/api/v1/collecting-event/f08516e5-add2-4baa-89bc-5b8abd0ec8ba/collectionMethod"
}
},
"data": {
"id": "01902d3a-0ec1-7a57-8284-f4ba3aff1664",
"type": "collection-method",
},
},
"protocol": {
"links": {
Expand Down

0 comments on commit 7391b18

Please sign in to comment.