Class: Resource

Inherits:
JSONModel
  • Object
show all
Includes:
ASModel, Agents, Classifications, CollectionManagements, ComponentsAddChildren, Dates, Deaccessions, Events, Extents, ExternalDocuments, ExternalIDs, Identifiers, Instances, MapToAspaceContainer, Notes, Publishable, ReindexTopContainers, Relationships, ResourceTrees, RevisionStatements, RightsRestrictionNotes, RightsStatements, Subjects, Trees, UserDefineds
Defined in:
backend/app/model/resource.rb,
frontend/app/models/resource.rb

Constant Summary

Constant Summary

Constants included from RightsRestrictionNotes

RightsRestrictionNotes::RESTRICTION_NOTE_TYPES

Constants included from Trees

Trees::NODE_PAGE_SIZE

Constants included from Identifiers

Identifiers::MAX_LENGTH

Instance Attribute Summary

Attributes included from Relationships

#cached_relationships

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from MapToAspaceContainer

included, mapper_to_aspace_json, mapper_to_managed_container, #update_from_json

Methods included from RightsRestrictionNotes

included, #update_from_json

Methods included from ReindexTopContainers

#delete, #reindex_top_containers, #reindex_top_containers_by_any_means_necessary, #update_from_json, #update_position_only

Methods included from RevisionStatements

included

Methods included from Publishable

db_value_for, included

Methods included from Events

included

Methods included from Classifications

included

Methods included from ComponentsAddChildren

#add_children, included

Methods included from UserDefineds

included

Methods included from CollectionManagements

included

Methods included from ExternalIDs

included

Methods included from Notes

included, #persistent_id_context, #update_from_json

Methods included from ResourceTrees

#build_node_query, #load_node_properties, #load_root_properties, #set_node_instances, #set_node_instances_pre_container_management, #set_node_level

Methods included from Trees

#adopt_children, #assimilate, #build_node_query, #children, included, #load_node_properties, #load_root_properties, #partial_tree, #transfer_to_repository, #tree, #trigger_index_of_entire_tree, #update_from_json

Methods included from Relationships

#assimilate, #cache_relationships, included, #my_relationships, #related_records, #transfer_to_repository, #trigger_reindex_of_dependants, #update_from_json

Methods included from Agents

included

Methods included from Deaccessions

included

Methods included from Instances

#eagerly_load!, included

Methods included from RightsStatements

included

Methods included from ExternalDocuments

included

Methods included from Dates

included

Methods included from Extents

included

Methods included from Subjects

included

Methods included from Identifiers

#after_initialize, #before_validation, format, #id_0=, #id_1=, #id_2=, #id_3=, included, parse, #validate

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, 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_repository, strict_mode, strict_mode?, with_repository

Constructor Details

- (Resource) initialize(values)

Returns a new instance of Resource



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'frontend/app/models/resource.rb', line 3

def initialize(values)
  super

  if !self.extents || self.extents.empty?
    self.extents = [JSONModel(:extent).new._always_valid!]
  end
  
  if !self.dates || self.dates.empty?
    self.dates = [JSONModel(:date).new._always_valid!]
  end

  self
end

Class Method Details

+ (Object) id_to_identifier(id)



50
51
52
53
# File 'backend/app/model/resource.rb', line 50

def self.id_to_identifier(id)
  res = Resource[id]
  [res[:id_0], res[:id_1], res[:id_2], res[:id_3]].compact.join(".")
end

Instance Method Details

- (Object) populate_from_accession(accession)



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
58
59
60
61
62
63
64
65
66
67
68
# File 'frontend/app/models/resource.rb', line 18

def populate_from_accession(accession)
  values = accession.to_hash(:raw)

  # Recursively remove bits that don't make sense to copy (like "lock_version"
  # properties)
  values = JSONSchemaUtils.map_hash_with_schema(values, JSONModel(:accession).schema,
                                                      [proc { |hash, schema|
                                                        hash = hash.clone
                                                        hash.delete_if {|k, v| k.to_s =~ /^(id_[0-9]|lock_version|instances|deaccessions|collection_management|user_defined|external_documents)$/}
                                                        hash
                                                      }])

  # We'll replace this with our own relationship, linking us back to the
  # accession we were spawned from.
  values.delete('related_accessions')

  notes ||= []

  if accession.content_description
    notes << JSONModel(:note_multipart).from_hash(:type => "scopecontent",
                                                  :label => I18n.t('accession.content_description'),
                                                  :subnotes => [{
                                                                  'content' => accession.content_description,
                                                                  'jsonmodel_type' => 'note_text'
                                                                }])
  end

  if accession.condition_description
    notes << JSONModel(:note_singlepart).from_hash(:type => "physdesc",
                                                   :label => I18n.t('accession.condition_description'),
                                                   :content => [accession.condition_description])
  end

  self.related_accessions = [{'ref' => accession.uri, '_resolved' => accession}]

  self.notes = notes

  self.update(values)

  self.rights_statements = Array(accession.rights_statements).map {|rights_statement|
    rights_statement.clone.tap {|r| r.delete('identifier')}
  }

  if !self.extents || self.extents.empty?
    self.extents = [JSONModel(:extent).new._always_valid!]
  end
  
  if !self.dates || self.dates.empty?
    self.dates = [JSONModel(:date).new._always_valid!]
  end
end