Class: Uc3DmpId::Deleter
- Inherits:
-
Object
- Object
- Uc3DmpId::Deleter
- Defined in:
- lib/uc3-dmp-id/deleter.rb
Overview
Utility to Tombstone DMP ID’a
Class Method Summary collapse
-
.tombstone(provenance:, p_key:, logger: nil) ⇒ Object
Delete/Tombstone a record in the table rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity ————————————————————————-.
Class Method Details
.tombstone(provenance:, p_key:, logger: nil) ⇒ Object
Delete/Tombstone a record in the table rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/uc3-dmp-id/deleter.rb', line 14 def tombstone(provenance:, p_key:, logger: nil) raise DeleterError, Helper::MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty? # Fail if the provenance is not defined raise DeleterError, Helper::MSG_DMP_FORBIDDEN unless provenance.is_a?(Hash) && !provenance['PK'].nil? # Fetch the latest version of the DMP ID by it's PK client = Uc3DmpDynamo::Client.new dmp = Finder.by_pk(p_key:, client:, cleanse: false, logger:) raise DeleterError, Helper::MSG_DMP_NOT_FOUND unless dmp.is_a?(Hash) && !dmp['dmp'].nil? # Only allow this if the provenance is the owner of the DMP! raise DeleterError, Helper::MSG_DMP_FORBIDDEN if dmp['dmp']['dmphub_provenance_id'] != provenance['PK'] # Make sure they're not trying to update a historical copy of the DMP raise DeleterError, Helper::MSG_DMP_NO_HISTORICALS if dmp['dmp']['SK'] != Helper::DMP_LATEST_VERSION # Annotate the DMP ID dmp['dmp']['SK'] = Helper::DMP_TOMBSTONE_VERSION dmp['dmp']['title'] = "OBSOLETE: #{dmp['dmp']['title']}" logger.info(message: "Tombstoning DMP ID: #{p_key}") if logger.respond_to?(:debug) # Set the :modified timestamps now = Time.now.utc.iso8601 dmp['dmp']['modified'] = now dmp['dmp']['dmphub_tombstoned_at'] = now # Create the Tombstone version resp = client.put_item(json: dmp['dmp'], logger:) raise DeleterError, Helper::MSG_DMP_NO_TOMBSTONE if resp.nil? # Delete the Latest version client.delete_item(p_key:, s_key: Helper::DMP_LATEST_VERSION, logger:) # TODO: We should do a check here to see if it was successful! # Notify EZID about the removal _post_process(json: dmp, logger:) # Return the tombstoned record Helper.cleanse_dmp_json(json: dmp) rescue Aws::Errors::ServiceError => e logger.error(message: e., details: e.backtrace) if logger.respond_to?(:error) raise DeleterError, Helper::MSG_SERVER_ERROR end |