Class: ExternalDocument

Inherits:
Sequel::Model
  • Object
show all
Includes:
ASModel, Publishable
Defined in:
backend/app/model/external_document.rb

Direct Known Subclasses

RightsStatementExternalDocument

Constant Summary

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Publishable

db_value_for, included

Methods included from ASModel

all_models, included, update_publish_flag, update_suppressed_flag

Methods included from JSONModel

JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository

Class Method Details

.create_from_json(json, opts = {}) ⇒ Object



35
36
37
# File 'backend/app/model/external_document.rb', line 35

def self.create_from_json(json, opts = {})
  super(json, opts.merge(:location_sha1 => generate_location_sha1(json)))
end

.generate_location_sha1(json) ⇒ Object



31
32
33
# File 'backend/app/model/external_document.rb', line 31

def self.generate_location_sha1(json)
  Digest::SHA1.hexdigest(json.location + json.title )
end

Instance Method Details

#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object



39
40
41
42
# File 'backend/app/model/external_document.rb', line 39

def update_from_json(json, opts = {}, apply_nested_records = true)
  self[:location_sha1] = self.class.generate_location_sha1(json)
  super
end

#validateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'backend/app/model/external_document.rb', line 11

def validate
  [:accession, :archival_object,
   :resource, :subject,
   :agent_person,
   :agent_family,
   :agent_corporate_entity,
   :agent_software,
   :rights_statement,
   :digital_object,
   :digital_object_component].each do |record|

    validates_unique([:location_sha1, "#{record}_id".intern],
                      :message => "location and title must have unique values within a record")

    map_validation_to_json_property([:location_sha1, "#{record}_id".intern], :location)
  end

  super
end