Class: MODSModel

Inherits:
ASpaceExport::ExportModel show all
Includes:
JSONModel
Defined in:
backend/app/exporters/models/mods.rb

Constant Summary

@@mods_note =
Struct.new(:tag, :type, :label, :content, :wrapping_tag)

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

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

Methods inherited from ASpaceExport::ExportModel

#apply_map, inherited, model_for, model_for?

Methods included from ASpaceExport::ExportModelHelpers

#extract_date_string, #extract_note_content, #get_subnotes_by_type

Constructor Details

- (MODSModel) initialize

Returns a new instance of MODSModel



46
47
48
49
50
51
52
# File 'backend/app/exporters/models/mods.rb', line 46

def initialize
  @extents = []
  @notes = []
  @subjects = []
  @names = []
  @parts = []
end

Instance Attribute Details

- (Object) extents

Returns the value of attribute extents



8
9
10
# File 'backend/app/exporters/models/mods.rb', line 8

def extents
  @extents
end

- (Object) language_term

Returns the value of attribute language_term



7
8
9
# File 'backend/app/exporters/models/mods.rb', line 7

def language_term
  @language_term
end

- (Object) names

Returns the value of attribute names



11
12
13
# File 'backend/app/exporters/models/mods.rb', line 11

def names
  @names
end

- (Object) notes

Returns the value of attribute notes



9
10
11
# File 'backend/app/exporters/models/mods.rb', line 9

def notes
  @notes
end

- (Object) parts

Returns the value of attribute parts



13
14
15
# File 'backend/app/exporters/models/mods.rb', line 13

def parts
  @parts
end

- (Object) repository_note

Returns the value of attribute repository_note



14
15
16
# File 'backend/app/exporters/models/mods.rb', line 14

def repository_note
  @repository_note
end

- (Object) subjects

Returns the value of attribute subjects



10
11
12
# File 'backend/app/exporters/models/mods.rb', line 10

def subjects
  @subjects
end

- (Object) title

Returns the value of attribute title



6
7
8
# File 'backend/app/exporters/models/mods.rb', line 6

def title
  @title
end

- (Object) type_of_resource

Returns the value of attribute type_of_resource



12
13
14
# File 'backend/app/exporters/models/mods.rb', line 12

def type_of_resource
  @type_of_resource
end

Class Method Details

+ (Object) build_repo_note(repo_record)



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'backend/app/exporters/models/mods.rb', line 103

def self.build_repo_note(repo_record)
  agent = repo_record['agent_representation']['_resolved']
  contacts = agent['agent_contacts']

  contents = [repo_record['name']]
  if contacts.length > 0
    contents += %w(address_1 address_2 address_3 city region post_code country).map {|part|
      contacts[0][part] }.compact
  end

  contents = contents.join(', ')
  if repo_record['url']
    contents << " (#{repo_record['url']})"
  end

  new_mods_note('note', nil, "Digital object made available by", contents)
end

+ (Object) from_archival_object(obj)

meaning, ‘archival object’ in the abstract



56
57
58
59
60
61
62
63
# File 'backend/app/exporters/models/mods.rb', line 56

def self.from_archival_object(obj)
  
  mods = self.new
  
  mods.apply_map(obj, @archival_object_map)

  mods
end

+ (Object) from_digital_object(obj, opts = {})



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'backend/app/exporters/models/mods.rb', line 66

def self.from_digital_object(obj, opts = {})
  
  mods = self.from_archival_object(obj)
  
  if obj.respond_to? :digital_object_type
    mods.type_of_resource = obj.digital_object_type
  end

  mods.apply_map(obj, @digital_object_map, opts)

  mods.repository_note = build_repo_note(obj.repository['_resolved'])

  mods
end

+ (Object) from_digital_object_component(obj)



82
83
84
85
86
# File 'backend/app/exporters/models/mods.rb', line 82

def self.from_digital_object_component(obj)
  mods = self.from_archival_object(obj)

  mods
end

+ (Object) name_part_type_map



93
94
95
# File 'backend/app/exporters/models/mods.rb', line 93

def self.name_part_type_map
  @name_part_type_map
end

+ (Object) name_type_map



89
90
91
# File 'backend/app/exporters/models/mods.rb', line 89

