uc3-dmp-id 0.0.62 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d86231b0d9bbba113c84fca3f8496f7a1d09eb07386b13f3a8082d1b79d9cd5
4
- data.tar.gz: 4c5bdfeda6ad713e7a77e6bb6cc27f5942dc170fe477920a40f42da43ff00f40
3
+ metadata.gz: 9a0c6efaee7727ad373bdccdc9184e12d1abefafe3834768c210d949d854c669
4
+ data.tar.gz: 0c771250b7459256822a87dc99bdbc720ebca8cc2f4d5a5c53ccfcf5a8a0d0aa
5
5
  SHA512:
6
- metadata.gz: 55a11fcf0cae95da912fde23d91b10a4cb0b0aed0fe607bab4a6db267e59030faa1c7d53b40bb9780888646bf530c296c9d9532a5b2ed77ab892af4606579ba2
7
- data.tar.gz: b305efdd75d24efc03ed9a792b7c8b04c3c530618071440c651a65f46f1a60b68d73e01185acbb65f928f4d34dfe35d733ee8ee39ef5af3afc41a23c7ca55b65
6
+ metadata.gz: 98025dcd7ccdd69b284b910d8391a715c2b2b72799398cf432bf1688efc25b22caf7f25e5b5ca0eb2d528b7256703304f287fa15b92cc9df6ce96d4aa4e7c738
7
+ data.tar.gz: bdc3d64ec36a853aca5ec44d32a415b65dc868b83c3bd48ce4054aae2a546a8005b3f25400d6bd759ef8fb6085e1f0bdfea16c1b4b6e178e1861e443a9a1cb3e
@@ -47,7 +47,7 @@ module Uc3DmpId
47
47
  raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
48
48
 
49
49
  _post_process(json: annotated, debug: debug)
50
- annotated
50
+ Helper.cleanse_dmp_json(json: JSON.parse({ dmp: annotated }.to_json))
51
51
  end
52
52
 
53
53
  private
@@ -155,7 +155,7 @@ module Uc3DmpId
155
155
  annotated['SK'] = DMP_LATEST_VERSION
156
156
 
157
157
  # Ensure that the :dmp_id matches the :PK
158
- annotated['dmp_id'] = pk_to_dmp_id(p_key: annotated['PK'])
158
+ annotated['dmp_id'] = pk_to_dmp_id(p_key: remove_pk_prefix(p_key: annotated['PK']))
159
159
 
160
160
  # Update the modification timestamps
161
161
  annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
@@ -182,6 +182,9 @@ module Uc3DmpId
182
182
  def cleanse_dmp_json(json:)
183
183
  return json unless json.is_a?(Hash) || json.is_a?(Array)
184
184
 
185
+ puts "Cleansing DMP JSON:"
186
+ puts json
187
+
185
188
  # If it's an array clean each of the objects individually
186
189
  return json.map { |obj| cleanse_dmp_json(json: obj) }.compact if json.is_a?(Array)
187
190
 
@@ -10,96 +10,93 @@ module Uc3DmpId
10
10
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
11
11
  # -------------------------------------------------------------------------
12
12
  def update(provenance:, p_key:, json: {})
