bplmodels 0.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +0 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/bplmodels/application.js +15 -0
  6. data/app/assets/stylesheets/bplmodels/application.css +13 -0
  7. data/app/controllers/bplmodels/application_controller.rb +4 -0
  8. data/app/helpers/bplmodels/application_helper.rb +4 -0
  9. data/app/models/bplmodels/audio_file.rb +14 -0
  10. data/app/models/bplmodels/book.rb +35 -0
  11. data/app/models/bplmodels/card.rb +35 -0
  12. data/app/models/bplmodels/characterization.rb +92 -0
  13. data/app/models/bplmodels/collection.rb +118 -0
  14. data/app/models/bplmodels/complex_object_base.rb +24 -0
  15. data/app/models/bplmodels/correspondence.rb +35 -0
  16. data/app/models/bplmodels/document.rb +35 -0
  17. data/app/models/bplmodels/document_file.rb +8 -0
  18. data/app/models/bplmodels/ephemera.rb +35 -0
  19. data/app/models/bplmodels/file.rb +151 -0
  20. data/app/models/bplmodels/file_content_datastream.rb +10 -0
  21. data/app/models/bplmodels/fits_datastream.rb +190 -0
  22. data/app/models/bplmodels/image.rb +14 -0
  23. data/app/models/bplmodels/image_file.rb +18 -0
  24. data/app/models/bplmodels/institution.rb +159 -0
  25. data/app/models/bplmodels/manuscript.rb +34 -0
  26. data/app/models/bplmodels/map.rb +34 -0
  27. data/app/models/bplmodels/mods_desc_metadata.rb +1826 -0
  28. data/app/models/bplmodels/musical_notation.rb +34 -0
  29. data/app/models/bplmodels/newspaper.rb +15 -0
  30. data/app/models/bplmodels/nom_terminology.rb +1242 -0
  31. data/app/models/bplmodels/non_photographic_print.rb +34 -0
  32. data/app/models/bplmodels/oai_collection.rb +19 -0
  33. data/app/models/bplmodels/oai_metadata.rb +75 -0
  34. data/app/models/bplmodels/oai_object.rb +45 -0
  35. data/app/models/bplmodels/object.rb +36 -0
  36. data/app/models/bplmodels/object_base.rb +1241 -0
  37. data/app/models/bplmodels/objects/collection.rb~ +28 -0
  38. data/app/models/bplmodels/objects/image.rb~ +59 -0
  39. data/app/models/bplmodels/objects/postcard.rb~ +56 -0
  40. data/app/models/bplmodels/organizational_set.rb +25 -0
  41. data/app/models/bplmodels/periodical.rb +37 -0
  42. data/app/models/bplmodels/photographic_print.rb +34 -0
  43. data/app/models/bplmodels/relation_base.rb +99 -0
  44. data/app/models/bplmodels/scrapbook.rb +35 -0
  45. data/app/models/bplmodels/simple_object_base.rb +27 -0
  46. data/app/models/bplmodels/sound_recording.rb +15 -0
  47. data/app/models/bplmodels/system_collection.rb +8 -0
  48. data/app/models/bplmodels/uploads_set.rb +3 -0
  49. data/app/models/bplmodels/workflow_metadata.rb +99 -0
  50. data/app/views/layouts/bplmodels/application.html.erb +14 -0
  51. data/config/application.rb +6 -0
  52. data/config/predicate_mappings.yml +61 -0
  53. data/config/routes.rb +2 -0
  54. data/lib/bplmodels.rb +21 -0
  55. data/lib/bplmodels/constants.rb +119 -0
  56. data/lib/bplmodels/datastream_input_funcs.rb +949 -0
  57. data/lib/bplmodels/engine.rb +5 -0
  58. data/lib/bplmodels/engine.rb~ +5 -0
  59. data/lib/bplmodels/finder.rb +192 -0
  60. data/lib/bplmodels/object_funcs.rb +10 -0
  61. data/lib/bplmodels/version.rb +3 -0
  62. data/lib/tasks/bplmodels_tasks.rake +4 -0
  63. data/test/bplmodels_test.rb +7 -0
  64. data/test/dummy/README.rdoc +261 -0
  65. data/test/dummy/Rakefile +7 -0
  66. data/test/dummy/app/assets/javascripts/application.js +15 -0
  67. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  68. data/test/dummy/app/controllers/application_controller.rb +3 -0
  69. data/test/dummy/app/helpers/application_helper.rb +2 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/config.ru +4 -0
  72. data/test/dummy/config/application.rb +59 -0
  73. data/test/dummy/config/boot.rb +10 -0
  74. data/test/dummy/config/environment.rb +5 -0
  75. data/test/dummy/config/environments/development.rb +37 -0
  76. data/test/dummy/config/environments/production.rb +67 -0
  77. data/test/dummy/config/environments/test.rb +37 -0
  78. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/test/dummy/config/initializers/inflections.rb +15 -0
  80. data/test/dummy/config/initializers/mime_types.rb +5 -0
  81. data/test/dummy/config/initializers/secret_token.rb +7 -0
  82. data/test/dummy/config/initializers/session_store.rb +8 -0
  83. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  84. data/test/dummy/config/locales/en.yml +5 -0
  85. data/test/dummy/config/routes.rb +4 -0
  86. data/test/dummy/public/404.html +26 -0
  87. data/test/dummy/public/422.html +26 -0
  88. data/test/dummy/public/500.html +25 -0
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/dummy/script/rails +6 -0
  91. data/test/integration/navigation_test.rb +10 -0
  92. data/test/test_helper.rb +15 -0
  93. metadata +234 -0
