Class: Bplmodels::Institution

Inherits:
RelationBase
  • Object
show all
Defined in:
app/models/bplmodels/institution.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RelationBase

#apply_default_permissions, #assert_content_model, #convert_to

Class Method Details

.mint(args) ⇒ Object

Expects the following args: parent_pid => id of the parent object local_id => local ID of the object local_id_type => type of that local ID label => label of the collection



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'app/models/bplmodels/institution.rb', line 199

def self.mint(args)

  args[:namespace_id] ||= ARK_CONFIG_GLOBAL['namespace_commonwealth_pid']

  #TODO: Duplication check here to prevent over-writes?

  response = Typhoeus::Request.post(ARK_CONFIG_GLOBAL['url'] + "/arks.json", :params => {:ark=>{:namespace_ark => ARK_CONFIG_GLOBAL['namespace_commonwealth_ark'], :namespace_id=>ARK_CONFIG_GLOBAL['namespace_commonwealth_pid'], :url_base => ARK_CONFIG_GLOBAL['ark_commonwealth_base'], :model_type => self.name, :local_original_identifier=>args[:local_id], :local_original_identifier_type=>args[:local_id_type]}})
  begin
    as_json = JSON.parse(response.body)
  rescue => ex
    raise('Error in JSON response for minting an institution pid.')
  end

  Bplmodels::Institution.find_in_batches('id'=>as_json["pid"]) do |group|
    group.each { |solr_result|
      return as_json["pid"]
    }
  end

  object = self.new(:pid=>as_json["pid"])

  title = Bplmodels::DatastreamInputFuncs.getProperTitle(args[:label])
  object.label = args[:label]
  object..insert_title(title[0], title[1])

  object.read_groups = ["public"]
  object.edit_groups = ["superuser", 'admin[' + object.pid + ']']

  return object
end

Instance Method Details

#fedora_nameObject



28
29
30
# File 'app/models/bplmodels/institution.rb', line 28

def fedora_name
  'institution'
end

#insert_member(fedora_object) ⇒ Object

A collection can have another collection as a member, or an image



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/bplmodels/institution.rb', line 11

def insert_member(fedora_object)
  if (fedora_object.instance_of?(Bplmodels::Collection))

    #add to the members ds
    members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)

    #add to the rels-ext ds
    fedora_object.institutions << selfinstitutioninstitution
    self.collections << fedora_object

  end

  fedora_object.save!
  self.save!

end

#new_examplary_image(file_path, file_name) ⇒ Object



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
# File 'app/models/bplmodels/institution.rb', line 32

def new_examplary_image(file_path, file_name)

  #Delete any old images
  ActiveFedora::Base.find_in_batches('is_exemplary_image_of_ssim'=>"info:fedora/#{self.pid}") do |group|
    group.each { |image_solr|
        current_image_file = ActiveFedora::Base.find(image_solr['id']).adapt_to_cmodel
        current_image_file.delete
    }
  end


  image_file = Bplmodels::ImageFile.mint(:parent_pid=>self.pid, :local_id=>file_name, :local_id_type=>'File Name', :label=>file_name, :institution_pid=>self.pid)

  datastream = 'productionMaster'
  image_file.send(datastream).content = ::File.open(file_path)

  if file_name.split('.').last.downcase == 'tif'
    image_file.send(datastream).mimeType = 'image/tiff'
  elsif file_name.split('.').last.downcase == 'jpg'
    image_file.send(datastream).mimeType = 'image/jpeg'
  elsif file_name.split('.').last.downcase == 'jp2'
    image_file.send(datastream).mimeType = 'image/jp2'
  elsif file_name.split('.').last.downcase == 'png'
    image_file.send(datastream).mimeType = 'image/png'
  elsif file_name.split('.').last.downcase == 'txt'
    image_file.send(datastream).mimeType = 'text/plain'
  else
    #image_file.send(datastream).mimeType = 'image/jpeg'
    raise "Could not find a mimeType for #{file_name.split('.').last.downcase}"
  end

  image_file.send(datastream).dsLabel = file_name.gsub(/\.(tif|TIF|jpg|JPG|jpeg|JPEG|jp2|JP2|png|PNG|txt|TXT)$/, '')

  #FIXME!!!
  original_file_location = "Uploaded file of #{file_path}"
  image_file..insert_file_source(original_file_location,file_name,datastream)
  image_file..item_status.state = "published"
  image_file..item_status.state_comment = "Added via the institution admin form using Bplmodels new_exemplary_image method on " + Time.new.year.to_s + "/" + Time.new.month.to_s + "/" + Time.new.day.to_s

  image_file.add_relationship(:is_image_of, "info:fedora/" + self.pid)
  image_file.add_relationship(:is_file_of, "info:fedora/" + self.pid)
  image_file.add_relationship(:is_exemplary_image_of, "info:fedora/" + self.pid)


  image_file.save
  image_file
