Class: DCModel

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

Constant Summary

Constants included from JSONModel

JSONModel::REFERENCE_KEY_REGEX

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, check_valid_refs, 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_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, 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

#initialize(obj) ⇒ DCModel

Returns a new instance of DCModel.



27
28
29
30
31
32
33
34
35
# File 'backend/app/exporters/models/dc.rb', line 27

def initialize(obj)
  @creators = []
  @subjects = []
  @sources = []
  @dates = []
  @lang_materials = []
  @rights = []
  @json = obj
end

Instance Attribute Details

#creatorsObject

Returns the value of attribute creators



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

def creators
  @creators
end

#datesObject

Returns the value of attribute dates



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

def dates
  @dates
end

#identifierObject

Returns the value of attribute identifier



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

def identifier
  @identifier
end

#lang_materialsObject

Returns the value of attribute lang_materials



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

def lang_materials
  @lang_materials
end

#subjectsObject

Returns the value of attribute subjects



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

def subjects
  @subjects
end

#titleObject

Returns the value of attribute title



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

def title
  @title
end

#typeObject

Returns the value of attribute type



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

def type
  @type
end

Class Method Details

.DESCRIPTIVE_NOTE_TYPESObject



63
64
65
66
# File 'backend/app/exporters/models/dc.rb', line 63

def self.DESCRIPTIVE_NOTE_TYPES
  @descriptive_note_type ||= %w(bioghist prefercite)
  @descriptive_note_type
end

.FORMAT_NOTE_TYPESObject



73
74
75
76
# File 'backend/app/exporters/models/dc.rb', line 73

def self.FORMAT_NOTE_TYPES
  @format_note_type ||= %w(dimensions physdesc)
  @format_note_type
end

.from_archival_object(obj) ⇒ Object



38
39
40
41
42
43
44
# File 'backend/app/exporters/models/dc.rb', line 38

def self.from_archival_object(obj)
  dc = self.new(obj)

  dc.apply_map(obj, @archival_object_map)

  dc
end

.from_digital_object(obj) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'backend/app/exporters/models/dc.rb', line 47

def self.from_digital_object(obj)
  dc = self.from_archival_object(obj)

  dc.apply_map(obj, @digital_object_map)

  if obj.respond_to?('uri')
    dc.identifier = "#{AppConfig[:backend_url]}#{obj.uri}"
  end

  if obj.respond_to?('digital_object_type')
    dc.type = obj.digital_object_type
  end

  dc
end

.RELATION_NOTE_TYPESObject



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

def self.RELATION_NOTE_TYPES
  @relation_note_type ||= %w(relatedmaterial)
  @relation_note_type
end

.RIGHTS_NOTE_TYPESObject



68
69
70
71
# File 'backend/app/exporters/models/dc.rb', line 68

def self.RIGHTS_NOTE_TYPES
  @rights_note_type ||= %w(accessrestrict userestrict)
  @rights_note_type
end

.SOURCE_NOTE_TYPESObject



78
79
80
81
# File 'backend/app/exporters/models/dc.rb', line 78

def self.SOURCE_NOTE_TYPES
  @source_note_type ||= %w(originalsloc)
  @source_note_type
end

Instance Method Details

#each_descriptionObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'backend/app/exporters/models/dc.rb', line 88

def each_description
  if @json.respond_to?('notes')
    @json.notes.each do |note|
      if self.class.DESCRIPTIVE_NOTE_TYPES.include? note['type']
        yield extract_note_content(note)
      end
    end

    repo = @json.repository['_resolved']
    repo_info = "Digital object made available by #{repo['name']}"
    repo_info << " (#{repo['url']})" if repo['url']

    yield repo_info
  end
end

#each_formatObject



114
115
116
117
118
119
120
121
122
# File 'backend/app/exporters/models/dc.rb', line 114

def each_format
  if @json.respond_to?('notes')
    @json.notes.each do |note|
      if self.class.FORMAT_NOTE_TYPES.include? note['type']
        yield extract_note_content(note)
      end
    end
  end
end

#each_relationObject



134
135
136
137
138
139
140
141
142
# File 'backend/app/exporters/models/dc.rb', line 134

def each_relation
  if @json.respond_to?('notes')
    @json.notes.each do |note|
      if self.class.RELATION_NOTE_TYPES.include? note['type']
        yield extract_note_content(note)
      end
    end
  end
end

#each_rightsObject



104
105
106
107
108
109
110
111
112
# File 'backend/app/exporters/models/dc.rb', line 104

def each_rights
  if @json.respond_to?('notes')
    @json.notes.each do |note|
      if self.class.RIGHTS_NOTE_TYPES.include? note['type']
        yield extract_note_content(note)
      end
    end
  end
end

#each_sourceObject



124
125
126
127
128
129
130
131
132
# File 'backend/app/exporters/models/dc.rb', line 124

def each_source
  if @json.respond_to?('notes')
    @json.notes.each do |note|
      if self.class.SOURCE_NOTE_TYPES.include? note['type']
        yield extract_note_content(note)
      end
    end
  end
end

#handle_agents(linked_agents) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'backend/app/exporters/models/dc.rb', line 145

def handle_agents(linked_agents)
  linked_agents.each do |link|

    role = link['role']
    agent = link['_resolved']

    case role
    when 'creator'
      agent['names'].each {|n| self.creators << n['sort_name'] }
    when 'subject'
      agent['names'].each {|n| self.subjects << n['sort_name'] }
    end
  end
end

#handle_date(dates) ⇒ Object



181
182
183
184
185
# File 'backend/app/exporters/models/dc.rb', line 181

def handle_date(dates)
  dates.each do |date|
    self.dates << extract_date_string(date)
  end
end

#handle_langmaterials(lang_materials) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'backend/app/exporters/models/dc.rb', line 161

def handle_langmaterials(lang_materials)
  language_vals = lang_materials.map {|l| l['language_and_script']}.compact
  if !language_vals.empty?
    language_vals.each do |language|
      self.lang_materials << language['language']
      if language['script']
        self.lang_materials << language['script']
      end
    end
  end

  language_notes = lang_materials.map {|l| l['notes']}.compact.reject {|e| e == [] }.flatten
  if !language_notes.empty?
    language_notes.each do |note|
      self.lang_materials << extract_note_content(note)
    end
  end
end

#handle_rights(rights_statements) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'backend/app/exporters/models/dc.rb', line 188

def handle_rights(rights_statements)
  rights_statements.each do |rs|

    case rs['rights_type']

    when 'license'
      self['rights'] << "License: #{rs.license_identifier_terms}"
    end

    if rs['permissions']
      self['rights'] << "Permissions: #{rs.permissions}"
    end

    if rs['restrictions']
      self['rights'] << "Restriction: #{rs.restrictions}"
    end
  end
end

#handle_subjects(subjects) ⇒ Object



207
208
209
210
211
# File 'backend/app/exporters/models/dc.rb', line 207

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