@@ -0,0 +1,34 @@
1
+ module Bplmodels
2
+ class NonPhotographicPrint < Bplmodels::SimpleObjectBase
3
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
4
+
5
+ #A collection can have another collection as a member, or an image
6
+ def insert_member(fedora_object)
7
+ if (fedora_object.instance_of?(Bplmodels::ImageFile))
8
+
9
+ #add to the members ds
10
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
11
+
12
+ #add to the rels-ext ds
13
+ fedora_object.object << self
14
+ self.image_files << fedora_object
15
+
16
+ end
17
+
18
+ fedora_object.save!
19
+ self.save!
20
+
21
+ end
22
+
23
+ def to_solr(doc = {} )
24
+ doc = super(doc)
25
+ doc['active_fedora_model_ssi'] = self.class.name
26
+ doc
27
+ end
28
+
29
+ def fedora_name
30
+ 'non_photographic_print'
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,19 @@
1
+ module Bplmodels
2
+ class OAICollection < Bplmodels::Collection
3
+ def fedora_name
4
+ 'oai_collection'
5
+ end
6
+ # To change this template use File | Settings | File Templates.
7
+
8
+ #Expects the following args:
9
+ #parent_pid => id of the parent object
10
+ #local_id => local ID of the object
11
+ #local_id_type => type of that local ID
12
+ #label => label of the collection
13
+ def self.mint(args)
14
+ args[:namespace_id] = ARK_CONFIG_GLOBAL['namespace_oai_pid']
15
+
16
+ super(args)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ module Bplmodels
2
+ class OAIMetadata < ActiveFedora::OmDatastream
3
+ include OM::XML::Document
4
+
5
+ OAI_NS = 'http://www.bpl.org/repository/xml/ns/oai'
6
+ OAI_SCHEMA = 'http://www.bpl.org/repository/xml/xsd/oai.xsd'
7
+ OAI_PARAMS = {
8
+ "version" => "0.0.1",
9
+ "xmlns:xlink" => "http://www.w3.org/1999/xlink",
10
+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
11
+ "xmlns" => OAI_NS,
12
+ "xsi:schemaLocation" => "#{OAI_NS} #{OAI_SCHEMA}",
13
+ }
14
+
15
+ set_terminology do |t|
16
+ t.root :path => 'oaiMetadata', :xmlns => OAI_NS
17
+
18
+ t.ingestion_information(:path=>"ingestionInformation") {
19
+ t.url(:path=>"url")
20
+ t.oai_format(:path=>'format')
21
+ t.set_name(:path=>'setName')
22
+ }
23
+
24
+ t.header_information(:path=>'headerInformation') {
25
+ t.status(:path=>'status')
26
+ t.identifer(:path=>'identifier')
27
+ t.datestamp(:path=>'datestamp')
28
+ t.set_spec(:path=>'setSpec')
29
+ }
30
+
31
+
32
+ t.original_record(:path=>'originalRecord')
33
+
34
+ t.raw_info(:path=>'rawInfo') {
35
+ t.file_urls(:path=>'fileURL') {
36
+ t.index(:path=>{:attribute=>"index"})
37
+ }
38
+ t.unparsed_dates(:path=>'unparsedDates')
39
+ }
40
+
41
+
42
+ end
43
+
44
+ def self.xml_template
45
+ Nokogiri::XML::Builder.new do |xml|
46
+ xml.oaiMetadata(OAI_PARAMS) {
47
+
48
+
49
+
50
+ }
51
+ end.doc
52
+ end
53
+
54
+ #Required for Active Fedora 9
55
+ def prefix(path=nil)
56
+ return ''
57
+ end
58
+
59
+
60
+ define_template :original_record do |xml, content|
61
+ xml.original_record {
62
+ xml.cdata content
63
+ }
64
+ end
65
+
66
+
67
+ def insert_original_record(content)
68
+ add_child_node(ng_xml.root, :original_record, content)
69
+ end
70
+
71
+ def remove_original_record(index)
72
+ self.find_by_terms(:original_record).slice(index.to_i).remove
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,45 @@
1
+ module Bplmodels
2
+ class OAIObject < Bplmodels::SimpleObjectBase
3
+
4
+ has_metadata :name => "oaiMetadata", :type => OAIMetadata
5
+
6
+ has_metadata :name => "workflowMetadata", :type => WorkflowMetadata
7
+
8
+ has_many :exemplary_image, :class_name => "Bplmodels::OAIObject", :property=> :is_exemplary_image_of
9
+
10
+
11
+ has_file_datastream 'thumbnail300', :versionable=>false, :label=>'thumbnail300 datastream'
12
+
13
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
14
+
15
+
16
+ def fedora_name
17
+ 'oai_object'
18
+ end
19
+
20
+ def to_solr(doc = {} )
21
+ doc = super(doc)
22
+ doc['active_fedora_model_ssi'] = self.class.name
23
+
24
+ doc
25
+ end
26
+
27
+ #Expects the following args:
28
+ #parent_pid => id of the parent object
29
+ #local_id => local ID of the object
30
+ #local_id_type => type of that local ID
31
+ #label => label of the collection
32
+ def self.mint(args)
33
+ args[:namespace_id] = ARK_CONFIG_GLOBAL['namespace_oai_pid']
34
+ #TODO: Duplication check here to prevent over-writes?
35
+
36
+ return_object = super(args)
37
+
38
+ if !return_object.is_a?(String)
39
+ return_object.workflowMetadata.insert_oai_defaults
40
+ end
41
+
42
+ return return_object
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ module Bplmodels
2
+ class Object < Bplmodels::SimpleObjectBase
3
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
4
+
5
+
6
+ #A collection can have another collection as a member, or an image
7
+ def insert_member(fedora_object)
8
+ if (fedora_object.instance_of?(Bplmodels::ImageFile))
9
+
10
+ #add to the members ds
11
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
12
+
13
+ #add to the rels-ext ds
14
+ fedora_object.object << self
15
+ self.image_files << fedora_object
16
+
17
+ end
18
+
19
+ fedora_object.save!
20
+ self.save!
21
+
22
+ end
23
+
24
+ def fedora_name
25
+ 'object'
26
+ end
27
+
28
+ def to_solr(doc = {} )
29
+ doc = super(doc)
30
+ doc['active_fedora_model_ssi'] = self.class.name
31
+ doc
32
+ end
33
+
34
+
35
+ end
36
+ end
@@ -0,0 +1,1241 @@
1
+ module Bplmodels
2
+ class ObjectBase < ActiveFedora::Base
3
+ # To change this template use File | Settings | File Templates.
4
+ include ActiveFedora::Auditable
5
+ include Hydra::AccessControls::Permissions
6
+ include Hydra::ModelMethods
7
+
8
+ has_many :exemplary_image, :class_name => "Bplmodels::File", :property=> :is_exemplary_image_of
9
+
10
+ has_many :image_files, :class_name => "Bplmodels::ImageFile", :property=> :is_image_of
11
+
12
+ has_many :audio_files, :class_name => "Bplmodels::AudioFile", :property=> :is_audio_of
13
+
14
+ has_many :document_files, :class_name => "Bplmodels::DocumentFile", :property=> :is_document_of
15
+
16
+ has_many :files, :class_name => "Bplmodels::File", :property=> :is_file_of
17
+
18
+
19
+
20
+ belongs_to :institution, :class_name => 'Bplmodels::Institution', :property => :is_member_of
21
+
22
+ belongs_to :collection, :class_name => 'Bplmodels::Collection', :property => :is_member_of_collection
23
+
24
+ belongs_to :organization, :class_name => 'Bplmodels::Collection', :property => :is_member_of_collection
25
+ has_and_belongs_to_many :members, :class_name=> "Bplmodels::Collection", :property=> :hasSubset
26
+
27
+ has_metadata :name => "descMetadata", :type => ModsDescMetadata
28
+ has_metadata :name => "workflowMetadata", :type => WorkflowMetadata
29
+
30
+ # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
31
+ has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
32
+
33
+ has_attributes :abstract, :datastream=>'descMetadata', :at => [:mods, :abstract], :multiple=> false
34
+ has_attributes :title, :datastream=>'descMetadata', :at => [:mods, :title], :multiple=> true
35
+ has_attributes :supplied_title, :datastream=>'descMetadata', :at => [:mods, :title_info, :supplied], :multiple=> true
36
+ has_attributes :note_value, :datastream=>'descMetadata', :at => [:mods, :note], :multiple=> true
37
+ has_attributes :workflow_state, :datastream=>'workflowMetadata', :at => [:item_status, :state], :multiple=> true
38
+ has_attributes :creator_name, :datastream=>'descMetadata', :at => [:mods, :name, :namePart], :multiple=> true
39
+ has_attributes :creator_type, :datastream=>'descMetadata', :at => [:mods, :name, :type], :multiple=> true
40
+ has_attributes :creator_role, :datastream=>'descMetadata', :at => [:mods, :name, :role, :text], :multiple=> true
41
+ has_attributes :resource_type, :datastream=>'descMetadata', :at => [:mods, :type_of_resource], :multiple=> true
42
+ has_attributes :manuscript, :datastream=>'descMetadata', :at => [:mods, :type_of_resource, :manuscript], :multiple=> true
43
+ has_attributes :genre, :datastream=>'descMetadata', :at => [:mods, :genre_basic], :multiple=> true
44
+ has_attributes :identifier, :datastream=>'descMetadata', :at=>[:mods, :identifier], :multiple=> true
45
+ has_attributes :identifier_type, :datastream=>'descMetadata', :at=>[:mods, :identifier, :type_at], :multiple=> true
46
+ has_attributes :publisher_name, :datastream=>'descMetadata', :at=>[:mods, :origin_info, :publisher], :multiple=> true
47
+ has_attributes :publisher_place, :datastream=>'descMetadata', :at=>[:mods, :origin_info, :place, :place_term], :multiple=> true
48
+ has_attributes :extent, :datastream=>'descMetadata', :at=>[:mods, :physical_description, :extent], :multiple=> true
49
+ has_attributes :digital_source, :datastream=>'descMetadata', :at=>[:mods, :physical_description, :digital_origin], :multiple=> true
50
+ has_attributes :note, :datastream=>'descMetadata', :at=>[:mods, :note], :multiple=> true
51
+ has_attributes :note_type, :datastream=>'descMetadata', :at=>[:mods, :note, :type_at], :multiple=> true
52
+ has_attributes :subject_place_value, :datastream=>'descMetadata', :at=>[:mods, :subject, :geographic], :multiple=> true
53
+ has_attributes :subject_name_value, :datastream=>'descMetadata', :at=>[:mods, :subject, :name, :name_part], :multiple=> true
54
+ has_attributes :subject_name_type, :datastream=>'descMetadata', :at=>[:mods, :subject, :name, :type], :multiple=> true
55
+ has_attributes :subject_topic_value, :datastream=>'descMetadata', :at=>[:mods, :subject, :topic], :multiple=> true
56
+ has_attributes :subject_authority, :datastream=>'descMetadata', :at=>[:mods, :subject, :authority], :multiple=> true
57
+ has_attributes :language, :datastream=>'descMetadata', :at=>[:mods, :language, :language_term], :multiple=> true
58
+ has_attributes :language_uri, :datastream=>'descMetadata', :at=>[:mods, :language, :language_term, :lang_val_uri], :multiple=> true
59
+ has_attributes :description, :datastream=>'descMetadata', :at => [:abstract], :multiple=> false
60
+
61
+
62
+
63
+ def apply_default_permissions
64
+ self.datastreams["rightsMetadata"].update_permissions( "group"=>{"Repository Administrators"=>"edit", "Repository Administrators"=>"read", "Repository Administrators"=>"discover"} )
65
+ self.save
66
+ end
67
+
68
+ def add_oai_relationships
69
+ self.add_relationship(:oai_item_id, "oai:digitalcommonwealth.org:" + self.pid, true)
70
+ end
71
+
72
+ #alias :limited_delete :delete
73
+
74
+ =begin
75
+ def save
76
+ super()
77
+ end
78
+ =end
79
+
80
+ def delete(delete_files=true)
81
+ if delete_files
82
+ Bplmodels::File.find_in_batches('is_file_of_ssim'=>"info:fedora/#{self.pid}") do |group|
83
+ group.each { |solr_file|
84
+ file = Bplmodels::File.find(solr_file['id']).adapt_to_cmodel
85
+ file.delete
86
+ }
87
+ end
88
+ end
89
+ super()
90
+ end
91
+
92
+ #Rough initial attempt at this implementation
93
+ #use test2.relationships(:has_model)?
94
+ def convert_to(klass)
95
+ #if !self.instance_of?(klass)
96
+ adapted_object = self.adapt_to(klass)
97
+
98
+ self.relationships.each_statement do |statement|
99
+ if statement.predicate == "info:fedora/fedora-system:def/model#hasModel"
100
+ self.remove_relationship(:has_model, statement.object)
101
+ end
102
+ end
103
+
104
+ adapted_object.assert_content_model
105
+ adapted_object.save
106
+ adapted_object
107
+ #end
108
+
109
+ end
110
+
111
+
112
+ def assert_content_model
113
+ super()
114
+ object_superclass = self.class.superclass
115
+ until object_superclass == ActiveFedora::Base || object_superclass == Object do
116
+ add_relationship(:has_model, object_superclass.to_class_uri)
117
+ object_superclass = object_superclass.superclass
118
+ end
119
+ end
120
+
121
+ def to_solr(doc = {} )
122
+ doc = super(doc)
123
+ #doc['has_model_ssim'] = [doc['has_model_ssim'][0], 'info:fedora/afmodel:Bplmodels_SimpleObjectBase']
124
+
125
+
126
+ doc['label_ssim'] = self.label.to_s
127
+ #1995-12-31T23:59:59.999Z
128
+ doc['date_start_dtsi'] = []
129
+ doc['date_start_tsim'] = []
130
+ doc['date_end_dtsi'] = []
131
+ doc['date_end_tsim'] = []
132
+ doc['date_facet_ssim'] = []
133
+ doc['date_type_ssm'] = []
134
+ doc['date_start_qualifier_ssm'] = []
135
+ dates_static = []
136
+ dates_start = []
137
+ dates_end = []
138
+
139
+ # dateOther
140
+ if self.descMetadata.date(0).date_other[0] != nil && self.descMetadata.date(0).date_other.length > 0
141
+ if self.descMetadata.date(0).date_other[0] == 'undated'
142
+ # do nothing -- don't want to index this
143
+ else
144
+ # TODO insert code for date_other values here
145
+ end
146
+ end
147
+
148
+ # dateCreated, dateIssued, copyrightDate
149
+ if self.descMetadata.date(0).dates_created[0] || self.descMetadata.date(0).dates_issued[0] || self.descMetadata.date(0).dates_copyright[0]
150
+
151
+ #dateCreated
152
+ if self.descMetadata.date(0).dates_created[0]
153
+ self.descMetadata.date(0).dates_created.each_with_index do |date,index|
154
+ #FIXME: Has to add "date.present" and the when '' case for oai-test:h415pc718
155
+ if date.present?
156
+ case self.descMetadata.date(0).dates_created(index).point[0]
157
+ when nil, ''
158
+ dates_static << date
159
+ doc['date_type_ssm'] << 'dateCreated'
160
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_created(index).qualifier[0].presence || 'nil')
161
+ when 'start'
162
+ dates_start << date
163
+ doc['date_type_ssm'] << 'dateCreated'
164
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_created(index).qualifier[0].presence || 'nil')
165
+ when 'end'
166
+ dates_end << date
167
+ end
168
+ end
169
+ end
170
+ end
171
+ # dateIssued
172
+ if self.descMetadata.date(0).dates_issued[0]
173
+ self.descMetadata.date(0).dates_issued.each_with_index do |date,index|
174
+ case self.descMetadata.date(0).dates_issued(index).point[0]
175
+ when nil
176
+ dates_static << date
177
+ doc['date_type_ssm'] << 'dateIssued'
178
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_issued(index).qualifier[0].presence || 'nil')
179
+ when 'start'
180
+ dates_start << date
181
+ doc['date_type_ssm'] << 'dateIssued'
182
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_issued(index).qualifier[0].presence || 'nil')
183
+ when 'end'
184
+ dates_end << date
185
+ end
186
+ end
187
+ end
188
+ # dateCopyright
189
+ if self.descMetadata.date(0).dates_copyright[0]
190
+ self.descMetadata.date(0).dates_copyright.each_with_index do |date,index|
191
+ case self.descMetadata.date(0).dates_copyright(index).point[0]
192
+ when nil
193
+ dates_static << date
194
+ doc['date_type_ssm'] << 'copyrightDate'
195
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_copyright(index).qualifier[0].presence || 'nil')
196
+ when 'start'
197
+ dates_start << date
198
+ doc['date_type_ssm'] << 'copyrightDate'
199
+ doc['date_start_qualifier_ssm'].append(self.descMetadata.date(0).dates_copyright(index).qualifier[0].presence || 'nil')
200
+ when 'end'
201
+ dates_end << date
202
+ end
203
+ end
204
+ end
205
+
206
+ # push the date values as-is into text fields
207
+ dates_static.each do |static_date|
208
+ doc['date_start_tsim'] << static_date
209
+ doc['date_end_tsim'] << 'nil' # hacky, but can't assign null in Solr
210
+ end
211
+ dates_start.each do |start_date|
212
+ doc['date_start_tsim'] << start_date
213
+ end
214
+ dates_end.each do |end_date|
215
+ doc['date_end_tsim'] << end_date
216
+ end
217
+
218
+ # set the date ranges for date-time fields and decade faceting
219
+ earliest_date = (dates_static + dates_start).sort[0]
220
+ date_facet_start = earliest_date[0..3].to_i
221
+
222
+ if earliest_date.length == 4
223
+ doc['date_start_dtsi'].append(earliest_date + '-01-01T00:00:00.000Z')
224
+ elsif earliest_date.length == 7
225
+ doc['date_start_dtsi'].append(earliest_date + '-01T01:00:00.000Z')
226
+ elsif earliest_date.length > 11
227
+ doc['date_start_dtsi'].append(earliest_date)
228
+ else
229
+ doc['date_start_dtsi'].append(earliest_date + 'T00:00:00.000Z')
230
+ end
231
+
232
+ if dates_end[0]
233
+ latest_date = dates_end.reverse[0]
234
+ date_facet_end = latest_date[0..3].to_i
235
+ if latest_date.length == 4
236
+ doc['date_end_dtsi'].append(latest_date + '-12-31T23:59:59.999Z')
237
+ elsif latest_date.length == 7
238
+ # TODO: DD value should be dependent on MM value
239
+ # e.g., '31' for January, but '28' for February, etc.
240
+ doc['date_end_dtsi'].append(latest_date + '-28T23:59:59.999Z')
241
+ elsif latest_date.length > 11
242
+ doc['date_end_dtsi'].append(latest_date)
243
+ else
244
+ doc['date_end_dtsi'].append(latest_date + 'T23:59:59.999Z')
245
+ end
246
+ else
247
+ date_facet_end = 0
248
+ end
249
+
250
+ # decade faceting
251
+ (1500..2020).step(10) do |index|
252
+ if ((date_facet_start >= index && date_facet_start < index+10) || (date_facet_end != -1 && index > date_facet_start && date_facet_end >= index))
253
+ doc['date_facet_ssim'].append(index.to_s + 's')
254
+ end
255
+ end
256
+
257
+ doc['date_facet_yearly_ssim'] = []
258
+ # yearly faceting
259
+ (1500..2020).step(1) do |index|
260
+ if ((date_facet_start >= index && date_facet_start < index+1) || (date_facet_end != -1 && index > date_facet_start && date_facet_end >= index))
261
+ doc['date_facet_yearly_ssim'].append(index.to_s + 's')
262
+ end
263
+ end
264
+
265
+ end
266
+
267
+ doc['abstract_tsim'] = self.descMetadata.abstract
268
+ doc['table_of_contents_tsi'] = self.descMetadata.table_of_contents[0]
269
+
270
+ doc['genre_basic_tsim'] = self.descMetadata.genre_basic
271
+ doc['genre_specific_tsim'] = self.descMetadata.genre_specific
272
+
273
+ doc['genre_basic_ssim'] = self.descMetadata.genre_basic
274
+ doc['genre_specific_ssim'] = self.descMetadata.genre_specific
275
+
276
+ # will need to make this more generic when we have more id fields with @invalid
277
+ if self.descMetadata.local_other
278
+ doc['identifier_local_other_tsim'] = []
279
+ doc['identifier_local_other_invalid_tsim'] = []
280
+ self.descMetadata.identifier.each_with_index do |id_val, index|
281
+ if self.descMetadata.identifier(index).type_at[0] == 'local-other'
282
+ if self.descMetadata.identifier(index).invalid[0]
283
+ doc['identifier_local_other_invalid_tsim'].append(id_val)
284
+ else
285
+ doc['identifier_local_other_tsim'].append(id_val)
286
+ end
287
+ end
288
+ end
289
+ end
290
+
291
+
292
+ doc['identifier_local_call_tsim'] = self.descMetadata.local_call
293
+ doc['identifier_local_barcode_tsim'] = self.descMetadata.local_barcode
294
+ doc['identifier_isbn_tsim'] = self.descMetadata.isbn
295
+ doc['identifier_lccn_tsim'] = self.descMetadata.lccn
296
+
297
+ doc['identifier_ark_ssi'] = ''
298
+
299
+ doc['local_accession_id_tsim'] = self.descMetadata.local_accession[0].to_s
300
+ if self.collection
301
+ doc['collection_name_ssim'] = self.collection.label.to_s
302
+ doc['collection_name_tsim'] = self.collection.label.to_s
303
+ doc['collection_pid_ssm'] = self.collection.pid
304
+
305
+ if self.collection
306
+ if self.collection.institutions
307
+ doc['institution_name_ssim'] = self.collection.institutions.label.to_s
308
+ doc['institution_name_tsim'] = self.collection.institutions.label.to_s
309
+ doc['institution_pid_ssi'] = self.collection.institutions.pid
310
+ end
311
+ end
312
+
313
+ end
314
+
315
+
316
+ #self.descMetadata.identifier_uri.each do |identifier|
317
+ #if idenfifier.include?("ark")
318
+ #doc['identifier_uri_ss'] = self.descMetadata.identifier_uri
319
+ #end
320
+ #end
321
+ if self.descMetadata.identifier_uri.length > 1
322
+ doc['identifier_uri_ss'] = self.descMetadata.identifier_uri[1]
323
+ else
324
+ doc['identifier_uri_ss'] = self.descMetadata.identifier_uri[0]
325
+ end
326
+
327
+
328
+ doc['publisher_tsim'] = self.descMetadata.origin_info.publisher
329
+
330
+ doc['pubplace_tsim'] = self.descMetadata.origin_info.place.place_term
331
+
332
+ doc['edition_tsim'] = self.descMetadata.origin_info.edition
333
+
334
+ doc['issuance_tsim'] = self.descMetadata.origin_info.issuance
335
+
336
+ doc['lang_term_ssim'] = self.descMetadata.language.language_term
337
+ #doc['lang_val_uri_ssim'] = self.descMetadata.language.language_term.lang_val_uri
338
+
339
+ # relatedItem, except subseries, subsubseries, etc.
340
+ if self.descMetadata.mods(0).related_item.length > 0
341
+ (0..self.descMetadata.mods(0).related_item.length-1).each do |index|
342
+ related_item_type = self.descMetadata.mods(0).related_item(index).type[0]
343
+ if related_item_type == 'isReferencedBy'
344
+ doc['related_item_' + related_item_type.downcase + '_ssm'] ||= []
345
+ doc['related_item_' + related_item_type.downcase + '_ssm'].append(self.descMetadata.mods(0).related_item(index).href[0])
346
+ else
347
+ doc['related_item_' + related_item_type + '_tsim'] ||= []
348
+ doc['related_item_' + related_item_type + '_ssim'] ||= []
349
+ related_title_prefix = self.descMetadata.mods(0).related_item(index).title_info.nonSort[0] ? self.descMetadata.mods(0).related_item(index).title_info.nonSort[0] + ' ' : ''
350
+ doc['related_item_' + related_item_type + '_tsim'].append(related_title_prefix + self.descMetadata.mods(0).related_item(index).title_info.title[0])
351
+ doc['related_item_' + related_item_type + '_ssim'].append(related_title_prefix + self.descMetadata.mods(0).related_item(index).title_info.title[0])
352
+ end
353
+ end
354
+ end
355
+
356
+ # subseries
357
+ if self.descMetadata.related_item.subseries
358
+ doc['related_item_subseries_tsim'] ||= []
359
+ doc['related_item_subseries_ssim'] ||= []
360
+ (0..self.descMetadata.mods(0).related_item.subseries.length-1).each do |index|
361
+ subseries_prefix = self.descMetadata.mods(0).related_item.subseries(index).title_info.nonSort[0] ? self.descMetadata.mods(0).related_item.subseries(index).title_info.nonSort[0] + ' ' : ''
362
+ subseries_value = subseries_prefix + self.descMetadata.mods(0).related_item.subseries(index).title_info.title[0]
363
+ doc['related_item_subseries_tsim'].append(subseries_value)
364
+ doc['related_item_subseries_ssim'].append(subseries_value)
365
+ end
366
+ end
367
+
368
+ # subsubseries
369
+ if self.descMetadata.related_item.subseries.subsubseries
370
+ doc['related_item_subsubseries_tsim'] ||= []
371
+ doc['related_item_subsubseries_ssim'] ||= []
372
+ (0..self.descMetadata.mods(0).related_item.subseries.subsubseries.length-1).each do |index|
373
+ subsubseries_prefix = self.descMetadata.mods(0).related_item.subseries.subsubseries(index).title_info.nonSort[0] ? self.descMetadata.mods(0).related_item.subseries.subsubseries(index).title_info.nonSort[0] + ' ' : ''
374
+ subsubseries_value = subsubseries_prefix + self.descMetadata.mods(0).related_item.subseries.subsubseries(index).title_info.title[0]
375
+ doc['related_item_subsubseries_tsim'].append(subsubseries_value)
376
+ doc['related_item_subsubseries_ssim'].append(subsubseries_value)
377
+ end
378
+ end
379
+
380
+ #doc['titleInfo_primary_ssim'] = self.descMetadata.title_info(0).main_title.to_s
381
+ #doc['name_personal_ssim'] = self.descMetadata.name(0).to_s
382
+
383
+ doc['name_personal_tsim'] = []
384
+ doc['name_personal_role_tsim'] = []
385
+ doc['name_corporate_tsim'] = []
386
+ doc['name_corporate_role_tsim'] = []
387
+
388
+ doc['name_generic_tsim'] = []
389
+ doc['name_generic_role_tsim'] = []
390
+
391
+ 0.upto self.descMetadata.mods(0).name.length-1 do |index|
392
+ if self.descMetadata.mods(0).name(index).type[0] == "personal"
393
+ if self.descMetadata.mods(0).name(index).date.length > 0
394
+ doc['name_personal_tsim'].append(self.descMetadata.mods(0).name(index).namePart[0] + ", " + self.descMetadata.mods(0).name(index).date[0])
395
+ else
396
+ doc['name_personal_tsim'].append(self.descMetadata.mods(0).name(index).namePart[0])
397
+ end
398
+ if self.descMetadata.mods(0).name(index).role.length > 1
399
+ doc['name_personal_role_tsim'].append(self.descMetadata.mods(0).name(0).role.join('||').gsub(/[\n]\s*/,''))
400
+ else
401
+ doc['name_personal_role_tsim'].append(self.descMetadata.mods(0).name(index).role.text[0])
402
+ end
403
+
404
+ elsif self.descMetadata.mods(0).name(index).type[0] == "corporate"
405
+ corporate_name = self.descMetadata.mods(0).name(index).namePart.join(". ").gsub(/\.\./,'.')
406
+ # TODO -- do we need the conditional below?
407
+ # don't think corp names have dates
408
+ if self.descMetadata.mods(0).name(index).date.length > 0
409
+ doc['name_corporate_tsim'].append(corporate_name + ", " + self.descMetadata.mods(0).name(index).date[0])
410
+ else
411
+ doc['name_corporate_tsim'].append(corporate_name)
412
+ end
413
+ if self.descMetadata.mods(0).name(index).role.length > 1
414
+ doc['name_corporate_role_tsim'].append(self.descMetadata.mods(0).name(0).role.join('||').gsub(/[\n]\s*/,''))
415
+ else
416
+ doc['name_corporate_role_tsim'].append(self.descMetadata.mods(0).name(index).role.text[0])
417
+ end
418
+
419
+ else
420
+ if self.descMetadata.mods(0).name(index).date.length > 0
421
+ doc['name_generic_tsim'].append(self.descMetadata.mods(0).name(index).namePart[0] + ", " + self.descMetadata.mods(0).name(index).date[0])
422
+ else
423
+ doc['name_generic_tsim'].append(self.descMetadata.mods(0).name(index).namePart[0])
424
+ end
425
+ if self.descMetadata.mods(0).name(index).role.length > 1
426
+ doc['name_generic_role_tsim'].append(self.descMetadata.mods(0).name(0).role.join('||').gsub(/[\n]\s*/,''))
427
+ else
428
+ doc['name_generic_role_tsim'].append(self.descMetadata.mods(0).name(index).role.text[0])
429
+ end
430
+ end
431
+
432
+ end
433
+
434
+ doc['name_facet_ssim'] = doc['name_personal_tsim'] + doc['name_corporate_tsim'] + doc['name_generic_tsim']
435
+
436
+
437
+ doc['type_of_resource_ssim'] = self.descMetadata.type_of_resource
438
+
439
+ doc['extent_tsi'] = self.descMetadata.physical_description(0).extent[0]
440
+ doc['digital_origin_ssi'] = self.descMetadata.physical_description(0).digital_origin[0]
441
+ doc['internet_media_type_ssim'] = self.descMetadata.physical_description(0).internet_media_type
442
+
443
+ doc['physical_location_ssim'] = self.descMetadata.item_location(0).physical_location
444
+ doc['physical_location_tsim'] = self.descMetadata.item_location(0).physical_location
445
+
446
+ doc['sub_location_tsim'] = self.descMetadata.item_location(0).holding_simple(0).copy_information(0).sub_location
447
+
448
+ doc['shelf_locator_tsim'] = self.descMetadata.item_location(0).holding_simple(0).copy_information(0).shelf_locator
449
+
450
+ doc['subject_topic_tsim'] = self.descMetadata.subject.topic
451
+
452
+ # subject - geographic
453
+ subject_geo = self.descMetadata.subject.geographic
454
+
455
+ # subject - hierarchicalGeographic
456
+ country = self.descMetadata.subject.hierarchical_geographic.country
457
+ province = self.descMetadata.subject.hierarchical_geographic.province
458
+ region = self.descMetadata.subject.hierarchical_geographic.region
459
+ state = self.descMetadata.subject.hierarchical_geographic.state
460
+ territory = self.descMetadata.subject.hierarchical_geographic.territory
461
+ county = self.descMetadata.subject.hierarchical_geographic.county
462
+ city = self.descMetadata.subject.hierarchical_geographic.city
463
+ city_section = self.descMetadata.subject.hierarchical_geographic.city_section
464
+ island = self.descMetadata.subject.hierarchical_geographic.island
465
+ area = self.descMetadata.subject.hierarchical_geographic.area
466
+
467
+ doc['subject_geo_country_ssim'] = country
468
+ doc['subject_geo_province_ssim'] = province
469
+ doc['subject_geo_region_ssim'] = region
470
+ doc['subject_geo_state_ssim'] = state
471
+ doc['subject_geo_territory_ssim'] = territory
472
+ doc['subject_geo_county_ssim'] = county
473
+ doc['subject_geo_city_ssim'] = city
474
+ doc['subject_geo_citysection_ssim'] = city_section
475
+ doc['subject_geo_island_ssim'] = island
476
+ doc['subject_geo_area_ssim'] = area
477
+
478
+ geo_subjects = (country + province + region + state + territory + area + island + city + city_section + subject_geo).uniq # all except 'county'
479
+
480
+ # add all subject-geo values to subject-geo text field for searching (remove dupes)
481
+ doc['subject_geographic_tsim'] = geo_subjects + county.uniq
482
+
483
+ # add " (county)" to county values for better faceting
484
+ county_facet = []
485
+ if county.length > 0
486
+ county.each do |county_value|
487
+ county_facet << county_value + ' (county)'
488
+ end
489
+ end
490
+
491
+ # add all subject-geo values to subject-geo facet field (remove dupes)
492
+ doc['subject_geographic_ssim'] = geo_subjects + county_facet.uniq
493
+
494
+ # scale
495
+ doc['subject_scale_tsim'] = self.descMetadata.subject.cartographics.scale
496
+
497
+ # coordinates / bbox
498
+ if self.descMetadata.subject.cartographics.coordinates.length > 0
499
+ doc['subject_coordinates_geospatial'] = self.descMetadata.subject.cartographics.coordinates # includes both bbox and point data
500
+ self.descMetadata.subject.cartographics.coordinates.each do |coordinates|
501
+ if coordinates.scan(/[\s]/).length == 3
502
+ doc['subject_bbox_geospatial'] ||= []
503
+ doc['subject_bbox_geospatial'] << coordinates
504
+ else
505
+ doc['subject_point_geospatial'] ||= []
506
+ doc['subject_point_geospatial'] << coordinates
507
+ end
508
+ end
509
+ end
510
+
511
+ # geographic data as GeoJSON (2 fields)
512
+ # subject_geojson_facet_ssim = for map-based faceting + display
513
+ # subject_hiergeo_geojson_ssm = for display of hiergeo metadata
514
+ doc['subject_geojson_facet_ssim'] = []
515
+ doc['subject_hiergeo_geojson_ssm'] = []
516
+ doc['subject_geo_nonhier_ssim'] = [] # other non-hierarchical geo subjects
517
+ 0.upto self.descMetadata.subject.length-1 do |subject_index|
518
+
519
+ this_subject = self.descMetadata.mods(0).subject(subject_index)
520
+
521
+ # TGN-id-derived hierarchical geo subjects. assumes only longlat points, no bboxes
522
+ if this_subject.hierarchical_geographic.any?
523
+ geojson_hash_base = {type: 'Feature', geometry: {type: 'Point'}}
524
+
525
+ if this_subject.cartographics.coordinates.any? # get the coordinates
526
+ coords = this_subject.cartographics.coordinates[0]
527
+ if coords.match(/^[-]?[\d]*[\.]?[\d]*,[-]?[\d]*[\.]?[\d]*$/)
528
+ geojson_hash_base[:geometry][:coordinates] = coords.split(',').reverse.map { |v| v.to_f }
529
+ end
530
+ end
531
+
532
+ facet_geojson_hash = geojson_hash_base.dup
533
+ hiergeo_geojson_hash = geojson_hash_base.dup
534
+
535
+ # get the hierGeo elements, except 'continent'
536
+ hiergeo_hash = {}
537
+ ModsDescMetadata.terminology.retrieve_node(:subject,:hierarchical_geographic).children.each do |hgterm|
538
+ hiergeo_hash[hgterm[0]] = '' unless hgterm[0].to_s == 'continent'
539
+ end
540
+ hiergeo_hash.each_key do |k|
541
+ hiergeo_hash[k] = this_subject.hierarchical_geographic.send(k)[0].presence
542
+ end
543
+ hiergeo_hash.reject! {|k,v| !v } # remove any nil values
544
+
545
+ if this_subject.geographic[0]
546
+ other_geo_value = this_subject.geographic[0]
547
+ other_geo_value << " (#{this_subject.geographic.display_label[0]})" if this_subject.geographic.display_label[0]
548
+ hiergeo_hash[:other] = other_geo_value
549
+ end
550
+
551
+ unless hiergeo_hash.empty?
552
+ hiergeo_geojson_hash[:properties] = hiergeo_hash
553
+ facet_geojson_hash[:properties] = {placename: DatastreamInputFuncs.render_display_placename(hiergeo_hash)}
554
+ doc['subject_hiergeo_geojson_ssm'].append(hiergeo_geojson_hash.to_json)
555
+ end
556
+
557
+ if geojson_hash_base[:geometry][:coordinates].is_a?(Array)
558
+ doc['subject_geojson_facet_ssim'].append(facet_geojson_hash.to_json)
559
+ end
560
+
561
+ end
562
+
563
+ # coordinates or bboxes w/o hierGeo elements, but maybe non-hierGeo geographic strings
564
+ if this_subject.cartographics.coordinates.any? && this_subject.hierarchical_geographic.blank?
565
+ geojson_hash = {type: 'Feature', geometry: {type: '', coordinates: []}}
566
+ coords = this_subject.cartographics.coordinates[0]
567
+ if coords.scan(/[\s]/).length == 3 #bbox TODO: better checking for bbox syntax
568
+ unless coords == '-180.0 -90.0 180.0 90.0' # don't want 'whole world' bboxes
569
+ coords_array = coords.split(' ').map { |v| v.to_f }
570
+ if coords_array[0] > coords_array[2] # bbox that crosses dateline
571
+ if coords_array[0] > 0
572
+ degrees_to_add = 180-coords_array[0]
573
+ coords_array[0] = -(180 + degrees_to_add)
574
+ elsif coords_array[0] < 0 && coords_array[2] < 0
575
+ degrees_to_add = 180+coords_array[2]
576
+ coords_array[2] = 180 + degrees_to_add
577
+ else
578
+ Rails.logger.error("This bbox format was not parsed correctly: '#{coords}'")
579
+ end
580
+ end
581
+ geojson_hash[:bbox] = coords_array
582
+ geojson_hash[:geometry][:type] = 'Polygon'
583
+ geojson_hash[:geometry][:coordinates] = [[[coords_array[0],coords_array[1]],
584
+ [coords_array[2],coords_array[1]],
585
+ [coords_array[2],coords_array[3]],
586
+ [coords_array[0],coords_array[3]],
587
+ [coords_array[0],coords_array[1]]]]
588
+ end
589
+ elsif coords.match(/^[-]?[\d]+[\.]?[\d]*,[\s]?[-]?[\d]+[\.]?[\d]*$/)
590
+ geojson_hash[:geometry][:type] = 'Point'
591
+ geojson_hash[:geometry][:coordinates] = coords.split(',').reverse.map { |v| v.to_f }
592
+ end
593
+
594
+ if this_subject.geographic[0]
595
+ doc['subject_geo_nonhier_ssim'] << this_subject.geographic[0]
596
+ geojson_hash[:properties] = {placename: this_subject.geographic[0]}
597
+ end
598
+
599
+ unless geojson_hash[:geometry][:coordinates].blank?
600
+ doc['subject_geojson_facet_ssim'].append(geojson_hash.to_json)
601
+ end
602
+ end
603
+
604
+ # non-hierarchical geo subjects w/o coordinates
605
+ if this_subject.cartographics.coordinates.empty? && this_subject.hierarchical_geographic.blank? && this_subject.geographic[0]
606
+ doc['subject_geo_nonhier_ssim'] << this_subject.geographic[0]
607
+ end
608
+
609
+ end
610
+
611
+ =begin
612
+ new_logger = Logger.new('log/geo_log')
613
+ new_logger.level = Logger::ERROR
614
+
615
+ #Blacklight-maps esque placename_coords
616
+ 0.upto self.descMetadata.subject.length-1 do |subject_index|
617
+ if self.descMetadata.mods(0).subject(subject_index).cartographics.present? && self.descMetadata.mods(0).subject(subject_index).cartographics.scale.blank?
618
+ place_name = "Results"
619
+
620
+ if self.descMetadata.mods(0).subject(subject_index).authority == ['tgn'] && self.descMetadata.mods(0).subject(subject_index).hierarchical_geographic[0].blank?
621
+ new_logger.error "Weird Geography for: " + self.pid
622
+ end
623
+
624
+ if self.descMetadata.mods(0).subject(subject_index).authority == ['tgn'] && self.descMetadata.mods(0).subject(subject_index).hierarchical_geographic[0].present?
625
+ place_locations = []
626
+ self.descMetadata.mods(0).subject(subject_index).hierarchical_geographic[0].split("\n").each do |split_geo|
627
+ split_geo = split_geo.strip
628
+ place_locations << split_geo if split_geo.present? && !split_geo.include?('North and Central America') && !split_geo.include?('United States')
629
+ end
630
+ place_name = place_locations.reverse.join(', ')
631
+ elsif self.descMetadata.mods(0).subject(subject_index).geographic.present?
632
+ place_name = self.descMetadata.mods(0).subject(subject_index).geographic.first
633
+ end
634
+
635
+ doc['subject_blacklight_maps_ssim'] = "#{place_name}-|-#{self.descMetadata.mods(0).subject(subject_index).cartographics.coordinates[0].split(',').first}-|-#{self.descMetadata.mods(0).subject(subject_index).cartographics.coordinates[0].split(',').last}"
636
+ end
637
+ end
638
+ =end
639
+ #Blacklight-maps coords only
640
+ =begin
641
+ best_coords_found = false
642
+ 0.upto self.descMetadata.subject.length-1 do |subject_index|
643
+ if self.descMetadata.mods(0).subject(subject_index).cartographics.present?
644
+ if self.descMetadata.mods(0).subject(subject_index).authority.present? && self.descMetadata.mods(0).subject(subject_index).authority != ['tgn']
645
+ best_coords_found = true
646
+ doc['subject_blacklight_maps_coords_ssim'] = self.descMetadata.mods(0).subject(subject_index).cartographics.coordinates[0]
647
+ end
648
+ end
649
+ end
650
+ 0.upto self.descMetadata.subject.length-1 do |subject_index|
651
+ if self.descMetadata.mods(0).subject(subject_index).cartographics.present? && !best_coords_found
652
+ doc['subject_blacklight_maps_coords_ssim'] = self.descMetadata.mods(0).subject(subject_index).cartographics.coordinates[0]
653
+ end
654
+ end
655
+ =end
656
+
657
+ # name subjects
658
+ doc['subject_name_personal_tsim'] = []
659
+ doc['subject_name_corporate_tsim'] = []
660
+ doc['subject_name_conference_tsim'] = []
661
+ doc['subject_facet_ssim'] = []
662
+ 0.upto self.descMetadata.subject.length-1 do |index|
663
+ if self.descMetadata.subject(index).personal_name.length > 0
664
+ if self.descMetadata.subject(index).personal_name.date.length > 0
665
+ subject_name_personal = self.descMetadata.subject(index).personal_name.name_part[0] + ", " + self.descMetadata.subject(index).personal_name.date[0]
666
+ else
667
+ subject_name_personal = self.descMetadata.subject(index).personal_name.name_part[0]
668
+ end
669
+ doc['subject_name_personal_tsim'].append(subject_name_personal)
670
+ doc['subject_facet_ssim'].append(subject_name_personal)
671
+ end
672
+ if self.descMetadata.subject(index).corporate_name.length > 0
673
+ subject_name_corporate = self.descMetadata.subject(index).corporate_name.name_part.join('. ').gsub(/\.\./,'.')
674
+ # TODO -- do we need the conditional below?
675
+ # don't think corp names have dates
676
+ if self.descMetadata.subject(index).corporate_name.date.length > 0
677
+ subject_name_corporate = subject_name_corporate + ", " + self.descMetadata.subject(index).corporate_name.date[0]
678
+ end
679
+ doc['subject_name_corporate_tsim'].append(subject_name_corporate)
680
+ doc['subject_facet_ssim'].append(subject_name_corporate)
681
+ end
682
+ if self.descMetadata.subject(index).conference_name.length > 0
683
+ subject_name_conference = self.descMetadata.subject(index).conference_name.name_part[0]
684
+ doc['subject_name_conference_tsim'].append(subject_name_conference)
685
+ doc['subject_facet_ssim'].append(subject_name_conference)
686
+ end
687
+
688
+ end
689
+
690
+ #doc['subject_facet_ssim'] = self.descMetadata.subject.topic + self.descMetadata.subject.corporate_name.name_part + self.descMetadata.subject.personal_name.name_part
691
+
692
+ doc['subject_facet_ssim'].concat(self.descMetadata.subject.topic)
693
+
694
+ # temporal subjects
695
+ if self.descMetadata.subject.temporal.length > 0
696
+ doc['subject_temporal_start_tsim'] = []
697
+ doc['subject_temporal_start_dtsim'] = []
698
+ doc['subject_temporal_facet_ssim'] = []
699
+ subject_date_range_start = []
700
+ subject_date_range_end = []
701
+ self.descMetadata.subject.temporal.each_with_index do |value,index|
702
+ if self.descMetadata.subject.temporal.point[index] != 'end'
703
+ subject_temporal_start = value
704
+ doc['subject_temporal_start_tsim'].append(subject_temporal_start)
705
+ subject_date_range_start.append(subject_temporal_start)
706
+ # subject_temporal_start.length > 4 ? subject_date_range_start.append(subject_temporal_start[0..3]) : subject_date_range_start.append(subject_temporal_start)
707
+ if subject_temporal_start.length == 4
708
+ doc['subject_temporal_start_dtsim'].append(subject_temporal_start + '-01-01T00:00:00.000Z')
709
+ elsif subject_temporal_start.length == 7
710
+ doc['subject_temporal_start_dtsim'].append(subject_temporal_start + '-01T01:00:00.000Z')
711
+ else
712
+ doc['subject_temporal_start_dtsim'].append(subject_temporal_start + 'T00:00:00.000Z')
713
+ end
714
+ else
715
+ doc['subject_temporal_end_tsim'] = []
716
+ doc['subject_temporal_end_dtsim'] = []
717
+ subject_temporal_end = value
718
+ doc['subject_temporal_end_tsim'].append(subject_temporal_end)
719
+ subject_date_range_end.append(subject_temporal_end)
720
+ # subject_temporal_end.length > 4 ? subject_date_range_end.append(subject_temporal_end[0..3]) : subject_date_range_end.append(subject_temporal_end)
721
+ if subject_temporal_end.length == 4
722
+ doc['subject_temporal_end_dtsim'].append(subject_temporal_end + '-01-01T00:00:00.000Z')
723
+ elsif subject_temporal_end.length == 7
724
+ doc['subject_temporal_end_dtsim'].append(subject_temporal_end + '-01T01:00:00.000Z')
725
+ else
726
+ doc['subject_temporal_end_dtsim'].append(subject_temporal_end + 'T00:00:00.000Z')
727
+ end
728
+ end
729
+ end
730
+
731
+ if subject_date_range_start.length > 0
732
+ subject_date_range_start.each_with_index do |date_start,index|
733
+ if subject_date_range_end.present?
734
+ doc['subject_temporal_facet_ssim'].append(date_start[0..3] + '-' + subject_date_range_end[index][0..3])
735
+ else
736
+ doc['subject_temporal_facet_ssim'].append(date_start)
737
+ end
738
+ end
739
+ end
740
+
741
+ doc['subject_facet_ssim'].concat(doc['subject_temporal_facet_ssim'])
742
+
743
+ end
744
+
745
+ # title subjects
746
+ if self.descMetadata.subject.title_info.length > 0
747
+ doc['subject_title_tsim'] = []
748
+ self.descMetadata.subject.title_info.title.each do |subject_title|
749
+ doc['subject_title_tsim'] << subject_title
750
+ end
751
+ doc['subject_facet_ssim'].concat(doc['subject_title_tsim'])
752
+ end
753
+
754
+ # de-dupe various subject fields (needed for LCSH-style subjects from MODS OAI feeds)
755
+ subjs_to_dedupe = %w(subject_topic_tsim subject_geo_nonhier_ssim subject_hiergeo_geojson_ssm subject_name_corporate_tsim subject_name_personal_tsim subject_name_conference_tsim subject_temporal_facet_ssim subject_title_tsim)
756
+ subjs_to_dedupe.each do |subj_to_dedupe|
757
+ doc[subj_to_dedupe] = doc[subj_to_dedupe].uniq if doc[subj_to_dedupe]
758
+ end
759
+
760
+ # remove values from subject_geo_nonhier_ssim
761
+ # that are represented in subject_hiergeo_geojson_ssm
762
+ if doc['subject_geo_nonhier_ssim'] && doc['subject_hiergeo_geojson_ssm']
763
+ doc['subject_geo_nonhier_ssim'].each do |non_hier_geo_subj|
764
+ doc['subject_hiergeo_geojson_ssm'].each do |hiergeo_geojson_feature|
765
+ if hiergeo_geojson_feature.match(/#{non_hier_geo_subj}/)
766
+ doc['subject_geo_nonhier_ssim'].delete(non_hier_geo_subj)
767
+ end
768
+ end
769
+ end
770
+ end
771
+
772
+ doc['active_fedora_model_suffix_ssi'] = self.rels_ext.model.class.to_s.gsub(/\A[\w]*::/,'')
773
+
774
+ doc['rights_ssm'] = []
775
+ doc['license_ssm'] = []
776
+ 0.upto self.descMetadata.use_and_reproduction.length-1 do |index|
777
+ case self.descMetadata.use_and_reproduction(index).displayLabel.first
778
+ when 'rights'
779
+ doc['rights_ssm'] << self.descMetadata.use_and_reproduction(index).first
780
+ when 'license'
781
+ doc['license_ssm'] << self.descMetadata.use_and_reproduction(index).first
782
+ end
783
+ end
784
+
785
+ doc['restrictions_on_access_ssm'] = self.descMetadata.restriction_on_access
786
+
787
+ doc['note_tsim'] = []
788
+ doc['note_resp_tsim'] = []
789
+ doc['note_date_tsim'] = []
790
+ doc['note_performers_tsim'] = []
791
+ doc['note_acquisition_tsim'] = []
792
+ doc['note_ownership_tsim'] = []
793
+ doc['note_citation_tsim'] = []
794
+ doc['note_reference_tsim'] = []
795
+
796
+ 0.upto self.descMetadata.note.length-1 do |index|
797
+ if self.descMetadata.note(index).type_at.first == 'statement of responsibility'
798
+ doc['note_resp_tsim'].append(self.descMetadata.mods(0).note(index).first)
799
+ elsif self.descMetadata.note(index).type_at.first == 'date'
800
+ doc['note_date_tsim'].append(self.descMetadata.mods(0).note(index).first)
801
+ elsif self.descMetadata.note(index).type_at.first == 'performers'
802
+ doc['note_performers_tsim'].append(self.descMetadata.mods(0).note(index).first)
803
+ elsif self.descMetadata.note(index).type_at.first == 'acquisition'
804
+ doc['note_acquisition_tsim'].append(self.descMetadata.mods(0).note(index).first)
805
+ elsif self.descMetadata.note(index).type_at.first == 'ownership'
806
+ doc['note_ownership_tsim'].append(self.descMetadata.mods(0).note(index).first)
807
+ elsif self.descMetadata.note(index).type_at.first == 'preferred citation'
808
+ doc['note_citation_tsim'].append(self.descMetadata.mods(0).note(index).first)
809
+ elsif self.descMetadata.note(index).type_at.first == 'citation/reference'
810
+ doc['note_reference_tsim'].append(self.descMetadata.mods(0).note(index).first)
811
+ else
812
+ doc['note_tsim'].append(self.descMetadata.mods(0).note(index).first)
813
+ end
814
+ end
815
+
816
+
817
+ 0.upto self.descMetadata.physical_description.length-1 do |physical_index|
818
+ 0.upto self.descMetadata.physical_description(physical_index).note.length-1 do |note_index|
819
+ if self.descMetadata.physical_description(physical_index).note(note_index).first != nil
820
+ doc['note_tsim'].append(self.descMetadata.physical_description(physical_index).note(note_index).first)
821
+ end
822
+ end
823
+ end
824
+
825
+ doc['title_info_alternative_tsim'] = []
826
+ doc['title_info_uniform_tsim'] = []
827
+ doc['title_info_primary_trans_tsim'] = []
828
+ doc['title_info_translated_tsim'] = []
829
+ self.descMetadata.mods(0).title.each_with_index do |title_value,index|
830
+ title_prefix = self.descMetadata.mods(0).title_info(index).nonSort[0] ? self.descMetadata.mods(0).title_info(index).nonSort[0] + ' ' : '' # shouldn't be adding space; see Trac ticket #101
831
+ if self.descMetadata.mods(0).title_info(index).usage[0] == 'primary'
832
+ if self.descMetadata.mods(0).title_info(index).type[0] == 'translated'
833
+ if self.descMetadata.mods(0).title_info(index).display_label[0] == 'primary_display'
834
+ doc['title_info_primary_tsi'] = title_prefix + title_value
835
+ doc['title_info_primary_ssort'] = title_value
836
+ else
837
+ doc['title_info_primary_trans_tsim'] << title_prefix + title_value
838
+ end
839
+ else
840
+ doc['title_info_primary_tsi'] = title_prefix + title_value
841
+ doc['title_info_primary_ssort'] = title_value
842
+ end
843
+ if self.descMetadata.mods(0).title_info(index).supplied[0] == 'yes'
844
+ doc['supplied_title_bs'] = 'true'
845
+ end
846
+ elsif self.descMetadata.mods(0).title_info(index).type[0] == 'alternative'
847
+ doc['title_info_alternative_tsim'] << title_prefix + title_value
848
+ if self.descMetadata.mods(0).title_info(index).supplied[0] == 'yes'
849
+ doc['supplied_alternative_title_bs'] = 'true'
850
+ end
851
+ doc['title_info_alternative_label_ssm'] = self.descMetadata.mods(0).title_info(index).display_label
852
+ elsif self.descMetadata.mods(0).title_info(index).type[0] == 'uniform'
853
+ doc['title_info_uniform_tsim'] << title_prefix + title_value
854
+ elsif self.descMetadata.mods(0).title_info(index).type[0] == 'translated'
855
+ doc['title_info_translated_tsim'] << title_prefix + title_value
856
+ end
857
+ end
858
+
859
+ doc['subtitle_tsim'] = self.descMetadata.title_info.subtitle
860
+
861
+ if self.collection
862
+ if self.collection.institutions
863
+ doc['institution_pid_si'] = self.collection.institutions.pid
864
+ end
865
+ end
866
+
867
+ if self.workflowMetadata
868
+ doc['workflow_state_ssi'] = self.workflowMetadata.item_status.state
869
+ doc['processing_state_ssi'] = self.workflowMetadata.item_status.processing
870
+ end
871
+
872
+ ActiveFedora::Base.find_in_batches('is_exemplary_image_of_ssim'=>"info:fedora/#{self.pid}") do |group|
873
+ group.each { |exemplary_solr|
874
+ doc['exemplary_image_ssi'] = exemplary_solr['id']
875
+ }
876
+ end
877
+
878
+ if self.workflowMetadata.marked_for_deletion.present?
879
+ doc['marked_for_deletion_bsi'] = self.workflowMetadata.marked_for_deletion.first
880
+ doc['marked_for_deletion_reason_ssi'] = self.workflowMetadata.marked_for_deletion.reason.first
881
+ end
882
+
883
+ if self.workflowMetadata.item_designations.present?
884
+ if self.workflowMetadata.item_designations(0).flagged_for_content.present?
885
+ doc['flagged_content_ssi'] = self.workflowMetadata.item_designations(0).flagged_for_content
886
+ end
887
+ end
888
+
889
+
890
+ #doc['all_text_timv'] = [self.descMetadata.abstract, main_title, self.rels_ext.model.class.to_s.gsub(/\A[\w]*::/,''),self.descMetadata.item_location(0).physical_location[0]]
891
+
892
+ doc
893
+ end
894
+
895
+ #Expects the following args:
896
+ #parent_pid => id of the parent object
897
+ #local_id => local ID of the object
898
+ #local_id_type => type of that local ID
899
+ #label => label of the object
900
+ #institution_pid => instituional access of this file
901
+ def self.mint(args)
902
+
903
+ #TODO: Duplication check here to prevent over-writes?
904
+
905
+ args[:namespace_id] ||= ARK_CONFIG_GLOBAL['namespace_commonwealth_pid']
906
+
907
+ response = Typhoeus::Request.post(ARK_CONFIG_GLOBAL['url'] + "/arks.json", :params => {:ark=>{:parent_pid=>args[:parent_pid], :namespace_ark => ARK_CONFIG_GLOBAL['namespace_commonwealth_ark'], :namespace_id=>args[:namespace_id], :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]}})
908
+ as_json = JSON.parse(response.body)
909
+
910
+ puts as_json['pid']
911
+
912
+ #For some reason, the below stopped working suddenly?
913
+ =begin
914
+ dup_check = ActiveFedora::Base.find(:pid=>as_json["pid"])
915
+ if dup_check.present?
916
+ return as_json["pid"]
917
+ end
918
+ =end
919
+
920
+ Bplmodels::ObjectBase.find_in_batches('id'=>as_json["pid"]) do |group|
921
+ group.each { |solr_result|
922
+ return as_json["pid"]
923
+ }
924
+ end
925
+
926
+ object = self.new(:pid=>as_json["pid"])
927
+
928
+ object.add_relationship(:is_member_of_collection, "info:fedora/" + args[:parent_pid])
929
+ object.add_oai_relationships
930
+
931
+ object.label = args[:label] if args[:label].present?
932
+
933
+ object.workflowMetadata.item_ark_info.ark_id = args[:local_id]
934
+ object.workflowMetadata.item_ark_info.ark_type = args[:local_id_type]
935
+ object.workflowMetadata.item_ark_info.ark_parent_pid = args[:parent_pid]
936
+
937
+ object.read_groups = ["public"]
938
+ object.edit_groups = ["superuser", "admin[#{args[:institution_pid]}]"] if args[:institution_pid]
939
+
940
+ return object
941
+ end
942
+
943
+ def generate_thumbnail_url(config_hash=nil)
944
+ if config_hash.present?
945
+ return config_hash['url'] + '/ark:/' + config_hash["namespace_commonwealth_ark"].to_s + "/" + self.pid.split(':').last.to_s + "/thumbnail"
946
+ end
947
+
948
+ return ARK_CONFIG_GLOBAL['url'] + '/ark:/' + ARK_CONFIG_GLOBAL["namespace_commonwealth_ark"].to_s + "/" + self.pid.split(':').last.to_s + "/thumbnail"
949
+ end
950
+
951
+ def generate_uri
952
+ return ARK_CONFIG_GLOBAL['url'] + '/ark:/' + ARK_CONFIG_GLOBAL["namespace_commonwealth_ark"].to_s + "/" + self.pid.split(':').last.to_s
953
+ end
954
+
955
+ # Expects a hash of the following keys
956
+ # :file_path -> The path to the file
957
+ # :datastream -> The datastream for the file
958
+ # :file_name -> The name of the file
959
+ def insert_new_file(files_hash, file_ingest_source, institution_pid)
960
+ puts files_hash.to_s
961
+
962
+ raise 'Missing insert_new_file params' if files_hash.first[:file_path].blank? || files_hash.first[:datastream].blank? || files_hash.first[:file_name].blank?
963
+
964
+ production_master = files_hash.select{ |hash| hash[:datastream] == 'productionMaster' }.first
965
+
966
+ if production_master[:file_name].include?('.tif')
967
+ self.descMetadata.insert_media_type('image/tiff')
968
+ self.descMetadata.insert_media_type('image/jpeg')
969
+ self.descMetadata.insert_media_type('image/jp2')
970
+ self.insert_new_image_file(files_hash, institution_pid)
971
+ elsif production_master[:file_name].include?('.mp3')
972
+ self.descMetadata.insert_media_type('audio/mpeg')
973
+ self.insert_new_audio_file(files_hash, institution_pid)
974
+ elsif production_master[:file_name].include?('.pdf')
975
+ self.descMetadata.insert_media_type('application/pdf')
976
+ self.insert_new_document_file(files_hash, institution_pid)
977
+ else
978
+ self.descMetadata.insert_media_type('image/jpeg')
979
+ self.descMetadata.insert_media_type('image/jp2')
980
+ self.insert_new_image_file(files_hash, institution_pid)
981
+ end
982
+
983
+ self.workflowMetadata.item_source.ingest_origin = file_ingest_source
984
+ files_hash.each do |file|
985
+ self.workflowMetadata.insert_file_source(file[:file_path],file[:file_name],file[:datastream])
986
+ end
987
+ end
988
+
989
+ def insert_new_image_file(files_hash, institution_pid)
990
+ #raise 'insert new image called with no files or more than one!' if file.blank? || file.is_a?(Array)
991
+
992
+ puts 'processing image of: ' + self.pid.to_s + ' with file_hash: ' + files_hash.to_s
993
+
994
+ production_master = files_hash.select{ |hash| hash[:datastream] == 'productionMaster' }.first
995
+
996
+ #uri_file_part = file
997
+ #Fix common url errors
998
+ #uri_file_part = URI::escape(uri_file_part) if uri_file_part.match(/^http/)
999
+
1000
+ image_file = Bplmodels::ImageFile.mint(:parent_pid=>self.pid, :local_id=>production_master[:file_name], :local_id_type=>'File Name', :label=>production_master[:file_name], :institution_pid=>institution_pid)
1001
+
1002
+ if image_file.is_a?(String)
1003
+ #Bplmodels::ImageFile.find(last_image_file).delete
1004
+ #last_image_file = Bplmodels::ImageFile.mint(:parent_pid=>self.pid, :local_id=>final_file_name, :local_id_type=>'File Name', :label=>final_file_name, :institution_pid=>institution_pid)
1005
+ return true
1006
+ end
1007
+
1008
+ files_hash.each_with_index do |file, file_index|
1009
+ datastream = file[:datastream]
1010
+
1011
+
1012
+ image_file.send(datastream).content = ::File.open(file[:file_path])
1013
+
1014
+ if file[:file_name].split('.').last.downcase == 'tif'
1015
+ image_file.send(datastream).mimeType = 'image/tiff'
1016
+ elsif file[:file_name].split('.').last.downcase == 'jpg'
1017
+ image_file.send(datastream).mimeType = 'image/jpeg'
1018
+ else
1019
+ image_file.send(datastream).mimeType = 'image/jpeg'
1020
+ end
1021
+
1022
+ image_file.send(datastream).dsLabel = file[:file_name].gsub('.tif', '').gsub('.jpg', '').gsub('.jpeg', '')
1023
+
1024
+ #FIXME!!!
1025
+ image_file.workflowMetadata.insert_file_source(file[:file_path],file[:file_name],datastream)
1026
+ image_file.workflowMetadata.item_status.state = "published"
1027
+ image_file.workflowMetadata.item_status.state_comment = "Added via the ingest image object base method on " + Time.new.year.to_s + "/" + Time.new.month.to_s + "/" + Time.new.day.to_s
1028
+
1029
+
1030
+ end
1031
+
1032
+
1033
+ other_images_exist = false
1034
+ Bplmodels::ImageFile.find_in_batches('is_image_of_ssim'=>"info:fedora/#{self.pid}", 'is_preceding_image_of_ssim'=>'') do |group|
1035
+ group.each { |image_id|
1036
+ other_images_exist = true
1037
+ preceding_image = Bplmodels::ImageFile.find(image_id['id'])
1038
+ preceding_image.add_relationship(:is_preceding_image_of, "info:fedora/#{image_file.pid}", true)
1039
+ preceding_image.save
1040
+ image_file.add_relationship(:is_following_image_of, "info:fedora/#{image_id['id']}", true)
1041
+ }
1042
+ end
1043
+
1044
+ image_file.add_relationship(:is_image_of, "info:fedora/" + self.pid)
1045
+ image_file.add_relationship(:is_file_of, "info:fedora/" + self.pid)
1046
+ image_file.add_relationship(:is_exemplary_image_of, "info:fedora/" + self.pid) unless other_images_exist
1047
+
1048
+ image_file.save
1049
+
1050
+ image_file
1051
+ end
1052
+
1053
+ #FIXME: NOT UPDATED!
1054
+ def insert_new_audio_file(audio_file, institution_pid)
1055
+ raise 'audio file missing!' if audio_file.blank?
1056
+
1057
+ uri_file_part = audio_file
1058
+ #Fix common url errors
1059
+ if uri_file_part.match(/^http/)
1060
+ #uri_file_part = uri_file_part.gsub(' ', '%20')
1061
+ uri_file_part = URI::escape(uri_file_part)
1062
+ end
1063
+
1064
+ final_audio_name = audio_file.gsub('\\', '/').split('/').last
1065
+ current_audio_file = Bplmodels::AudioFile.mint(:parent_pid=>self.pid, :local_id=>final_audio_name, :local_id_type=>'File Name', :label=>final_audio_name, :institution_pid=>institution_pid)
1066
+ if current_audio_file.is_a?(String)
1067
+ Bplmodels::AudioFile.find(current_audio_file).delete
1068
+ current_audio_file = Bplmodels::AudioFile.mint(:parent_pid=>self.pid, :local_id=>final_audio_name, :local_id_type=>'File Name', :label=>final_audio_name, :institution_pid=>institution_pid)
1069
+ end
1070
+
1071
+
1072
+ current_audio_file.productionMaster.content = open(uri_file_part)
1073
+ if audio_file.split('.').last.downcase == 'mp3'
1074
+ current_audio_file.productionMaster.mimeType = 'audio/mpeg'
1075
+ else
1076
+ current_audio_file.productionMaster.mimeType = 'audio/mpeg'
1077
+ end
1078
+
1079
+
1080
+ other_audio_exist = false
1081
+ Bplmodels::AudioFile.find_in_batches('is_audio_of_ssim'=>"info:fedora/#{self.pid}", 'is_preceding_audio_of_ssim'=>'') do |group|
1082
+ group.each { |audio|
1083
+ other_audio_exist = true
1084
+ preceding_audio = Bplmodels::AudioFile.find(audio['id'])
1085
+ preceding_audio.add_relationship(:is_preceding_audio_of, "info:fedora/#{current_audio_file.pid}", true)
1086
+ preceding_audio.save
1087
+ current_audio_file.add_relationship(:is_following_audio_of, "info:fedora/#{audio['id']}", true)
1088
+ }
1089
+ end
1090
+
1091
+ current_audio_file.add_relationship(:is_audio_of, "info:fedora/" + self.pid)
1092
+ current_audio_file.add_relationship(:is_file_of, "info:fedora/" + self.pid)
1093
+
1094
+ current_audio_file.workflowMetadata.insert_file_path(audio_file)
1095
+ current_audio_file.workflowMetadata.insert_file_name(final_audio_name)
1096
+ current_audio_file.workflowMetadata.item_status.state = "published"
1097
+ current_audio_file.workflowMetadata.item_status.state_comment = "Added via the ingest audio object base method on " + Time.new.year.to_s + "/" + Time.new.month.to_s + "/" + Time.new.day.to_s
1098
+
1099
+ current_audio_file.save
1100
+
1101
+ current_audio_file
1102
+ end
1103
+
1104
+ #FIXME: NOT UPDATED!
1105
+ #FIXME: Cases of images and PDF?
1106
+ def insert_new_document_file(document_file, institution_pid)
1107
+ raise 'document file missing!' if document_file.blank?
1108
+
1109
+ puts 'processing document of: ' + self.pid.to_s + ' with file: ' + document_file
1110
+
1111
+ uri_file_part = document_file
1112
+
1113
+ #Fix common url errors
1114
+ if uri_file_part.match(/^http/)
1115
+ #uri_file_part = uri_file_part.gsub(' ', '%20')
1116
+ uri_file_part = URI::escape(uri_file_part)
1117
+ end
1118
+
1119
+ final_document_name = document_file.gsub('\\', '/').split('/').last
1120
+ current_document_file = Bplmodels::DocumentFile.mint(:parent_pid=>self.pid, :local_id=>final_document_name, :local_id_type=>'File Name', :label=>final_document_name, :institution_pid=>institution_pid)
1121
+ if current_document_file.is_a?(String)
1122
+ Bplmodels::DocumentFile.find(current_document_file).delete
1123
+ current_document_file = Bplmodels::DocumentFile.mint(:parent_pid=>self.pid, :local_id=>final_document_name, :local_id_type=>'File Name', :label=>final_document_name, :institution_pid=>institution_pid)
1124
+ #return true
1125
+ end
1126
+
1127
+ current_document_file.productionMaster.content = open(uri_file_part)
1128
+ if document_file.split('.').last.downcase == 'pdf'
1129
+ current_document_file.productionMaster.mimeType = 'application/pdf'
1130
+ else
1131
+ current_document_file.productionMaster.mimeType = 'application/pdf'
1132
+ end
1133
+
1134
+ current_page = 0
1135
+ total_colors = 0
1136
+ until total_colors > 1 do
1137
+ img = Magick::Image.read(uri_file_part + '[' + current_page.to_s + ']'){
1138
+ self.quality = 100
1139
+ self.density = 200
1140
+ }.first
1141
+ total_colors = img.total_colors
1142
+ current_page = current_page + 1
1143
+ end
1144
+
1145
+ #This is horrible. But if you don't do this, some PDF files won't come out right at all.
1146
+ #Multiple attempts have failed to fix this but perhaps the bug will be patched in ImageMagick.
1147
+ #To duplicate, one can use the PDF files at: http://libspace.uml.edu/omeka/files/original/7ecb4dc9579b11e2b53ccc2040e58d36.pdf
1148
+ img = Magick::Image.from_blob( img.to_blob { self.format = "jpg" } ).first
1149
+
1150
+ thumb = img.resize_to_fit(300,300)
1151
+
1152
+ current_document_file.thumbnail300.content = thumb.to_blob { self.format = "jpg" }
1153
+ current_document_file.thumbnail300.mimeType = 'image/jpeg'
1154
+
1155
+ Bplmodels::DocumentFile.find_in_batches('is_document_of_ssim'=>"info:fedora/#{self.pid}", 'is_preceding_document_of_ssim'=>'') do |group|
1156
+ group.each { |document_solr|
1157
+ other_document_exist = true
1158
+ preceding_document = Bplmodels::DocumentFile.find(document_solr['id'])
1159
+ preceding_document.add_relationship(:is_preceding_document_of, "info:fedora/#{current_document_file.pid}", true)
1160
+ preceding_document.save
1161
+ current_document_file.add_relationship(:is_following_document_of, "info:fedora/#{document_solr['id']}", true)
1162
+ }
1163
+ end
1164
+
1165
+ #TODO: Fix this in the image file object?
1166
+ other_exemplary_exist = false
1167
+ Bplmodels::File.find_in_batches('is_exemplary_image_of_ssim'=>"info:fedora/#{self.pid}") do |group|
1168
+ group.each { |exemplary_solr|
1169
+ other_exemplary_exist = true
1170
+ }
1171
+ end
1172
+
1173
+ current_document_file.add_relationship(:is_document_of, "info:fedora/" + self.pid)
1174
+ current_document_file.add_relationship(:is_file_of, "info:fedora/" + self.pid)
1175
+
1176
+ current_document_file.add_relationship(:is_exemplary_image_of, "info:fedora/" + self.pid) unless other_exemplary_exist
1177
+
1178
+ current_document_file.workflowMetadata.insert_file_path(document_file)
1179
+ current_document_file.workflowMetadata.insert_file_name(final_document_name)
1180
+ current_document_file.workflowMetadata.item_status.state = "published"
1181
+ current_document_file.workflowMetadata.item_status.state_comment = "Added via the ingest document object base method on " + Time.new.year.to_s + "/" + Time.new.month.to_s + "/" + Time.new.day.to_s
1182
+
1183
+ current_document_file.save
1184
+
1185
+ img.destroy!
1186
+ current_document_file
1187
+ end
1188
+
1189
+ def deleteAllFiles
1190
+ Bplmodels::ImageFile.find_in_batches('is_image_of_ssim'=>"info:fedora/#{self.pid}") do |group|
1191
+ group.each { |solr_object|
1192
+ object = ActiveFedora::Base.find(solr_object['id']).adapt_to_cmodel
1193
+ object.delete
1194
+ }
1195
+ end
1196
+
1197
+ Bplmodels::AudioFile.find_in_batches('is_audio_of_ssim'=>"info:fedora/#{self.pid}") do |group|
1198
+ group.each { |solr_object|
1199
+ object = ActiveFedora::Base.find(solr_object['id']).adapt_to_cmodel
1200
+ object.delete
1201
+ }
1202
+ end
1203
+
1204
+ Bplmodels::DocumentFile.find_in_batches('is_document_of_ssim'=>"info:fedora/#{self.pid}") do |group|
1205
+ group.each { |solr_object|
1206
+ object = ActiveFedora::Base.find(solr_object['id']).adapt_to_cmodel
1207
+ object.delete
1208
+ }
1209
+ end
1210
+ end
1211
+
1212
+ def derivative_service(is_new)
1213
+ response = Typhoeus::Request.post(DERIVATIVE_CONFIG_GLOBAL['url'] + "/processor/byobject.json", :params => {:pid=>self.pid, :new=>is_new, :environment=>Bplmodels.environment})
1214
+ puts response.body.to_s
1215
+ as_json = JSON.parse(response.body)
1216
+
1217
+ if as_json['result'] == "false"
1218
+ pid = self.object.pid
1219
+ self.deleteAllFiles
1220
+ self.delete
1221
+ raise "Error Generating Derivatives For Object: " + pid
1222
+ end
1223
+
1224
+ return true
1225
+ end
1226
+
1227
+ def oai_thumbnail_service(is_new, urls, system_type, thumbnail_url=nil)
1228
+ response = Typhoeus::Request.post(DERIVATIVE_CONFIG_GLOBAL['url'] + "/processor/oaithumbnail.json", :params => {:pid=>self.pid, :new=>is_new, :environment=>Bplmodels.environment, :image_urls=>urls, :system_type=>system_type, :thumbnail_url=>thumbnail_url})
1229
+ as_json = JSON.parse(response.body)
1230
+
1231
+ if as_json['result'] == "false"
1232
+ pid = self.object.pid
1233
+ self.delete
1234
+ raise "Error Generating OAI Thumbnail For Object: " + pid
1235
+ end
1236
+
1237
+ return true
1238
+ end
1239
+
1240
+ end
1241
+ end