Class: Dor::VersionMetadataDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::VersionMetadataDS
- Defined in:
- lib/dor/datastreams/version_metadata_ds.rb
Class Method Summary collapse
-
.xml_template ⇒ Object
Default EventsDS xml.
Instance Method Summary collapse
-
#current_description ⇒ String
The description for the current version.
-
#current_tag ⇒ String
The tag for the newest version.
-
#current_version_closeable? ⇒ Boolean
Returns true if the current version has a tag and a description, false otherwise.
-
#current_version_id ⇒ String
Value of the most current versionId.
-
#description_for_version(versionId) ⇒ String
The description for the specified version, or empty string if there is no description.
- #ensure_non_versionable ⇒ Object
- #increment_version(description = nil, significance = nil) ⇒ Object
-
#sync_then_increment_version(known_version, opts = {}) ⇒ Object
Compares the current_version with the passed in known_version (usually SDRs version) If the known_version is greater than the current version, then all version nodes greater than the known_version are removed, then the current_version is incremented.
- #tag_for_version(versionId) ⇒ Object
- #update_current_version(opts = {}) ⇒ Object
Class Method Details
.xml_template ⇒ Object
Default EventsDS xml
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 65 def self.xml_template builder = Nokogiri::XML::Builder.new do |xml| xml.versionMetadata { xml.version(:versionId => '1', :tag => '1.0.0') { xml.description 'Initial Version' } } end return builder.doc end |
Instance Method Details
#current_description ⇒ String
Returns The description for the current version.
189 190 191 192 193 194 195 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 189 def current_description desc_node=current_version_node.at_xpath('description') if desc_node return desc_node.content end '' end |
#current_tag ⇒ String
Returns The tag for the newest version.
165 166 167 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 165 def current_tag current_version_node[:tag].to_s end |
#current_version_closeable? ⇒ Boolean
Returns true if the current version has a tag and a description, false otherwise
155 156 157 158 159 160 161 162 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 155 def current_version_closeable? current = current_version_node if(current[:tag] && current.at_xpath('description')) return true else return false end end |
#current_version_id ⇒ String
Returns value of the most current versionId.
111 112 113 114 115 116 117 118 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 111 def current_version_id current_version=current_version_node if current_version.nil? return '1' else current_version[:versionId].to_s end end |
#description_for_version(versionId) ⇒ String
Returns The description for the specified version, or empty string if there is no description.
179 180 181 182 183 184 185 186 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 179 def description_for_version(versionId) nodes=self.ng_xml.search('//version[@versionId=\''+versionId+'\']') if nodes.length == 1 and nodes.first.at_xpath('description') nodes.first.at_xpath('description').content.to_s else '' end end |
#ensure_non_versionable ⇒ Object
76 77 78 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 76 def ensure_non_versionable self.versionable = "false" end |
#increment_version(description = nil, significance = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 83 def increment_version(description = nil, significance = nil) if( find_by_terms(:version).size == 0) v = ng_xml.create_element "version", :versionId => '1', :tag => '1.0.0' d = ng_xml.create_element "description", "Initial Version" ng_xml.root['objectId'] = pid ng_xml.root.add_child(v) v.add_child d else current = current_version_node current_id = current[:versionId].to_i current_tag = VersionTag.parse(current[:tag]) v = ng_xml.create_element "version", :versionId => (current_id + 1).to_s if(significance && current_tag) v[:tag] = current_tag.increment(significance).to_s end ng_xml.root['objectId'] = pid ng_xml.root.add_child(v) if(description) d = ng_xml.create_element "description", description v.add_child d end end end |
#sync_then_increment_version(known_version, opts = {}) ⇒ Object
Compares the current_version with the passed in known_version (usually SDRs version)
If the known_version is greater than the current version, then all version nodes greater than the known_version are removed,
then the current_version is incremented. This repairs the case where a previous call to open a new verison
updates the versionMetadata datastream, but versioningWF is not initiated. Prevents the versions from getting
out of synch with SDR
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 207 def sync_then_increment_version known_version, opts = {} cv = current_version_id.to_i raise Dor::Exception.new("Cannot sync to a version greater than current: #{cv}, requested #{known_version}") if cv < known_version while cv != known_version && current_version_node.remove cv = current_version_id.to_i end increment_version(opts[:description], opts[:significance]) end |
#tag_for_version(versionId) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 169 def tag_for_version(versionId) nodes=self.ng_xml.search('//version[@versionId=\''+versionId+'\']') if nodes.length == 1 nodes.first['tag'].to_s else '' end end |
#update_current_version(opts = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 124 def update_current_version(opts = {}) ng_xml.root['objectId'] = pid return if find_by_terms(:version).size == 1 return if opts.empty? current = current_version_node if(opts.include? :description) d = current.at_xpath('description') if(d) d.content = opts[:description] else d_node = ng_xml.create_element "description", opts[:description] current.add_child d_node end end if(opts.include? :significance) # tricky because if there is no tag, we have to find the newest if(current[:tag].nil?) current[:tag] = newest_tag.increment(opts[:significance]).to_s else # get rid of the current tag = find_by_terms(:version, :tag) = .map{|t| VersionTag.parse(t.value)}.sort current_tag = [.length - 2] # Get the second greatest tag since we are dropping the current, greatest current[:tag] = current_tag.increment(opts[:significance]).to_s end end self.content = ng_xml.to_s end |