updating relation meta for resource copy and versioning
@@ -412,9 +412,8 @@ def copy_resource_task(ori_res_id, new_res_id=None, request_username=None):
new_res = utils.get_resource_by_shortkey(new_res_id)
utils.copy_and_create_metadata(ori_res, new_res)
- hs_identifier = ori_res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
- if hs_identifier:
- new_res.metadata.create_element('source', derived_from=hs_identifier.url)
+ # create the relation element for the new_res
+ new_res.metadata.create_element('relation', type='source', value=ori_res.get_citation())
if ori_res.resource_type.lower() == "collectionresource":
# clone contained_res list of original collection and add to new collection
@@ -456,8 +455,7 @@ def create_new_version_resource_task(ori_res_id, username, new_res_id=None):
utils.copy_and_create_metadata(ori_res, new_res)
# add or update Relation element to link source and target resources
- hs_identifier = new_res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
- ori_res.metadata.create_element('relation', type='isReplacedBy', value=hs_identifier.url)
+ ori_res.metadata.create_element('relation', type='isReplacedBy', value=new_res.get_citation())
if new_res.metadata.relations.all().filter(type='isVersionOf').exists():
# the original resource is already a versioned resource, and its isVersionOf relation
@@ -466,8 +464,7 @@ def create_new_version_resource_task(ori_res_id, username, new_res_id=None):
eid = new_res.metadata.relations.all().filter(type='isVersionOf').first().id
new_res.metadata.delete_element('relation', eid)
- hs_identifier = ori_res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
- new_res.metadata.create_element('relation', type='isVersionOf', value=hs_identifier.url)
+ new_res.metadata.create_element('relation', type='isVersionOf', value=ori_res.get_citation())
if ori_res.resource_type.lower() == "collectionresource":
# clone contained_res list of original collection and add to new collection
