Class: Resource
- Inherits:
-
JSONModel
- Object
- JSONModel
- Resource
- 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
Constants included from Identifiers
Instance Attribute Summary
Attributes included from Relationships
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Resource) initialize(values)
constructor
A new instance of Resource.
-
- (Object) populate_from_accession(accession)
Methods included from MapToAspaceContainer
included, mapper_to_aspace_json, mapper_to_managed_container, #update_from_json
Methods included from RightsRestrictionNotes
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
Methods included from Publishable
Methods included from Events
Methods included from Classifications
Methods included from ComponentsAddChildren
Methods included from UserDefineds
Methods included from CollectionManagements
Methods included from ExternalIDs
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
Methods included from Deaccessions
Methods included from Instances
Methods included from RightsStatements
Methods included from ExternalDocuments
Methods included from Dates
Methods included from Extents
Methods included from Subjects
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. = [{'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 |