dor-services 4.5.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Dor
7
7
  "http://www.loc.gov/mods/v3" => 'mods'
8
8
  }
9
9
  class CrosswalkError < Exception; end
10
-
10
+
11
11
  included do
12
12
  has_metadata :name => "descMetadata", :type => Dor::DescMetadataDS, :label => 'Descriptive Metadata', :control_group => 'M'
13
13
  end
@@ -31,7 +31,7 @@ module Dor
31
31
  ds.content = ds.ng_xml.to_xml
32
32
  end
33
33
  end
34
-
34
+
35
35
  # Generates Dublin Core from the MODS in the descMetadata datastream using the LoC mods2dc stylesheet
36
36
  # Should not be used for the Fedora DC datastream
37
37
  # @raise [Exception] Raises an Exception if the generated DC is empty or has no children
@@ -41,7 +41,9 @@ module Dor
41
41
  raise CrosswalkError, "Unknown descMetadata namespace: #{metadata_namespace.inspect}"
42
42
  end
43
43
  xslt = Nokogiri::XSLT(File.new(File.expand_path(File.dirname(__FILE__) + "/#{format}2dc.xslt")) )
44
- dc_doc = xslt.transform(Nokogiri::XML(self.add_collection_reference))
44
+ desc_md = self.descMetadata.ng_xml.dup(1)
45
+ self.add_collection_reference(desc_md)
46
+ dc_doc = xslt.transform(desc_md)
45
47
  # Remove empty nodes
46
48
  dc_doc.xpath('/oai_dc:dc/*[count(text()) = 0]').remove
47
49
  if(dc_doc.root.nil? || dc_doc.root.children.size == 0)
@@ -49,54 +51,90 @@ module Dor
49
51
  end
50
52
  dc_doc
51
53
  end
52
- #returns the desc metadata a relatedItem with information about the collection this object belongs to for use in published mods and mods to DC conversion
53
- def add_collection_reference
54
+
55
+ def generate_public_desc_md
56
+ doc = self.descMetadata.ng_xml.dup(1)
57
+ add_collection_reference(doc)
58
+ add_access_conditions(doc)
59
+ Nokogiri::XML(doc.to_xml) { |x| x.noblanks }.to_xml { |config| config.no_declaration }
60
+ end
61
+
62
+ # Create MODS accessCondition statements from rightsMetadata
63
+ # @param [Nokogiri::XML::Document] doc Document representing the descriptiveMetadata of the object
64
+ # @note this method modifies the passed in doc
65
+ def add_access_conditions(doc)
66
+ # clear out any existing accessConditions
67
+ doc.xpath('//mods:accessCondition').each {|n| n.remove}
68
+ rights = self.datastreams['rightsMetadata'].ng_xml
69
+
70
+ rights.xpath('//use/human[@type="useAndReproduction"]').each do |use|
71
+ new_use = doc.create_element("accessCondition", use.text.strip, :type => 'useAndReproduction')
72
+ doc.root.element_children.last.add_next_sibling new_use
73
+ end
74
+ rights.xpath('//copyright/human[@type="copyright"]').each do |cr|
75
+ new_use = doc.create_element("accessCondition", cr.text.strip, :type => 'copyright')
76
+ doc.root.element_children.last.add_next_sibling new_use
77
+ end
78
+ rights.xpath("//use/machine[#{ci_compare('type', 'creativecommons')}]").each do |lic|
79
+ next if(lic.text =~ /none/i)
80
+ new_text = "CC #{lic.text} : " << rights.at_xpath("//use/human[#{ci_compare('type', 'creativecommons')}]").text.strip
81
+ new_lic = doc.create_element("accessCondition", new_text, :type => 'license')
82
+ doc.root.element_children.last.add_next_sibling new_lic
83
+ end
84
+ rights.xpath("//use/machine[#{ci_compare('type', 'opendata')}]").each do |lic|
85
+ next if(lic.text =~ /none/i)
86
+ new_text = "ODC #{lic.text} : " << rights.at_xpath("//use/human[#{ci_compare('type', 'opendata')}]").text.strip
87
+ new_lic = doc.create_element("accessCondition", new_text, :type => 'license')
88
+ doc.root.element_children.last.add_next_sibling new_lic
89
+ end
90
+ end
91
+
92
+ # returns the desc metadata a relatedItem with information about the collection this object belongs to for use in published mods and mods to DC conversion
93
+ # @param [Nokogiri::XML::Document] doc Document representing the descriptiveMetadata of the object
94
+ # @note this method modifies the passed in doc
95
+ def add_collection_reference(doc)
54
96
  if not self.methods.include? :public_relationships
55
- return self.descMetadata.ng_xml.to_s
97
+ return
56
98
  end
57
99
  relationships=self.public_relationships
