uc3-dmp-id 0.0.104 → 0.0.106

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: f281a066200306c56a78470094fe5924fab333221e1bcdd4dcaade896d0e02ff
4
- data.tar.gz: fa4b3f82159d32df245267596f3dd9d559f82c4faf07175a712448e2b2d7dd6c
3
+ metadata.gz: 23097d67b2f230b8c3a194cc3eed7c31f7f90056b7a8e0fae5c2d72af09a9927
4
+ data.tar.gz: e517ebc36f9ecddc28723d0334626ff348a95e9f91b050fbc938b628e04aae64
5
5
  SHA512:
6
- metadata.gz: a35bccc8f9a1b3a4bd475ba63151c082d5a263594454f0670e5b90800bc525d381e5191054102924c4220303648904d5c11562313360b4638def9b3aea98234e
7
- data.tar.gz: ebbbef1978d20fad47c45bb75f1e242e4d583fc8f3107b7370a187679ce77d8adf2679178399ab85339ba1ec2ca6e7026345dd3ebfae0534343feec270ce9b9f
6
+ metadata.gz: 619e35ef6240834357d62e57dcab4c70359085fff7d73d31f0505361c836c38749b35fc3b7d27967a7c7415dd49cb6de61df6b8076d714d0d329160badb7f751
7
+ data.tar.gz: 97d30d99e8ff0e258507f6830b10bede00c88538d3b36f3c8a1fd63711d14f0e1a32730a1fb3a196dfe1c4c99555db8eec2a8cc2b18017e617e242cb38bf0881
@@ -49,14 +49,14 @@ puts "MODIFIED_VERSION ASSERTIONS: #{modified_version['dmphub_assertions']}"
49
49
  logger.debug(message: "Incoming modifications", details: incoming_assertions) if logger.respond_to?(:debug)
50
50
 
51
51
  # Keep any assetions that were made after the dmphub_updated_at on the incoming changes
52
- latest_version['dmphub_assertions'] = existing_assertions.select do |entry|
52
+ modified_version['dmphub_assertions'] = existing_assertions.select do |entry|
53
53
  !entry['timestamp'].nil? && Time.parse(entry['timestamp']) > Time.parse(modified_version['dmphub_updated_at'])
54
54
  end
55
- return latest_version unless incoming_assertions.any?
55
+ return modified_version unless incoming_assertions.any?
56
56
 
57
57
  # Add any of the assertions still on the incoming record back to the latest record
58
- incoming_assertions.each { |entry| latest_version['dmphub_assertions'] << entry }
59
- latest_version
58
+ incoming_assertions.each { |entry| modified_version['dmphub_assertions'] << entry }
59
+ modified_version
60
60
  end
61
61
 
62
62
  private
@@ -49,6 +49,9 @@ puts version
49
49
  version = _process_modifications(owner: owner, updater: updater, version: version, mods: mods, note: note,
50
50
  logger: logger)
51
51
 
52
+ puts "AFTER PROCESING MODS:"
53
+ puts version
54
+
52
55
  # Save the changes
53
56
  resp = client.put_item(json: version, logger: logger)
54
57
  raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
@@ -107,21 +110,32 @@ puts version
107
110
  end
108
111
 
109
112
  def _process_modifications(owner:, updater:, version:, mods:, note: nil, logger: nil)
110
-
111
- puts "OWNER: #{owner}, UPDATER #{updater}, Version is Hash? #{version.is_a?(Hash)}, Mods is Hash? #{mods.is_a?(Hash)}"
112
-
113
- puts "Returning version? #{!mods.is_a?(Hash) || updater.nil?}"
114
- puts "Returning mods? #{!version.is_a?(Hash) || owner.nil?}"
115
-
116
113
  return version unless mods.is_a?(Hash) && !updater.nil?
117
114
  return mods unless version.is_a?(Hash) && !owner.nil?
118
115
 
119
- puts "Asserting!"
120
-
121
116
  # Splice together any assertions that may have been made while the user was editing the DMP ID
122
- Asserter.splice(latest_version: version, modified_version: mods, logger: logger) if owner == updater
117
+ updated = Asserter.splice(latest_version: version, modified_version: mods, logger: logger) if owner == updater
118
+
123
119
  # Attach the incoming changes as an assertion to the DMP ID since the updater is NOT the owner
124
- Asserter.add(updater: provenance['PK'], dmp: version, mods: mods, note: note, logger: logger) if owner != updater
120
+ updater = provenance['PK']
121
+ updated = Asserter.add(updater: updater, dmp: version, mods: mods, note: note, logger: logger) if owner != updater
122
+
123
+ merge_versions(latest_version: version, mods: updated, logger: logger)
124
+ end
125
+
126
+ # We are replacing the latest version with the modifcations but want to retain the PK, SK and any dmphub_ prefixed
127
+ # entries in the metadata so that we do not lose creation timestamps, provenance ids, etc.
128
+ def merge_versions(latest_version:, mods:, logger: nil)
129
+ logger.debug(message: 'Modifications before merge.', details: mods)
130
+ keys_to_retain = latest_version.keys.select do |key|
131
+ (key.start_with?('dmphub_') && !%w[dmphub_assertions].include?(key)) ||
132
+ key.start_with?('PK') || key.start_with?('SK')
133
+ end
134
+ keys_to_retain.each do |key|
135
+ mods[key] = latest_version[key]
136
+ end
137
+ logger.debug(message: 'Modifications after merge.', details mods)
138
+ mods
125
139
  end
126
140
 
127
141
  # Once the DMP has been updated, we need to update it's DOI metadata
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.104'
4
+ VERSION = '0.0.106'
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.104
4
+ version: 0.0.106
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley