bplmodels 0.0.91

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45fa0e10e32adebfefb0eb641cf428a2e6f91fa8
4
+ data.tar.gz: 14f75699119c3990c4f8e18ceed8253deca191a7
5
+ SHA512:
6
+ metadata.gz: 4e63652810c8d068c3eb2f91bb7cefcfe42ca29beae7f04f00cdd3864b6c076a7b6e7e963209675578d0828035d5e1832c0dca8154672c86ff706f62a66636a8
7
+ data.tar.gz: c0b1657ed6b96678b9dfb3237c28b561b5ae66da2ef676f55df6b5e12164c27ffc1d9279773482780eb022f05b83c35931318bd1baa9695b925ae0e531fa51ad
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Bplmodels'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Bplmodels
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bplmodels
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Bplmodels
2
+ class AudioFile < Bplmodels::File
3
+
4
+ has_many :next_audio, :class_name => "Bplmodels::AudioFile", :property=> :is_preceding_audio_of
5
+
6
+ has_many :prev_audio, :class_name => "Bplmodels::AudioFile", :property=> :is_following_audio_of
7
+
8
+ has_many :transcription, :class_name => "Bplmodels::File", :property=> :is_transcription_of
9
+
10
+ def fedora_name
11
+ 'audio_file'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module Bplmodels
2
+ class Book < Bplmodels::ComplexObjectBase
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
+ 'book'
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
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Bplmodels
2
+ class Card < 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
+ 'card'
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
+ end
35
+ end
@@ -0,0 +1,92 @@
1
+ module Bplmodels
2
+ module Characterization
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ has_metadata "characterization", type: Bplmodels::FitsDatastream
6
+ has_attributes :mime_type, datastream: :characterization, multiple: false
7
+ has_attributes :format_label, :file_size, :last_modified,
8
+ :filename, :original_checksum, :rights_basis,
9
+ :copyright_basis, :copyright_note,
10
+ :well_formed, :valid, :status_message,
11
+ :file_title, :file_author, :page_count,
12
+ :file_language, :word_count, :character_count,
13
+ :paragraph_count, :line_count, :table_count,
14
+ :graphics_count, :byte_order, :compression,
15
+ :color_space, :profile_name,
16
+ :profile_version, :orientation, :color_map,
17
+ :image_producer, :capture_device,
18
+ :scanning_software, :exif_version,
19
+ :gps_timestamp, :latitude, :longitude,
20
+ :character_set, :markup_basis,
21
+ :markup_language, :bit_depth,
22
+ :channels, :data_format, :offset, :frame_rate, datastream: :characterization, multiple: true
23
+
24
+ end
25
+
26
+ def fits_config_values
27
+ return {:file_title => :title, :file_author => :creator }
28
+ end
29
+
30
+ def width
31
+ characterization.width.blank? ? characterization.video_width : characterization.width
32
+ end
33
+
34
+ def height
35
+ characterization.height.blank? ? characterization.video_height : characterization.height
36
+ end
37
+
38
+ def duration
39
+ characterization.duration.blank? ? characterization.video_duration : characterization.duration
40
+ end
41
+
42
+ def sample_rate
43
+ characterization.sample_rate.blank? ? characterization.video_sample_rate : characterization.sample_rate
44
+ end
45
+
46
+ ## Extract the metadata from the content datastream and record it in the characterization datastream
47
+ def characterize
48
+ self.characterization.ng_xml = self.productionMaster.extract_metadata
49
+ self.append_metadata
50
+ self.filename = self.label
51
+ save
52
+ end
53
+
54
+ # Populate descMetadata with fields from FITS (e.g. Author from pdfs)
55
+ def append_metadata
56
+ terms = self.characterization_terms
57
+ #Sufia.config.fits_to_desc_mapping.each_pair do |k, v|
58
+ fits_config_values.each_pair do |k, v|
59
+ if terms.has_key?(k)
60
+ # coerce to array to remove a conditional
61
+ terms[k] = [terms[k]] unless terms[k].is_a? Array
62
+ terms[k].each do |term_value|
63
+ proxy_term = self.send(v)
64
+ if proxy_term.kind_of?(Array)
65
+ proxy_term << term_value unless proxy_term.include?(term_value)
66
+ else
67
+ # these are single-valued terms which cannot be appended to
68
+ self.send("#{v}=", term_value)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def characterization_terms
76
+ h = {}
77
+ self.characterization.class.terminology.terms.each_pair do |k, v|
78
+ next unless v.respond_to? :proxied_term
79
+ term = v.proxied_term
80
+ begin
81
+ value = self.send(term.name)
82
+ h[term.name] = value unless value.empty?
83
+ rescue NoMethodError
84
+ next
85
+ end
86
+ end
87
+ h
88
+ end
89
+
90
+
91
+ end
92
+ end
@@ -0,0 +1,118 @@
1
+ module Bplmodels
2
+ class Collection < Bplmodels::RelationBase
3
+
4
+ #has_relationship "similar_audio", :has_part, :type=>AudioRecord
5
+ has_many :objects, :class_name=> "Bplmodels::ObjectBase", :property=> :is_member_of_collection
6
+
7
+ has_many :objects_casted, :class_name=> "Bplmodels::ObjectBase", :property=> :is_member_of_collection
8
+
9
+ belongs_to :institutions, :class_name => 'Bplmodels::Institution', :property => :is_member_of
10
+
11
+ has_many :exemplary_image, :class_name => "ActiveFedora::Base", :property=> :is_exemplary_image_of
12
+
13
+ # Uses the Hydra modsCollection profile for collection list
14
+ #has_metadata :name => "members", :type => Hydra::ModsCollectionMembers
15
+
16
+ #A collection can have another collection as a member, or an image
17
+ def insert_member(fedora_object)
18
+ if (fedora_object.instance_of?(Bplmodels::ObjectBase))
19
+
20
+ #add to the members ds
21
+ #members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name
22
+
23
+ #add to the rels-ext ds
24
+ #fedora_object.collections << self
25
+ #self.objects << fedora_object
26
+ #self.add_relationship(:has_image, "info:fedora/#{fedora_object.pid}")
27
+ elsif (fedora_object.instance_of?(Bplmodels::Institution))
28
+ #add to the members ds
29
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
30
+
31
+ #add to the rels-ext ds
32
+ fedora_object.collections << self
33
+ self.institutions << fedora_object
34
+
35
+ end
36
+
37
+ fedora_object.save!
38
+ self.save!
39
+
40
+ end
41
+
42
+ def add_oai_relationships
43
+ #self.add_relationship(:oai_item_id, "oai:digitalcommonwealth.org:" + self.pid, true)
44
+ self.add_relationship(:oai_set_spec, self.pid, true)
45
+ self.add_relationship(:oai_set_name, self.label.gsub(' & ', ' &amp; '), true)
46
+ end
47
+
48
+ def fedora_name
49
+ 'collection'
50
+ end
51
+
52
+ def to_solr(doc = {} )
53
+ doc = super(doc)
54
+
55
+ # description
56
+ doc['abstract_tsim'] = self.descMetadata.abstract
57
+
58
+ # institution
59
+ if self.institutions
60
+ collex_location = self.institutions.label.to_s
61
+ doc['physical_location_ssim'] = collex_location
62
+ doc['physical_location_tsim'] = collex_location
63
+ doc['institution_pid_si'] = self.institutions.pid
64
+ # TODO: need to remove the 3 above and refactor apps as necessary
65
+ # collections (AKA sets) have institutions, not locations
66
+ doc['institution_name_ssim'] = collex_location
67
+ doc['institution_name_tsim'] = collex_location
68
+ doc['institution_pid_ssi'] = self.institutions.pid
69
+ end
70
+
71
+ if self.exemplary_image.first != nil
72
+ doc['exemplary_image_ssi'] = self.exemplary_image.first.pid
73
+ end
74
+
75
+ doc
76
+
77
+ end
78
+
79
+ #Expects the following args:
80
+ #parent_pid => id of the parent object
81
+ #local_id => local ID of the object
82
+ #local_id_type => type of that local ID
83
+ #label => label of the collection
84
+ def self.mint(args)
85
+
86
+ #TODO: Duplication check here to prevent over-writes?
87
+
88
+ args[:namespace_id] ||= ARK_CONFIG_GLOBAL['namespace_commonwealth_pid']
89
+
90
+ 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]}})
91
+ as_json = JSON.parse(response.body)
92
+
93
+ Bplmodels::Collection.find_in_batches('id'=>as_json["pid"]) do |group|
94
+ group.each { |solr_result|
95
+ return as_json["pid"]
96
+ }
97
+ end
98
+
99
+ object = self.new(:pid=>as_json["pid"])
100
+
101
+ title = Bplmodels::DatastreamInputFuncs.getProperTitle(args[:label])
102
+ object.label = args[:label]
103
+ object.descMetadata.insert_title(title[0], title[1])
104
+
105
+ object.add_relationship(:is_member_of, "info:fedora/" + args[:parent_pid])
106
+ uri = ARK_CONFIG_GLOBAL['url'] + '/ark:/'+ as_json["namespace_ark"] + '/' + as_json["noid"]
107
+ object.descMetadata.insert_access_links(nil, uri)
108
+
109
+ object.add_oai_relationships
110
+
111
+ object.read_groups = ["public"]
112
+ object.edit_groups = ["superuser", "admin[#{args[:parent_pid]}]"]
113
+
114
+ return object
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,24 @@
1
+ module Bplmodels
2
+ class ComplexObjectBase < Bplmodels::ObjectBase
3
+
4
+ ## Produce a unique filename that doesn't already exist.
5
+ def temp_filename(basename, tmpdir='/tmp')
6
+ n = 0
7
+ begin
8
+ tmpname = File.join(tmpdir, sprintf('%s%d.%d', basename, $$, n))
9
+ lock = tmpname + '.lock'
10
+ n += 1
11
+ end while File.exist?(tmpname)
12
+ tmpname
13
+ end
14
+
15
+ def to_solr(doc = {} )
16
+ doc = super(doc)
17
+ doc
18
+
19
+ end
20
+
21
+
22
+
23
+ end
24
+ end