58
- xml=Nokogiri::XML(self.descMetadata.ng_xml.to_s)
59
-
100
+
60
101
  collections=relationships.search('//rdf:RDF/rdf:Description/fedora:isMemberOfCollection','fedora' => 'info:fedora/fedora-system:def/relations-external#', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' )
61
102
  #if there is an existing relatedItem node with type=host and a child typeOfResource @collection=yes dont add anything
62
- existing_node=xml.search('//mods:relatedItem/mods:typeOfResource[@collection=\'yes\']', 'mods' => 'http://www.loc.gov/mods/v3')
63
- if(existing_node.length>0)
64
- return xml.to_s
103
+ existing_node=doc.search('//mods:relatedItem/mods:typeOfResource[@collection=\'yes\']', 'mods' => 'http://www.loc.gov/mods/v3')
104
+ if(existing_node.length > 0)
105
+ return
65
106
  end
66
107
  collections.each do |collection_node|
67
108
  druid=collection_node['rdf:resource']
68
109
  druid=druid.gsub('info:fedora/','')
69
110
  collection_obj=Dor::Item.find(druid)
70
111
  collection_title = Dor::Describable.get_collection_title(collection_obj)
71
- node=xml.search('//mods:mods', 'mods' => 'http://www.loc.gov/mods/v3')
72
- node=node.first
73
- related_item_node=Nokogiri::XML::Node.new('relatedItem',xml)
112
+ related_item_node=Nokogiri::XML::Node.new('relatedItem',doc)
74
113
  related_item_node['type']='host'
75
- title_info_node=Nokogiri::XML::Node.new('titleInfo',xml)
76
- title_node=Nokogiri::XML::Node.new('title',xml)
114
+ title_info_node=Nokogiri::XML::Node.new('titleInfo',doc)
115
+ title_node=Nokogiri::XML::Node.new('title',doc)
77
116
  title_node.content=collection_title
78
- type_node=Nokogiri::XML::Node.new('typeOfResource',xml)
117
+ type_node=Nokogiri::XML::Node.new('typeOfResource',doc)
79
118
  type_node['collection'] = 'yes'
80
- node.add_child(related_item_node)
119
+ doc.root.add_child(related_item_node)
81
120
  related_item_node.add_child(title_info_node)
82
121
  title_info_node.add_child(title_node)
83
122
  related_item_node.add_child(type_node)
84
123
  end
85
- Nokogiri::XML(xml.to_s) {|x| x.noblanks }.to_s
86
124
  end
87
125
  def metadata_namespace
88
126
  desc_md = self.datastreams['descMetadata'].ng_xml
89
127
  if desc_md.nil? or desc_md.root.nil? or desc_md.root.namespace.nil?
90
- return nil
128
+ return nil
91
129
  else
92
130
  return desc_md.root.namespace.href
93
131
  end
94
132
  end
95
-
133
+
96
134
  def metadata_format
97
135
  DESC_MD_FORMATS[metadata_namespace]
98
136
  end
99
-
137
+
100
138
  def to_solr(solr_doc=Hash.new, *args)
101
139
  super solr_doc, *args
102
140
  add_solr_value(solr_doc, "metadata_format", self.metadata_format, :string, [:searchable, :facetable])
@@ -135,18 +173,18 @@ module Dor
135
173
  end
136
174
  end
137
175
  def delete_identifier(type,value=nil)
138
-
176
+
139
177
  ds_xml=self.descMetadata.ng_xml
140
- ds_xml.search('//mods:identifier','mods' => 'http://www.loc.gov/mods/v3').each do |node|
178
+ ds_xml.search('//mods:identifier','mods' => 'http://www.loc.gov/mods/v3').each do |node|
141
179
  if node.content == value or value==nil
142
180
  node.remove
143
- return true
181
+ return true
144
182
  end
145
183
  end
146
184
  return false
147
185
  end
148
-
149
- def set_desc_metadata_using_label(force=false)
186
+
187
+ def set_desc_metadata_using_label(force=false)
150
188
  ds=self.descMetadata
151
189
  unless force or ds.new?#22 is the length of <?xml version="1.0"?>
152
190
  raise 'Cannot proceed, there is already content in the descriptive metadata datastream.'+ds.content.to_s
@@ -158,10 +196,10 @@ module Dor
158
196
  xml.title label
159
197
  }
160
198
  }
161
- }
199
+ }
162
200
  self.descMetadata.content=builder.to_xml
163
201
  end
164
-
202
+
165
203
  def self.get_collection_title(obj)
166
204
  xml=obj.descMetadata.ng_xml
167
205
  preferred_citation=xml.search('//mods:mods/mods:note[@type=\'preferredCitation\']','mods' => 'http://www.loc.gov/mods/v3')
@@ -177,7 +215,7 @@ module Dor
177
215
  end
178
216
  title
179
217
  end
180
-
218
+
181
219
  private
182
220
  #generic updater useful for updating things like title or subtitle which can only have a single occurance and must be present
183
221
  def update_simple_field(field,new_val)
@@ -188,7 +226,16 @@ module Dor
188
226
  end
189
227
  return false
190
228
  end
191
-
192
-
229
+
230
+ # Builds case-insensitive xpath translate function call that will match the attribute to a value
231
+ def ci_compare(attribute, value)
232
+ "translate(
233
+ @#{attribute},
234
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
235
+ 'abcdefghijklmnopqrstuvwxyz'
236
+ ) = '#{value}' "
237
+ end
238
+
239
+
193
240
  end
194
241
  end
@@ -56,7 +56,7 @@ module Dor
56
56
  DigitalStacksService.transfer_to_document_store(pid, self.datastreams['rightsMetadata'].to_xml, 'rightsMetadata')
57
57
  DigitalStacksService.transfer_to_document_store(pid, public_xml, 'public')
58
58
  if self.metadata_format == 'mods'
59
- DigitalStacksService.transfer_to_document_store(pid, self.add_collection_reference, 'mods')
59
+ DigitalStacksService.transfer_to_document_store(pid, self.generate_public_desc_md, 'mods')
60
60
  end
61
61
  else
62
62
  # Clear out the document cache for this item
data/lib/dor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dor
2
- VERSION = '4.5.0'
2
+ VERSION = '4.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-02-05 00:00:00.000000000 Z
16
+ date: 2014-02-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: active-fedora