end

#to_solr(doc = {}) ⇒ Object



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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'app/models/bplmodels/institution.rb', line 80

def to_solr(doc = {} )
  doc = super(doc)



  # description
  doc['abstract_tsim'] = self..abstract

  # url
  doc['institution_url_ss'] = self..local_other

  # sublocations
  doc['sub_location_ssim']  = self..item_location.holding_simple.copy_information.sub_location

  # hierarchical geo
  country = self..subject.hierarchical_geographic.country
  state = self..subject.hierarchical_geographic.state
  county = self..subject.hierarchical_geographic.county
  city = self..subject.hierarchical_geographic.city
  city_section = self..subject.hierarchical_geographic.city_section

  doc['subject_geo_country_ssim'] = country
  doc['subject_geo_state_ssim'] = state
  doc['subject_geo_county_ssim'] = county
  doc['subject_geo_city_ssim'] = city
  doc['subject_geo_citysection_ssim'] = city_section

  # add " (county)" to county values for better faceting
  county_facet = []
  if county.length > 0
    county.each do |county_value|
      county_facet << county_value + ' (county)'
    end
  end

  # add hierarchical geo to subject-geo text field
  doc['subject_geographic_tsim'] = country + state + county + city + city_section

  # add hierarchical geo to subject-geo facet field
  doc['subject_geographic_ssim'] = country + state + county_facet + city + city_section

  # coordinates
  coords = self..subject.cartographics.coordinates
  doc['subject_coordinates_geospatial'] = coords
  doc['subject_point_geospatial'] = coords

  # TODO: DRY this out with Bplmodels::ObjectBase
  # geographic data as GeoJSON
  # subject_geojson_facet_ssim = for map-based faceting + display
  # subject_hiergeo_geojson_ssm = for display of hiergeo metadata
  doc['subject_geojson_facet_ssim'] = []
  doc['subject_hiergeo_geojson_ssm'] = []
  0.upto self..subject.length-1 do |subject_index|

    this_subject = self..mods(0).subject(subject_index)

    # TGN-id-derived geo subjects. assumes only longlat points, no bboxes
    if this_subject.cartographics.coordinates.any? && this_subject.hierarchical_geographic.any?
      geojson_hash_base = {type: 'Feature', geometry: {type: 'Point'}}
      # get the coordinates
      coords = coords[0]
      if coords.match(/^[-]?[\d]*[\.]?[\d]*,[-]?[\d]*[\.]?[\d]*$/)
        geojson_hash_base[:geometry][:coordinates] = coords.split(',').reverse.map { |v| v.to_f }
      end

      facet_geojson_hash = geojson_hash_base.dup
      hiergeo_geojson_hash = geojson_hash_base.dup

      # get the hierGeo elements, except 'continent'
      hiergeo_hash = {}
      ModsDescMetadata.terminology.retrieve_node(:subject,:hierarchical_geographic).children.each do |hgterm|
        hiergeo_hash[hgterm[0]] = '' unless hgterm[0].to_s == 'continent'
      end
      hiergeo_hash.each_key do |k|
        hiergeo_hash[k] = this_subject.hierarchical_geographic.send(k)[0].presence
      end
      hiergeo_hash.reject! {|k,v| !v } # remove any nil values

      hiergeo_hash[:other] = this_subject.geographic[0] if this_subject.geographic[0]

      hiergeo_geojson_hash[:properties] = hiergeo_hash
      facet_geojson_hash[:properties] = {placename: DatastreamInputFuncs.render_display_placename(hiergeo_hash)}

      if geojson_hash_base[:geometry][:coordinates].is_a?(Array)
        doc['subject_hiergeo_geojson_ssm'].append(hiergeo_geojson_hash.to_json)
        doc['subject_geojson_facet_ssim'].append(facet_geojson_hash.to_json)
      end
    end
  end

  doc['institution_pid_si'] = self.pid
  doc['institution_pid_ssi'] = self.pid

  # basic genre
  basic_genre = 'Institutions'
  doc['genre_basic_ssim'] = basic_genre
  doc['genre_basic_tsim'] = basic_genre

  # physical location
  # slightly redundant, but needed for faceting and A-Z filtering
  institution_name = self..mods(0).title.first
  doc['physical_location_ssim'] = institution_name
  doc['physical_location_tsim'] = institution_name

  exemplary_check = Bplmodels::ImageFile.find_with_conditions({"is_exemplary_image_of_ssim"=>"info:fedora/#{self.pid}"}, rows: '1', fl: 'id' )
  if exemplary_check.present?
    doc['exemplary_image_ssi'] = exemplary_check.first["id"]
  end


  doc

end