Class: SubjectConverter

Inherits:
Converter show all
Defined in:
backend/app/converters/subject_converter.rb

Class Method Summary collapse

Methods inherited from Converter

for, #get_output_path, #import_options, import_options, inherited, #initialize, list_import_types, register_converter, #remove_files, #run

Constructor Details

This class inherits a constructor from Converter

Class Method Details

.configureObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
161
# File 'backend/app/converters/subject_converter.rb', line 26

def self.configure
  {
    # 1. Map the cell data to schemas or handlers
    'subject_authority_id' => 'subject.authority_id',
    'subject_source' => 'subject.source',
    'subject_scope_note' => 'subject.scope_note',

    'term_1' => 'term_1.term',
    'term_type_1' => 'term_1.term_type',

    'term_2' => 'term_2.term',
    'term_type_2' => 'term_2.term_type',

    'term_3' => 'term_3.term',
    'term_type_3' => 'term_3.term_type',

    'term_4' => 'term_4.term',
    'term_type_4' => 'term_4.term_type',

    'term_5' => 'term_5.term',
    'term_type_5' => 'term_5.term_type',

    'external_document_title' => 'external_document.title',
    'external_document_location' => 'external_document.location',
    'external_document_publish' => 'external_document.publish',

    'md_rights_dec_license' => 'md_rights.license',
    'md_rights_dec_descriptive_note' => 'md_rights.descriptive_note',
    'md_rights_dec_file_uri' => 'md_rights.file_uri',
    'md_rights_dec_xlink_actuate' => 'md_rights.file_version_xlink_actuate_attribute',
    'md_rights_dec_xlink_show' => 'md_rights.file_version_xlink_show_attribute',
    'md_rights_dec_xlink_role' => 'md_rights.file_version_xlink_role_attribute',
    'md_rights_dec_xlink_title' => 'md_rights.file_version_xlink_title_attribute',
    'md_rights_dec_xlink_arcrole' => 'md_rights.file_version_xlink_arcrole_attribute',
    'md_rights_dec_last_verified_date' => 'md_rights.last_verified_date',


    # 2. Define data handlers
    #    :record_type of the schema (if other than the handler key)
    #    :defaults - hash which maps property keys to default values if nothing shows up in the source date
    #    :on_row_complete - Proc to run whenever a row in the CSV table is complete
    #        param 1 is the set of objects generated by the row
    #        param 2 is an object in the row (of the type described in the handler)

    :subject => {
      :record_type => :subject,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, obj|
      },
    },

    :external_document => {
      :record_type => :external_document,
      :on_create => Proc.new {|cache, obj|
      },
      :on_row_complete => Proc.new {|cache, doc|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.external_documents << doc
        end
      },
    },

    :md_rights => {
      :record_type => :metadata_rights_declaration,
      :on_create => Proc.new {|cache, obj|
      },
      :on_row_complete => Proc.new {|cache, rights|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject. << rights
        end
      },
    },

    :term_1 => {
      :record_type => :term,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, term|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.terms << term
        end
      },
    },

    :term_2 => {
      :record_type => :term,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, term|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.terms << term
        end
      },
    },

    :term_3 => {
      :record_type => :term,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, term|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.terms << term
        end
      },
    },

    :term_4 => {
      :record_type => :term,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, term|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.terms << term
        end
      },
    },

    :term_5 => {
      :record_type => :term,
      :on_create => Proc.new {|cache, obj|
        obj.vocabulary = '/vocabularies/1'
      },
      :on_row_complete => Proc.new {|cache, term|
        cache.select {|obj| obj.class.record_type == 'subject'}.each do |subject|
          subject.terms << term
        end
      },
    },
  }
end

.import_types(show_hidden = false) ⇒ Object



7
8
9
10
11
12
13
14
# File 'backend/app/converters/subject_converter.rb', line 7

def self.import_types(show_hidden = false)
  [
   {
     :name => "subject_csv",
     :description => "Import Subject records from a CSV file"
   }
  ]
end

.instance_for(type, input_file) ⇒ Object



17
18
19
20
21
22
23
# File 'backend/app/converters/subject_converter.rb', line 17

def self.instance_for(type, input_file)
  if type == "subject_csv"
    self.new(input_file)
  else
    nil
  end
end