uc3-dmp-id 0.0.60 → 0.0.62

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc2cccff208ffef601a91dc92d6cd2e3ed5b517fd47e09254ff7fea2572ea928
4
- data.tar.gz: 32ed9cdab64dcc03154eacb748ad3fe9bde7ee61d4080874092381c3ffc59c09
3
+ metadata.gz: 8d86231b0d9bbba113c84fca3f8496f7a1d09eb07386b13f3a8082d1b79d9cd5
4
+ data.tar.gz: 4c5bdfeda6ad713e7a77e6bb6cc27f5942dc170fe477920a40f42da43ff00f40
5
5
  SHA512:
6
- metadata.gz: c65520e657194a50a53c6fa88d5e5e43ae471c8d7ac5a56b5da1d3b16bbf0932b90eb42f01674141afbd3577ac071e02c77e8accb7d0e3c3eb150e8344a8bca7
7
- data.tar.gz: 5ab9a028be14f33f10031ef3530d78e2f9d09fb496c9a8225f664fa307de50b8a3fb2fbb1615bc4e0226a3197273a440b3aa00bdf955e25b92dc117716cc905f
6
+ metadata.gz: 55a11fcf0cae95da912fde23d91b10a4cb0b0aed0fe607bab4a6db267e59030faa1c7d53b40bb9780888646bf530c296c9d9532a5b2ed77ab892af4606579ba2
7
+ data.tar.gz: b305efdd75d24efc03ed9a792b7c8b04c3c530618071440c651a65f46f1a60b68d73e01185acbb65f928f4d34dfe35d733ee8ee39ef5af3afc41a23c7ca55b65
@@ -133,6 +133,14 @@ module Uc3DmpId
133
133
  a == b
134
134
  end
135
135
 
136
+ # Extract the Contact's affiliaiton ROR ID
137
+ def extract_owner_org(json: {})
138
+ return nil unless json.is_a?(Hash)
139
+
140
+ dmp = json['dmp'].nil? ? json : json['dmp']
141
+ owner_org = dmp.fetch('contact', {}).fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
142
+ end
143
+
136
144
  # Add DMPHub specific fields to the DMP ID JSON
137
145
  def annotate_dmp_json(provenance:, owner_org:, p_key:, json:)
138
146
  json = parse_json(json: json)
@@ -143,7 +151,7 @@ module Uc3DmpId
143
151
  return json if id != p_key && !json['PK'].nil?
144
152
 
145
153
  annotated = deep_copy_dmp(obj: json)
146
- annotated['PK'] = json['PK'] || p_key
154
+ annotated['PK'] = json['PK'] || append_pk_prefix(p_key: p_key)
147
155
  annotated['SK'] = DMP_LATEST_VERSION
148
156
 
149
157
  # Ensure that the :dmp_id matches the :PK
@@ -46,23 +46,25 @@ module Uc3DmpId
46
46
  # fetch the existing latest version of the DMP ID
47
47
  client = Uc3DmpDynamo::Client.new(debug: debug)
48
48
  dmp = Finder.by_pk(p_key: p_key, client: client, debug: debug)
49
- # Don't continue if nothing has changed!
50
- raise UpdaterError, MSG_DMP_NOT_FOUND if dmp.nil?
49
+ owner_org = Helper.extract_owner_org(json: dmp)
50
+ # Don't continue if DMP ID could not be found or the contact has no identifier (should be impossible)
51
+ raise UpdaterError, MSG_DMP_NOT_FOUND if dmp.nil? || owner_org.nil?
51
52
 
52
53
  errs = _updateable?(provenance: provenance, p_key: p_key, json: dmp['dmp'])
53
54
  raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
54
55
 
55
- # Add the DMPHub specific attributes
56
- dmp['dmp']['dmproadmap_related_identifiers'] = [] if dmp['dmp']['dmproadmap_related_identifiers'].nil?
57
- dmp['dmp']['dmproadmap_related_identifiers'] << {
56
+ # Add the DMPHub specific attributes and then add the download URl for the PDF
57
+ annotated = Helper.annotate_dmp_json(provenance: provenance, owner_org: owner_org, p_key: p_key, json: dmp['dmp'])
58
+ annotated['dmproadmap_related_identifiers'] = [] if annotated['dmproadmap_related_identifiers'].nil?
59
+ annotated['dmproadmap_related_identifiers'] << {
58
60
  descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
59
61
  }
60
62
 
61
63
  puts "Attached:"
62
- puts dmp
64
+ puts annotated
63
65
 
64
- # Save the changes as the new latest version
65
- resp = client.put_item(json: dmp['dmp'], debug: debug)
66
+ # Save the changes without creating a new version!
67
+ resp = client.put_item(json: annotated, debug: debug)
66
68
  raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
67
69
 
68
70
  true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.60'
4
+ VERSION = '0.0.62'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.60
4
+ version: 0.0.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley