dor-services 4.13.2 → 4.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -207,7 +207,7 @@ module Dor
207
207
 
208
208
  # Clears RELS-EXT relationships, sets the isGovernedBy relationship to the SDR Graveyard APO
209
209
  # @param [String] tag optional String of text that is concatenated to the identityMetadata/tag "Decomissioned : "
210
- def decomission tag = nil
210
+ def decomission tag
211
211
  # remove isMemberOf and isMemberOfCollection relationships
212
212
  clear_relationship :is_member_of
213
213
  clear_relationship :is_member_of_collection
@@ -77,7 +77,7 @@ module Dor
77
77
  druid=druid.gsub('info:fedora/','')
78
78
  if @@apo_hash.has_key? druid or @@hydrus_apo_hash.has_key? druid
79
79
  add_solr_value(solr_doc, "hydrus_apo_title", @@hydrus_apo_hash[druid], :string, [:searchable, :facetable]) if @@hydrus_apo_hash.has_key? druid
80
- add_solr_value(solr_doc, "apo_title", @@apo_hash[druid] , :string, [:searchable, :facetable]) if @@apo_hash.has_key? druid
80
+ add_solr_value(solr_doc, "apo_title", @@apo_hash[druid] , :string, [:searchable, :facetable]) if @@apo_hash.has_key? druid
81
81
  else
82
82
  begin
83
83
  apo_object=Dor.find(druid)
@@ -95,7 +95,7 @@ module Dor
95
95
  end
96
96
  end
97
97
  collections=rels_doc.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#' )
98
- collections.each do |collection_node|
98
+ collections.each do |collection_node|
99
99
  druid=collection_node['rdf:resource']
100
100
  if(druid)
101
101
  druid=druid.gsub('info:fedora/','')
@@ -117,9 +117,9 @@ module Dor
117
117
  end
118
118
  end
119
119
  end
120
- end
120
+ end
121
121
  # Fix for ActiveFedora 3.3 to ensure all date fields are properly formatted as UTC XML Schema datetime strings
122
- solr_doc.each_pair { |k,v|
122
+ solr_doc.each_pair { |k,v|
123
123
  if k =~ /_dt|_date$/
124
124
  if v.is_a?(Array)
125
125
  solr_doc[k] = v.collect { |t| Time.parse(t.to_s).utc.xmlschema }
@@ -136,7 +136,7 @@ module Dor
136
136
  end
137
137
 
138
138
  def add_other_Id(type,val)
139
- if self.identityMetadata.otherId(type).length>0
139
+ if self.identityMetadata.otherId(type).length>0
140
140
  raise 'There is an existing entry for '+node_name+', consider using update_other_identifier.'
141
141
  end
142
142
  identity_metadata_ds = self.identityMetadata
@@ -171,41 +171,77 @@ module Dor
171
171
  return removed
172
172
  end
173
173
 
174
+ # turns a tag string into an array with one element per tag part.
175
+ # split on ":", disregard leading and trailing whitespace on tokens.
176
+ def split_tag_to_arr(tag_str)
177
+ return tag_str.split(":").map {|str| str.strip}
178
+ end
179
+
180
+ # turn a tag array back into a tag string with a standard format
181
+ def normalize_tag_arr(tag_arr)
182
+ return tag_arr.join(' : ')
183
+ end
184
+
185
+ # take a tag string and return a normalized tag string
186
+ def normalize_tag(tag_str)
187
+ return normalize_tag_arr(split_tag_to_arr(tag_str))
188
+ end
189
+
190
+ # take a proposed tag string and a list of the existing tags for the object being edited. if
191
+ # the proposed tag is valid, return it in normalized form. if not, raise an exception with an
192
+ # explanatory message.
193
+ def validate_and_normalize_tag(tag_str, existing_tag_list)
194
+ tag_arr = split_tag_to_arr(tag_str)
195
+
196
+ if tag_arr.length < 2
197
+ raise "Invalid tag structure: tag '#{tag_str}' must have at least 2 elements"
198
+ end
199
+
200
+ if tag_arr.detect {|str| str.empty?}
201
+ raise "Invalid tag structure: tag '#{tag_str}' contains empty elements"
202
+ end
203
+
204
+ # note that the comparison for duplicate tags is case-insensitive, but we don't change case as part of the normalized version
205
+ # we return, because we want to preserve the user's intended case.
206
+ normalized_tag = normalize_tag_arr(tag_arr)
207
+ dupe_existing_tag = existing_tag_list.detect { |existing_tag| normalize_tag(existing_tag).downcase == normalized_tag.downcase }
208
+ if dupe_existing_tag
209
+ raise "An existing tag (#{dupe_existing_tag}) is the same, consider using update_tag?"
210
+ end
211
+
212
+ return normalized_tag
213
+ end
214
+
174
215
  def add_tag(tag)
175
216
  identity_metadata_ds = self.identityMetadata
176
- prefix=tag.split(/:/).first
177
- identity_metadata_ds.tags.each do |existing_tag|
178
- if existing_tag.split(/:/).first ==prefix
179
- raise 'An existing tag ('+existing_tag+') has the same prefix, consider using update_tag?'
180
- end
181
- end
182
- identity_metadata_ds.add_value(:tag,tag)
217
+ normalized_tag = validate_and_normalize_tag(tag, identity_metadata_ds.tags)
218
+ identity_metadata_ds.add_value(:tag, normalized_tag)
183
219
  end
184
220
 
185
221
  def remove_tag(tag)
186
222
  identity_metadata_ds = self.identityMetadata
187
- ds_xml=identity_metadata_ds.ng_xml
188
- removed=false
223
+ ds_xml = identity_metadata_ds.ng_xml
224
+ removed = false
189
225
  ds_xml.search('//tag').each do |node|
190
- if node.content===tag
226
+ if normalize_tag(node.content) === normalize_tag(tag)
191
227
  node.remove
192
- removed=true
228
+ removed = true
193
229
  end
194
230
  end
195
231
  return removed
196
232
  end
197
233
 
198
- def update_tag(old_tag,new_tag)
234
+ def update_tag(old_tag, new_tag)
199
235
  identity_metadata_ds = self.identityMetadata
200
- ds_xml=identity_metadata_ds.ng_xml
201
- updated=false
236
+ ds_xml = identity_metadata_ds.ng_xml
237
+ updated = false
202
238
  ds_xml.search('//tag').each do |node|
203
- if node.content==old_tag
204
- node.content=new_tag
239
+ if normalize_tag(node.content) == normalize_tag(old_tag)
240
+ node.content = normalize_tag(new_tag)
205
241
  updated = true
206
242
  end
207
243
  end
208
- return updated
244
+ return updated
209
245
  end
210
246
  end
211
247
  end
data/lib/dor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dor
2
- VERSION = '4.13.2'
2
+ VERSION = '4.14.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.13.2
4
+ version: 4.14.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-09-12 00:00:00.000000000 Z
16
+ date: 2014-09-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: active-fedora