def self.name_type_map
  @name_type_map
end

+ (Object) new_mods_note(*a)



98
99
100
# File 'backend/app/exporters/models/mods.rb', line 98

def self.new_mods_note(*a)
  @@mods_note.new(*a)
end

Instance Method Details



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'backend/app/exporters/models/mods.rb', line 230

def each_related_item(children = nil, maxDepth = 20)
  return if maxDepth == 0
  maxDepth = maxDepth - 1
  children ||= @children
  return unless children
  children.each do |child|
    json = JSONModel(:digital_object_component).new(child)
    yield self.class.from_digital_object_component(json)
    if child['children']
      each_related_item(child['children'], maxDepth) do |item|
        yield item
      end
    end
  end
end

- (Object) handle_agents(linked_agents)



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'backend/app/exporters/models/mods.rb', line 184

def handle_agents(linked_agents)
  linked_agents.each do |link|
    agent = link['_resolved']
    role = link['role']
    name_type = self.class.name_type_map[agent['jsonmodel_type']]
    # shift in granularity - role repeats for each name
    agent['names'].each do |name|
      self.names << {
        'type' => name_type, 
        'role' => role,
        'source' => name['source'],
        'parts' => name_parts(name, agent['jsonmodel_type']),
        'displayForm' => name['sort_name']
      }
    end
  end
end

- (Object) handle_extent(extents)



163
164
165
166
167
168
169
170
171
# File 'backend/app/exporters/models/mods.rb', line 163

def handle_extent(extents)
  extents.each do |ext|
    e = ext['number']
    e << " (#{ext['portion']})" if ext['portion']
    e << " #{ext['extent_type']}"

    self.extents << e
  end
end

- (Object) handle_notes(notes)



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'backend/app/exporters/models/mods.rb', line 127

def handle_notes(notes)
  notes.each do |note|
    content = ASpaceExport::Utils.extract_note_text(note)
    mods_note = case note['type']
                when 'accessrestrict'
                  new_mods_note('accessCondition', 
                                 'restrictionOnAccess',
                                 note['label'],
                                 content)
                when 'userestrict'
                  new_mods_note('accessCondition', 
                                'useAndReproduction',
                                note['label'],
                                content)
                when 'legalstatus'
                  new_mods_note('accessCondition', 
                                note['type'],
                                note['label'],
                                content)
                when 'physdesc'
                  new_mods_note('note', 
                                nil,
                                note['label'],
                                content,
                                'physicalDescription')
                else
                  new_mods_note('note',
                                note['type'],
                                note['label'],
                                content)
                end
   self.notes << mods_note
  end
end

- (Object) handle_subjects(subjects)



174
175
176
177
178
179
180
181
# File 'backend/app/exporters/models/mods.rb', line 174

def handle_subjects(subjects)
  subjects.map {|s| s['_resolved'] }.each do |subject|
    self.subjects << {
      'terms' => subject['terms'].map {|t| t['term']},
      'source' => subject['source']
    }
  end
end

- (Object) handle_tree(tree)



225
226
227
# File 'backend/app/exporters/models/mods.rb', line 225

def handle_tree(tree)
  @children = tree['_resolved']['children']
end

- (Object) name_parts(name, type)



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'backend/app/exporters/models/mods.rb', line 202

def name_parts(name, type)
  fields = case type
           when 'agent_person'
             ["primary_name", "title", "prefix", "rest_of_name", "suffix", "fuller_form", "number"]
           when 'agent_family'
             ["family_name", "prefix"]
           when 'agent_software'
             ["software_name", "version", "manufacturer"]
           when 'agent_corporate_entity'
             ["primary_name", "subordinate_name_1", "subordinate_name_2", "number"]
           end
  parts = []
  fields.each do |field|
    part = {}
    part['type'] = self.class.name_part_type_map[field] 
    part.delete('type') if part['type'].nil?
    part['content'] = name[field] unless name[field].nil?
    parts << part unless part.empty?
  end
  parts    
end

- (Object) new_mods_note(*a)



122
123
124
# File 'backend/app/exporters/models/mods.rb', line 122

def new_mods_note(*a)
  self.class.new_mods_note(*a)
end