eem_model 0.0.2.2

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Stanford University Library
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
@@ -0,0 +1,15 @@
1
+ = eem_model
2
+
3
+ >= 0.0.2 Requires active-fedora >= 1.1.13
4
+ 0.0.1 Requires active-fedora 1.0.7
5
+
6
+ = Releases
7
+
8
+ 0.0.2.2 Refactored gem creation. No impact to users of the gem.
9
+ 0.0.2.1 Added DC to Eem declaration
10
+ 0.0.2 Require active-fedora 1.1.13
11
+ 0.0.1 Requires active-fedora 0.0.7
12
+
13
+ == Copyright
14
+
15
+ Copyright (c) 2011 Stanford University Library. See LICENSE for details.
@@ -0,0 +1,35 @@
1
+
2
+ module EemModel
3
+
4
+ class Eem < ActiveFedora::Base
5
+
6
+ has_relationship "parts", :is_part_of, :inbound => true #content files
7
+
8
+ has_metadata :name => 'eemsProperties', :type => ActiveFedora::MetadataDatastream do |m|
9
+ m.label = "eemsProperties"
10
+
11
+ m.field "copyrightStatusDate", :string, :multiple => false #mutiple doesn't do anything
12
+ m.field "copyrightStatus", :string
13
+ m.field "creatorOrg", :string
14
+ m.field "creatorPerson", :string
15
+ m.field "language", :string
16
+ m.field "note", :string
17
+ m.field "paymentType", :string
18
+ m.field "paymentFund", :string
19
+ m.field "selectorName", :string
20
+ m.field "selectorSunetid", :string
21
+ m.field "title", :string
22
+ m.field "sourceUrl", :string
23
+ m.field "requestDatetime", :string
24
+ m.field "status", :string
25
+ m.field "statusDatetime", :string
26
+ m.field "downloadDate", :string
27
+ end
28
+
29
+ has_metadata :name => "DC", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,307 @@
1
+ require 'nokogiri'
2
+
3
+ module EemModel
4
+ module EemAccession
5
+
6
+ # create a datastream in the repository for the given eem object
7
+ def populate_datastream(ds_name)
8
+ label = case ds_name
9
+ when "identityMetadata" then 'Identity Metadata'
10
+ when "contentMetadata" then 'Content Metadata'
11
+ when "rightsMetadata" then 'Rights Metadata'
12
+ else ''
13
+ end
14
+ metadata = case ds_name
15
+ when "identityMetadata" then generate_identity_metadata_xml
16
+ when "contentMetadata" then generate_content_metadata_xml
17
+ when "rightsMetadata" then generate_rights_metadata_xml
18
+ else nil
19
+ end
20
+ unless( metadata.nil? )
21
+ populate_datastream_in_repository(ds_name,label,metadata)
22
+ end
23
+ end
24
+
25
+ # create a datastream for the given eem object with the given datastream name, label, and metadata blob
26
+ def populate_datastream_in_repository(ds_name,label,metadata)
27
+ attrs = { :pid => pid, :dsID => ds_name, :mimeType => 'application/xml', :dsLabel => label, :blob => metadata }
28
+ datastream = ActiveFedora::Datastream.new(attrs)
29
+ datastream.control_group = 'M'
30
+ datastream.versionable = false
31
+ datastream.save
32
+ end
33
+
34
+ # create the identity metadata xml datastream
35
+ #
36
+ # <identityMetadata>
37
+ # <objectId>druid:rt923jk342</objectId> <-- Fedora PID
38
+ # <objectType>item</objectType> <-- Supplied fixed value
39
+ # <objectLabel>value from Fedora header</objectLabel> <-- from Fedora header
40
+ # <objectCreator>DOR</objectCreator> <-- Supplied fixed value
41
+ # <citationTitle>title, from DC:title</citationTitle> <-- updated after Symphony record is created
42
+ # <citationCreator>creator, from DC:creator</citationCreator> <-- updated after Symphony record is created
43
+ # <otherId name="dissertationid">0000000012</otherId> <-- per Registrar, from EEM propertied <dissertationid>
44
+ # <otherId name="catkey">129483625</otherId> <-- added after Symphony record is created. Can be found in DC
45
+ # <otherId name="uuid">7f3da130-7b02-11de-8a39-0800200c9a66</otherId> <-- DOR assigned (omit if not present)
46
+ # <agreementId>druid:ct692vv3660</agreementId> <-- fixed pre-assigned value, use the value shown here for EEMs
47
+ # <tag>EEM : Dissertation | Thesis</tag> <-- set of tags *
48
+ # </identityMetadata>
49
+ #
50
+ # == Options
51
+ # - <b>:add_label</b> If set to <i>true</i>, will add objectLabel to the xml, based on the Fedora object label. Default is <i>false</i>
52
+ def generate_initial_identity_metadata_xml(options={:add_label => false})
53
+ builder = Nokogiri::XML::Builder.new do |xml|
54
+ dc_ds = datastreams['DC']
55
+ props_ds = datastreams['eemsProperties']
56
+ xml.identityMetadata {
57
+ xml.objectId {
58
+ xml.text(pid)
59
+ }
60
+ xml.objectType {
61
+ xml.text("item")
62
+ }
63
+ if(options[:add_label])
64
+ xml.objectLabel{
65
+ xml.text(self.label)
66
+ }
67
+ end
68
+ xml.objectAdminClass {
69
+ xml.text("EEMs")
70
+ }
71
+ xml.agreementId {
72
+ xml.text("druid:fn200hb6598")
73
+ }
74
+ xml.tag {
75
+ xml.text("EEM : 1.0" )
76
+ }
77
+ }
78
+ end
79
+ builder.to_xml
80
+ end
81
+
82
+ def update_identity_metadata_object_label
83
+ id_ds = datastreams['identityMetadata']
84
+ id_xml = id_ds.content
85
+ if(!id_xml.nil? && !id_xml.empty?)
86
+ id_doc = Nokogiri::XML(id_xml)
87
+ object_label = id_doc.at_xpath('//objectLabel')
88
+ # create a new one if it doesn't exist
89
+ if(object_label.nil?)
90
+ object_label = Nokogiri::XML::Node.new('objectLabel', id_doc)
91
+ object_label.content = self.label
92
+ object_type = id_doc.at_xpath('//objectType')
93
+ if(object_type)
94
+ object_type.add_next_sibling(object_label)
95
+ else
96
+ id_doc.root << object_label
97
+ end
98
+ # else replace the old label with the new label
99
+ elsif(object_label.content != self.label)
100
+ object_label.content = self.label
101
+ end
102
+ id_ds.content = id_doc.to_xml
103
+
104
+ # Create identityXml datastream since it doesn't exist
105
+ else
106
+ id_ds.content = generate_initial_identity_metadata_xml(:add_label => true)
107
+ end
108
+
109
+ id_ds.save
110
+
111
+ end
112
+
113
+ # create the content metadata xml datastream
114
+ #
115
+ # <contentMetadata type="eem" objectId="druid:rt923jk342">
116
+ # <resource id="main" type="main-original" data="content">
117
+ # <attr name="label">Body of dissertation (as submitted)</attr>
118
+ # <file id="mydissertation.pdf" mimetype="application/pdf" size="758621" shelve="yes" deliver="no" preserve="yes" />
119
+ # </resource>
120
+ # <resource id="main" type="main-augmented" data="content" objectId="druid:ck234ku2334">
121
+ # <attr name="label">Body of dissertation</attr>
122
+ # <file id="mydissertation-augmented.pdf" mimetype="application/pdf" size="751418" shelve="yes" deliver="yes" preserve="yes">
123
+ # <location type="url">https://stacks.stanford.edu/file/druid:rt923jk342/mydissertation-augmented.pdf</location>
124
+ # </file>
125
+ # </resource>
126
+ # <resource id="supplement" type="supplement" data="content" sequence="1" objectId="druid:pt747ce6889">
127
+ # <attr name="label">Full experimental data</attr>
128
+ # <file id="datafile.xls" mimetype="application/ms-excel" size="83418" shelve="yes" deliver="yes" preserve="yes">
129
+ # <location type="url">https://stacks.stanford.edu/file/druid:rt923jk342/datafile.xls</location>
130
+ # </file>
131
+ # </resource>
132
+ # <resource id="permissions" type="permissions" data="content" objectId="druid:wb711pm9935">
133
+ # <attr name="label">Permission from the artist</attr>
134
+ # <file id="xyz-permission.txt" mimetype="application/text" size="341" shelve="yes" deliver="no" preserve="yes" />
135
+ # </resource>
136
+ # </contentMetadata>
137
+ #
138
+ def generate_content_metadata_xml
139
+ builder = Nokogiri::XML::Builder.new do |xml|
140
+ xml.contentMetadata(:type => "eem", :objectId => pid) {
141
+ # main pdf
142
+ props_ds = main_pdf.datastreams['properties']
143
+ main_pdf_file_name = props_ds.file_name_values.first
144
+ main_pdf_file_size = props_ds.size_values.first
145
+ xml.resource(:id => "main", :type => "main-original", :data => "content") {
146
+ xml.attr(:name => "label") {
147
+ xml.text("Body of dissertation (as submitted)")
148
+ }
149
+ xml.file(:id => main_pdf_file_name, :mimetype => "application/pdf", :size => main_pdf_file_size, :shelve => "yes", :deliver => "no", :preserve => "yes")
150
+ }
151
+ # augmented pdf
152
+ props_ds = main_pdf.datastreams['properties']
153
+ main_pdf_file_name = props_ds.file_name_values.first
154
+ main_pdf_file_size = props_ds.size_values.first
155
+ augmented_pdf_file_name = main_pdf_file_name.gsub(/\.pdf/,'-augmented.pdf')
156
+ augmented_pdf_file_size = File.size?(File.join(WORKSPACE_DIR, pid, augmented_pdf_file_name))
157
+ xml.resource(:id => "main", :type => "main-augmented", :data => "content", :objectId => main_pdf.pid) {
158
+ xml.attr(:name => "label") {
159
+ xml.text("Body of dissertation")
160
+ }
161
+ xml.file(:id => augmented_pdf_file_name, :mimetype => "application/pdf", :size => augmented_pdf_file_size, :shelve => "yes", :deliver => "yes", :preserve => "yes") {
162
+ xml.location(:type => "url") {
163
+ xml.text("https://stacks.stanford.edu/file/#{pid}/#{augmented_pdf_file_name}")
164
+ }
165
+ }
166
+ }
167
+ # supplemental files
168
+ supplemental_files.each_with_index do |supplemental_file, sequence|
169
+ props_ds = supplemental_file.datastreams['properties']
170
+ supplemental_file_name = props_ds.file_name_values.first
171
+ supplemental_file_mimetype = MIME::Types.type_for(supplemental_file_name).first.content_type
172
+ supplemental_file_label = props_ds.label_values.first
173
+ supplemental_file_size = props_ds.size_values.first
174
+ xml.resource(:id => "supplement", :type => "supplement", :data => "content", :sequence => sequence+1, :objectId => supplemental_file.pid) {
175
+ xml.attr(:name => "label") {
176
+ xml.text(supplemental_file_label)
177
+ }
178
+ xml.file(:id => supplemental_file_name, :mimetype => supplemental_file_mimetype, :size => supplemental_file_size, :shelve => "yes", :deliver => "yes", :preserve => "yes") {
179
+ xml.location(:type => "url") {
180
+ xml.text("https://stacks.stanford.edu/file/#{pid}/#{supplemental_file_name}")
181
+ }
182
+ }
183
+ }
184
+ end
185
+ # permission files
186
+ permission_files.each_with_index do |permission_file, sequence|
187
+ props_ds = permission_file.datastreams['properties']
188
+ permission_file_name = props_ds.file_name_values.first
189
+ permission_file_mimetype = MIME::Types.type_for(permission_file_name).first.content_type
190
+ permission_file_label = props_ds.label_values.first
191
+ permission_file_size = props_ds.size_values.first
192
+ xml.resource(:id => "permissions", :type => "permissions", :data => "content", :objectId => permission_file.pid) {
193
+ xml.attr(:name => "label") {
194
+ xml.text(permission_file_label)
195
+ }
196
+ xml.file(:id => permission_file_name, :mimetype => permission_file_mimetype, :size => permission_file_size, :shelve => "yes", :deliver => "no", :preserve => "yes")
197
+ }
198
+ end
199
+ }
200
+ end
201
+ builder.to_xml
202
+ end
203
+
204
+ # create the rights metadata xml datastream
205
+ #
206
+ # <rightsMetadata objectId="druid:rt923jk342">
207
+ # <copyright>
208
+ # <human>(c) Copyright [conferral year] by [student name]</human>
209
+ # </copyright>
210
+ # <access type="discover"> <--- this block is static across EEMs; all EEMs are discoverable
211
+ # <machine>
212
+ # <world />
213
+ # </machine>
214
+ # </access>
215
+ # <access type="read"> <--- include this block after an object has been "released"
216
+ # <machine>
217
+ # <group>stanford:stanford</group> -OR- <world /> <--- for Stanford-only access or world/public visibility
218
+ # <embargoReleaseDate>2011-03-01</embargoReleaseDate> <--- if embargoed, date calculated from release date
219
+ # </machine>
220
+ # </access>
221
+ # <use>
222
+ # <machine type="creativeCommons" type="code">value</machine> <--- if a license is selected
223
+ # <use>
224
+ # </rightsMetadata>
225
+ #
226
+ def generate_rights_metadata_xml
227
+
228
+ # determine which parts of the rights metadata should be displayed based on the workflow lifecycle
229
+ is_shelved = false
230
+ shelve_status = Dor::WorkflowService.get_workflow_status(pid,'eemAccessionWF','shelve')
231
+ if( "#{shelve_status}".eql? "completed" )
232
+ is_shelved = true
233
+ end
234
+
235
+ builder = Nokogiri::XML::Builder.new do |xml|
236
+ xml.rightsMetadata(:objectId => pid) {
237
+ props_ds = datastreams['properties']
238
+ conferral_year = props_ds.degreeconfyr_values.first
239
+ student_name = props_ds.name_values.first
240
+ xml.copyright {
241
+ xml.human {
242
+ formatted_student_name = Dor::Util.parse_name(student_name)
243
+ xml.text("(c) Copyright #{conferral_year} by #{formatted_student_name}")
244
+ }
245
+ }
246
+ xml.access(:type => "discover") {
247
+ xml.machine {
248
+ xml.world
249
+ }
250
+ }
251
+ if( is_shelved )
252
+ release_date = get_embargo_date
253
+ visibility = props_ds.external_visibility_values.first
254
+ generate_rights_access_block(xml,release_date,visibility)
255
+ end
256
+ cc_license_type = props_ds.cclicensetype_values.first
257
+ cc_code = props_ds.cclicense_values.first
258
+ cc_license = case cc_code
259
+ when "1" then 'by'
260
+ when "2" then 'by-sa'
261
+ when "3" then 'by-nd'
262
+ when "4" then 'by-nc'
263
+ when "5" then 'by-nc-sa'
264
+ when "6" then 'by-nc-nd'
265
+ else 'none'
266
+ end
267
+ unless( cc_license.nil? and cc_license_type.nil? )
268
+ xml.use {
269
+ xml.machine(:type => "creativeCommons") {
270
+ xml.text(cc_license)
271
+ }
272
+ xml.human(:type => "creativeCommons") {
273
+ xml.text(cc_license_type)
274
+ }
275
+ }
276
+ end
277
+ }
278
+ end
279
+ builder.to_xml
280
+ end
281
+
282
+ def generate_rights_access_block(xml,release_date,visibility)
283
+ access_type = 'stanford'
284
+ if( visibility == '100' and (!release_date.nil? and release_date.past?) )
285
+ access_type = 'world'
286
+ end
287
+ xml.access(:type => "read") {
288
+ xml.machine {
289
+ if( access_type.eql? 'stanford' )
290
+ xml.group {
291
+ xml.text("stanford")
292
+ }
293
+ if( !release_date.nil? && release_date.future? )
294
+ xml.embargoReleaseDate {
295
+ xml.text(release_date.strftime("%Y-%m-%d"))
296
+ }
297
+ end
298
+ else
299
+ xml.world
300
+ end
301
+ }
302
+ }
303
+ end
304
+
305
+ end
306
+ end
307
+
@@ -0,0 +1,20 @@
1
+
2
+ module EemModel
3
+
4
+ class Part < ActiveFedora::Base
5
+
6
+ has_relationship "parents", :is_part_of #relationship between content file and parent Eem
7
+
8
+ has_metadata :name => 'properties', :type => ActiveFedora::MetadataDatastream do |m|
9
+ m.label = "properties"
10
+ m.field "url", :string
11
+ m.field "done", :string
12
+ m.field "content_file_id", :string
13
+ m.field "filename", :string
14
+ m.field "download_date", :string
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
data/lib/eem_model.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'eem_model/eem'
2
+ require 'eem_model/part'
3
+ require 'eem_model/eem_accession'
4
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eem_model
3
+ version: !ruby/object:Gem::Version
4
+ hash: 67
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ - 2
11
+ version: 0.0.2.2
12
+ platform: ruby
13
+ authors:
14
+ - Douglas Kim
15
+ - Willy Mene
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-01-07 00:00:00 -08:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: active-fedora
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 9
32
+ segments:
33
+ - 1
34
+ - 1
35
+ - 13
36
+ version: 1.1.13
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ description: Contains classes that define the Fedora content model for everday electronic materials.
40
+ email:
41
+ - dougkim@stanford.edu
42
+ - wmene@stanford.edu
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - lib/eem_model/eem.rb
51
+ - lib/eem_model/eem_accession.rb
52
+ - lib/eem_model/part.rb
53
+ - lib/eem_model.rb
54
+ - LICENSE
55
+ - README.rdoc
56
+ has_rdoc: true
57
+ homepage: http://github.com/wmene/eem_model
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 23
80
+ segments:
81
+ - 1
82
+ - 3
83
+ - 6
84
+ version: 1.3.6
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: SULAIR Everyday Electronic Materials Fedora Content Model
92
+ test_files: []
93
+