eem_model 0.0.2.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+
2
+ module EemModel
3
+
4
+ class ContentFile < ActiveRecord::Base
5
+
6
+ # needs to save percent done to object in db
7
+ def update_progress(dl_total, dl_now)
8
+ done_now = (Float(dl_now) / Float(dl_total) * 100).round
9
+ update_attribute(:percent_done, done_now) if(done_now != percent_done)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
data/lib/eem_model/eem.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_fedora'
1
2
 
2
3
  module EemModel
3
4
 
@@ -5,9 +6,9 @@ module EemModel
5
6
 
6
7
  has_relationship "parts", :is_part_of, :inbound => true #content files
7
8
 
9
+ has_relationship "permission_files", :is_dependent_of, :inbound => true
10
+
8
11
  has_metadata :name => 'eemsProperties', :type => ActiveFedora::MetadataDatastream do |m|
9
- m.label = "eemsProperties"
10
-
11
12
  m.field "copyrightStatusDate", :string, :multiple => false #mutiple doesn't do anything
12
13
  m.field "copyrightStatus", :string
13
14
  m.field "creatorOrg", :string
@@ -25,9 +26,6 @@ module EemModel
25
26
  m.field "statusDatetime", :string
26
27
  m.field "downloadDate", :string
27
28
  end
28
-
29
- has_metadata :name => "DC", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
30
- end
31
29
 
32
30
  end
33
31
 
@@ -1,10 +1,11 @@
1
+ require 'active_fedora'
1
2
 
2
3
  module EemModel
3
4
 
4
5
  class Part < ActiveFedora::Base
5
6
 
6
7
  has_relationship "parents", :is_part_of #relationship between content file and parent Eem
7
-
8
+
8
9
  has_metadata :name => 'properties', :type => ActiveFedora::MetadataDatastream do |m|
9
10
  m.label = "properties"
10
11
  m.field "url", :string
@@ -0,0 +1,20 @@
1
+ require 'active_fedora'
2
+
3
+ module EemModel
4
+
5
+ class PermissionFile < ActiveFedora::Base
6
+
7
+ has_relationship "permission_file_for", :is_dependent_of # relationship between permission file and parent eem
8
+
9
+ has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
10
+ m.field "file_name", :string
11
+ m.field "comment", :string
12
+ end
13
+
14
+ has_metadata :name => "DC", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
data/lib/eem_model.rb CHANGED
@@ -1,4 +1,3 @@
1
1
  require 'eem_model/eem'
2
2
  require 'eem_model/part'
3
- require 'eem_model/eem_accession'
4
3
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eem_model
3
3
  version: !ruby/object:Gem::Version
4
- hash: 67
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- - 2
11
- version: 0.0.2.2
9
+ - 3
10
+ version: 0.0.3
12
11
  platform: ruby
13
12
  authors:
14
13
  - Douglas Kim
@@ -17,7 +16,7 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2011-01-07 00:00:00 -08:00
19
+ date: 2011-02-01 00:00:00 -08:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
@@ -47,9 +46,10 @@ extensions: []
47
46
  extra_rdoc_files: []
48
47
 
49
48
  files:
49
+ - lib/eem_model/content_file.rb
50
50
  - lib/eem_model/eem.rb
51
- - lib/eem_model/eem_accession.rb
52
51
  - lib/eem_model/part.rb
52
+ - lib/eem_model/permission_file.rb
53
53
  - lib/eem_model.rb
54
54
  - LICENSE
55
55
  - README.rdoc
@@ -1,307 +0,0 @@
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
-