Class: DigitalObject
- Defined in:
- backend/app/model/digital_object.rb,
public/app/models/digital_object.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Record
Instance Attribute Summary collapse
-
#cite ⇒ Object
readonly
Returns the value of attribute cite.
-
#cite_item ⇒ Object
readonly
Returns the value of attribute cite_item.
-
#cite_item_description ⇒ Object
readonly
Returns the value of attribute cite_item_description.
-
#linked_instances ⇒ Object
readonly
Returns the value of attribute linked_instances.
Attributes inherited from Record
#agents, #classifications, #container_display, #container_summary_for_badge, #container_titles_and_uris, #criteria, #dates, #display_string, #extents, #external_documents, #full, #highlights, #identifier, #json, #lang_materials, #level, #linked_digital_objects, #notes, #other_level, #primary_type, #raw, #repository_information, #resolved_repository, #resolved_resource, #resolved_top_container, #subjects, #uri
Class Method Summary collapse
-
.instance_owners_root_records(id) ⇒ Object
-
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
-
.touch_records(obj) ⇒ Object
Instance Method Summary collapse
-
#breadcrumb ⇒ Object
-
#delete ⇒ Object
-
#finding_aid ⇒ Object
-
#initialize(*args) ⇒ DigitalObject
constructor
A new instance of DigitalObject.
-
#root_node_uri ⇒ Object
Methods inherited from Record
#[], #apply_highlighting, #dig, #note, #parse_full_title, #request_item
Constructor Details
#initialize(*args) ⇒ DigitalObject
Returns a new instance of DigitalObject.
5 6 7 8 9 10 11 12 13 |
# File 'public/app/models/digital_object.rb', line 5 def initialize(*args) super @linked_instances = parse_linked_instances # ANW-921: Refactored citation modal, keep cite in case used by others @cite = parse_cite_string("") @cite_item = parse_cite_string("item") @cite_item_description = parse_cite_string("description") end |
Instance Attribute Details
#cite ⇒ Object (readonly)
Returns the value of attribute cite
3 4 5 |
# File 'public/app/models/digital_object.rb', line 3 def cite @cite end |
#cite_item ⇒ Object (readonly)
Returns the value of attribute cite_item
3 4 5 |
# File 'public/app/models/digital_object.rb', line 3 def cite_item @cite_item end |
#cite_item_description ⇒ Object (readonly)
Returns the value of attribute cite_item_description
3 4 5 |
# File 'public/app/models/digital_object.rb', line 3 def cite_item_description @cite_item_description end |
#linked_instances ⇒ Object (readonly)
Returns the value of attribute linked_instances
3 4 5 |
# File 'public/app/models/digital_object.rb', line 3 def linked_instances @linked_instances end |
Class Method Details
.instance_owners_root_records(id) ⇒ Object
109 110 111 112 113 114 115 |
# File 'backend/app/model/digital_object.rb', line 109 def self.instance_owners_root_records(id) relationships = self.find_relationship(:instance_do_link).find_by_participant(self[id]) resource_ids = Instance.inner_join(:archival_object, archival_object__id: :instance__archival_object_id) .filter(instance__id: relationships.map {|relationship| relationship[:instance_id]}) .map { |row| row[:root_record_id] } resource_ids end |
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'backend/app/model/digital_object.rb', line 60 def self.sequel_to_jsonmodel(objs, opts = {}) jsons = super relationships = find_relationship(:instance_do_link).find_by_participant_ids(self, objs.map(&:id)) instances = Instance.filter(:id => relationships.map {|relationship| relationship[:instance_id]}).all relationship_to_instance = Hash[relationships.map {|relationship| [relationship, instances.select {|instance| relationship[:instance_id] == instance.id}] }] jsons.zip(objs).each do |json, obj| json["collection"] = [] json["linked_instances"] = [] relationships.each do |relationship| next unless relationship.relates_to?(obj) instances = relationship_to_instance[relationship] instances.each do |link| uri = self.uri_for(:resource, link[:resource_id]) if link[:resource_id] uri = self.uri_for(:archival_object, link[:archival_object_id]) if link[:archival_object_id] uri = self.uri_for(:accession, link[:accession_id]) if link[:accession_id] if uri.nil? raise "Digital Object Instance not linked to either a resource, archival object or accession" end if link[:archival_object_id] archival_object = ArchivalObject.find(id: link[:archival_object_id]) # ANW-1703: only include resource uri from AO if the AO is published. Publish will be 0|1 if archival_object.publish.positive? json["collection"] << {"ref" => self.uri_for(:resource, archival_object.root_record_id)} end else json["collection"] << {"ref" => uri} end json["linked_instances"].push({"ref" => uri}) end end json["collection"].uniq! end jsons end |
.touch_records(obj) ⇒ Object
117 118 119 120 121 |
# File 'backend/app/model/digital_object.rb', line 117 def self.touch_records(obj) [ { type: Resource, ids: DigitalObject.instance_owners_root_records(obj.id) } ] end |
Instance Method Details
#breadcrumb ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'public/app/models/digital_object.rb', line 25 def [ { :uri => '', :type => 'digital_object', :crumb => display_string } ] end |
#delete ⇒ Object
123 124 125 126 127 |
# File 'backend/app/model/digital_object.rb', line 123 def delete instance_subrecords = (:instance_do_link) super instance_subrecords.each {|sub| sub.delete } end |
#finding_aid ⇒ Object
15 16 17 18 19 |
# File 'public/app/models/digital_object.rb', line 15 def finding_aid # as this shares the same template as resources, # be clear that this object doesn't have a finding aid nil end |
#root_node_uri ⇒ Object
21 22 23 |
# File 'public/app/models/digital_object.rb', line 21 def root_node_uri uri end |