13
- raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
14
-
15
- dmp = Helper.parse_json(json: json)
16
- errs = _updateable?(provenance: provenance, p_key: p_key, dmp: dmp)
17
- raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
18
-
19
- # Add the DMPHub specific attributes
20
- annotated = Helper.annotate_dmp(provenance: provenance, json: dmp['dmp'], p_key: p_key)
21
-
22
- # fetch the existing latest version of the DMP ID
23
- client = Uc3DmpDynamo::Client.new(debug: debug)
24
- existing = Finder.by_pk(p_key: p_key, client: client, debug: debug)
25
- # Don't continue if nothing has changed!
26
- raise UpdaterError, MSG_NO_CHANGE if Helper.eql?(dmp_a: existing, dmp_b: annotated)
27
-
28
- # Generate a new version of the DMP. This involves versioning the current latest version
29
- new_version = versioner.new_version(p_key: p_key, dmp: json)
30
- raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if new_version.nil?
31
-
32
- # Save the changes as the new latest version
33
- resp = client.put_item(json: new_version, debug: debug)
34
- raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
35
-
36
- # Send the updates to EZID, notify the provenance and download the PDF if applicable
37
- _post_process(json: dmp, debug: debug)
38
- resp
39
- end
40
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
41
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
42
-
43
- def attach_narrative(provenance:, p_key:, url:, debug: false)
44
- raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
45
-
46
- # fetch the existing latest version of the DMP ID
47
- client = Uc3DmpDynamo::Client.new(debug: debug)
48
- dmp = Finder.by_pk(p_key: p_key, client: client, debug: debug)
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?
52
-
53
- errs = _updateable?(provenance: provenance, p_key: p_key, json: dmp['dmp'])
54
- raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
55
-
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'] << {
60
- descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
61
- }
62
-
63
- puts "Attached:"
64
- puts annotated
65
-
66
- # Save the changes without creating a new version!
67
- resp = client.put_item(json: annotated, debug: debug)
68
- raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
69
-
70
- true
71
- end
72
-
73
- private
74
-
75
- # Check if the DMP ID is updateable by the provenance
76
- def _updateable?(provenance:, p_key:, json:)
77
- # Validate the incoming JSON first
78
- errs = Validator.validate(mode: 'author', json: json)
79
- return errs.join(', ') if errs.is_a?(Array) && errs.any? && errs.first != Validator::MSG_VALID_JSON
80
-
81
- # Fail if the provenance is not defined
82
- return [MSG_DMP_FORBIDDEN] unless provenance.is_a?(Hash) && !provenance['PK'].nil?
83
-
84
- # Verify that the JSON is for the same DMP in the PK
85
- dmp_id = json.fetch('dmp_id', {})
86
- return [MSG_DMP_FORBIDDEN] unless Helper.dmp_id_to_pk(json: dmp_id) == p_key
87
- # Make sure they're not trying to update a historical copy of the DMP
88
- return [MSG_DMP_NO_HISTORICALS] if json['SK'] != Helper::DMP_LATEST_VERSION
89
- end
90
-
91
- # Once the DMP has been updated, we need to register it's DMP ID and download any PDF if applicable
92
- # -------------------------------------------------------------------------
93
- def _post_process(json:, debug: false)
94
- return false unless json.is_a?(Hash)
95
-
96
- # Indicate whether or not the updater is the provenance system
97
- json['dmphub_updater_is_provenance'] = @provenance['PK'] == json['dmphub_provenance_id']
98
- # Publish the change to the EventBridge
99
- publisher = Uc3DmpEventBridge::Publisher.new
100
- publisher.publish(source: 'DmpUpdater', dmp: json, debug: debug)
101
- true
102
- end
13
+ raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
14
+
15
+ dmp = Helper.parse_json(json: json)
16
+ errs = _updateable?(provenance: provenance, p_key: p_key, dmp: dmp)
17
+ raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
18
+
19
+ # Add the DMPHub specific attributes
20
+ annotated = Helper.annotate_dmp(provenance: provenance, json: dmp['dmp'], p_key: p_key)
21
+
22
+ # fetch the existing latest version of the DMP ID
23
+ client = Uc3DmpDynamo::Client.new(debug: debug)
24
+ existing = Finder.by_pk(p_key: p_key, client: client, debug: debug)
25
+ # Don't continue if nothing has changed!
26
+ raise UpdaterError, MSG_NO_CHANGE if Helper.eql?(dmp_a: existing, dmp_b: annotated)
27
+
28
+ # Generate a new version of the DMP. This involves versioning the current latest version
29
+ new_version = versioner.new_version(p_key: p_key, dmp: json)
30
+ raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if new_version.nil?
31
+
32
+ # Save the changes as the new latest version
33
+ resp = client.put_item(json: new_version, debug: debug)
34
+ raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
35
+
36
+ # Send the updates to EZID, notify the provenance and download the PDF if applicable
37
+ _post_process(json: dmp, debug: debug)
38
+ resp
39
+ end
40
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
41
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
42
+
43
+ def attach_narrative(provenance:, p_key:, url:, debug: false)
44
+ raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
45
+
46
+ # fetch the existing latest version of the DMP ID
47
+ client = Uc3DmpDynamo::Client.new(debug: debug)
48
+ dmp = Finder.by_pk(p_key: p_key, client: client, debug: debug)
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?
52
+
53
+ errs = _updateable?(provenance: provenance, p_key: p_key, json: dmp['dmp'])
54
+ raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
55
+
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'] << {
60
+ descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
61
+ }
62
+
63
+ # Save the changes without creating a new version!
64
+ resp = client.put_item(json: annotated, debug: debug)
65
+ raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
66
+
67
+ true
68
+ end
69
+
70
+ private
71
+
72
+ # Check if the DMP ID is updateable by the provenance
73
+ def _updateable?(provenance:, p_key:, json:)
74
+ # Validate the incoming JSON first
75
+ errs = Validator.validate(mode: 'author', json: json)
76
+ return errs.join(', ') if errs.is_a?(Array) && errs.any? && errs.first != Validator::MSG_VALID_JSON
77
+
78
+ # Fail if the provenance is not defined
79
+ return [MSG_DMP_FORBIDDEN] unless provenance.is_a?(Hash) && !provenance['PK'].nil?
80
+
81
+ # Verify that the JSON is for the same DMP in the PK
82
+ dmp_id = json.fetch('dmp_id', {})
83
+ return [MSG_DMP_FORBIDDEN] unless Helper.dmp_id_to_pk(json: dmp_id) == p_key
84
+ # Make sure they're not trying to update a historical copy of the DMP
85
+ return [MSG_DMP_NO_HISTORICALS] if json['SK'] != Helper::DMP_LATEST_VERSION
86
+ end
87
+
88
+ # Once the DMP has been updated, we need to register it's DMP ID and download any PDF if applicable
89
+ # -------------------------------------------------------------------------
90
+ def _post_process(json:, debug: false)
91
+ return false unless json.is_a?(Hash)
92
+
93
+ # Indicate whether or not the updater is the provenance system
94
+ json['dmphub_updater_is_provenance'] = @provenance['PK'] == json['dmphub_provenance_id']
95
+ # Publish the change to the EventBridge
96
+ publisher = Uc3DmpEventBridge::Publisher.new
97
+ publisher.publish(source: 'DmpUpdater', dmp: json, debug: debug)
98
+ true
99
+ end
103
100
  end
104
101
  end
105
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.62'
4
+ VERSION = '0.0.64'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.62
4
+ version: 0.0.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json