Class: DCModel

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

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

- (DCModel) initialize(obj)

Returns a new instance of DCModel



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

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

Instance Attribute Details

- (Object) creators

Returns the value of attribute creators



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

def creators
  @creators
end

- (Object) dates

Returns the value of attribute dates



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

def dates
  @dates
end

- (Object) identifier

Returns the value of attribute identifier



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

def identifier
  @identifier
end

- (Object) language

Returns the value of attribute language



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

def language
  @language
end

- (Object) subjects

Returns the value of attribute subjects



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

def subjects
  @subjects
end

- (Object) title

Returns the value of attribute title



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

def title
  @title
end

- (Object) type

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

+ (Object) DESCRIPTIVE_NOTE_TYPES



60
61
62
63
# File 'backend/app/exporters/models/dc.rb', line 60

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

+ (Object) FORMAT_NOTE_TYPES



70
71
72
73
# File 'backend/app/exporters/models/dc.rb', line 70

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

+ (Object) from_archival_object(obj)



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

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

+ (Object) from_digital_object(obj)



47
48
49
50
51
52
53
54
55
56
57
58
# 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)

  dc.identifier = "#{AppConfig[:backend_url]}#{obj.uri}"

  dc.type = obj.digital_object_type

  dc
end

+ (Object) RELATION_NOTE_TYPES



80
81
82
83
# File 'backend/app/exporters/models/dc.rb', line 80

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

+ (Object) RIGHTS_NOTE_TYPES



65
66
67
68
# File 'backend/app/exporters/models/dc.rb', line 65

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

+ (Object) SOURCE_NOTE_TYPES



75
76
77
78
# File 'backend/app/exporters/models/dc.rb', line 75

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

Instance Method Details

- (Object) each_description {|repo_info| ... }

Yields:

  • (repo_info)


85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'backend/app/exporters/models/dc.rb', line 85

def each_description
  @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

- (Object) each_format



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

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

- (Object) each_relation



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

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

- (Object) each_rights



99
100
101
102
103
104
105
# File 'backend/app/exporters/models/dc.rb', line 99

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

- (Object) each_source



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

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

- (Object) handle_agents(linked_agents)



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

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

- (Object) handle_date(dates)



148
149
150
151
152
# File 'backend/app/exporters/models/dc.rb', line 148

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

- (Object) handle_rights(rights_statements)



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'backend/app/exporters/models/dc.rb', line 155

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

- (Object) handle_subjects(subjects)



174
175
176
177
178
# File 'backend/app/exporters/models/dc.rb', line 174

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