Class: ArkMinter

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/ark/ark_minter.rb

Direct Known Subclasses

ArchivesSpaceArkMinter, SmithsonianArkMinter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_version_key(*version_grist) ⇒ Object

Hash some values together and return a string.



89
90
91
# File 'backend/app/lib/ark/ark_minter.rb', line 89

def self.generate_version_key(*version_grist)
  Digest::SHA256.hexdigest(version_grist.map(&:to_s).to_json)
end

Instance Method Details

#ark_recognized?(ark) ⇒ Boolean

Return true if a given ARK string can be assumed to have been generated by the current ARK minter. Used during import to determine how to handle incoming ARK strings.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


63
64
65
# File 'backend/app/lib/ark/ark_minter.rb', line 63

def ark_recognized?(ark)
  raise NotImplementedError.new
end

#is_still_current?(ark_name_obj, obj) ⇒ Boolean

Return true if the provided ark name still looks right. Reasons it might not look right include: changed NAAN, changed repository shoulder. Stuff like that.

The version_key column in the ark_name table can be used to hold a minter-specific value to record the conditions under which each Ark was generated. For example, the default minter (archivesspace_ark_minter.rb) stores a hash containing the Ark NAAN & repository shoulder that were in use at the point each Ark was generated. Its is_still_current? can then recalculate that hash (using generate_version_key below) to determine if the Ark needs to be recomputed.

Returns:

  • (Boolean)


77
78
79
# File 'backend/app/lib/ark/ark_minter.rb', line 77

def is_still_current?(ark_name_obj, obj)
  ark_name_obj.version_key == version_key_for(obj)
end

#mint!(obj, row_defaults) ⇒ Object

Raises:

  • (NotImplementedError)


56
57
58
# File 'backend/app/lib/ark/ark_minter.rb', line 56

def mint!(obj, row_defaults)
  raise NotImplementedError.new
end

#shoulder_for_repo(repo_id) ⇒ Object

Caching shoulder lookup for bulk record creation (like imports)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'backend/app/lib/ark/ark_minter.rb', line 94

def shoulder_for_repo(repo_id)
  if RequestContext.get(:repo_ark_shoulders).nil?
    RequestContext.put(:repo_ark_shoulders, {})
  end

  shoulders = RequestContext.get(:repo_ark_shoulders)

  if !shoulders.include?(repo_id)
    DB.open do |db|
      shoulders[repo_id] = db[:repository].filter(:id => repo_id).get(:ark_shoulder)
    end
  end

  shoulders[repo_id]
end

#version_key_for(obj) ⇒ Object

Return an opaque value that captures any values that will be used to generate an ARK for obj. Default implementation just hashes together the bits of data the provided minters use for generating ARKs.



84
85
86
# File 'backend/app/lib/ark/ark_minter.rb', line 84

def version_key_for(obj)
  ArkMinter.generate_version_key(AppConfig[:ark_naan], shoulder_for_repo(obj.repo_id), AppConfig[:ark_shoulder_delimiter], AppConfig[:ark_minter])
end