Class: DigitalObject
- Inherits:
-
Record
show all
- Defined in:
- backend/app/model/digital_object.rb,
public/app/models/digital_object.rb
Constant Summary
Constants inherited
from Record
Record::ABSTRACT
Instance Attribute Summary collapse
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 Method Summary
collapse
Methods inherited from Record
#[], #apply_highlighting, #dig, #note, #parse_full_title, #request_item
Constructor Details
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
@cite = parse_cite_string("")
@cite_item = parse_cite_string("item")
@cite_item_description = parse_cite_string("description")
end
|
Instance Attribute Details
#cite ⇒ Object
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
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
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
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
117
118
119
120
121
122
123
|
# File 'backend/app/model/digital_object.rb', line 117
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
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
108
109
110
111
112
113
114
115
|
# File 'backend/app/model/digital_object.rb', line 68
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])
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
125
126
127
128
129
|
# File 'backend/app/model/digital_object.rb', line 125
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 breadcrumb
[
{
:uri => '',
:type => 'digital_object',
:crumb => display_string
}
]
end
|
#delete ⇒ Object
131
132
133
134
135
|
# File 'backend/app/model/digital_object.rb', line 131
def delete
instance_subrecords = related_records(: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
nil
end
|
#root_node_uri ⇒ Object
21
22
23
|
# File 'public/app/models/digital_object.rb', line 21
def root_node_uri
uri
end
|
#validate ⇒ Object
63
64
65
66
|
# File 'backend/app/model/digital_object.rb', line 63
def validate
validate_mixed_content_field()
super
end
|