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
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 62 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 builder.doc end |
Instance Method Details
#current_description ⇒ String
Returns The description for the current version.
186 187 188 189 190 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 186 def current_description desc_node = current_version_node.at_xpath('description') return desc_node.content if desc_node '' end |
#current_tag ⇒ String
Returns The tag for the newest version.
162 163 164 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 162 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
152 153 154 155 156 157 158 159 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 152 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.
108 109 110 111 112 113 114 115 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 108 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.
176 177 178 179 180 181 182 183 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 176 def description_for_version(versionId) nodes = ng_xml.search('//version[@versionId=\'' + versionId + '\']') if nodes.length == 1 && nodes.first.at_xpath('description') nodes.first.at_xpath('description').content.to_s else '' end end |
#ensure_non_versionable ⇒ Object
73 74 75 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 73 def ensure_non_versionable self.versionable = 'false' end |
#increment_version(description = nil, significance = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 80 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
202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 202 def sync_then_increment_version(known_version, opts = {}) cv = current_version_id.to_i raise Dor::Exception, "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
166 167 168 169 170 171 172 173 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 166 def tag_for_version(versionId) nodes = ng_xml.search('//version[@versionId=\'' + versionId + '\']') if nodes.length == 1 nodes.first['tag'].to_s else '' end end |
#update_current_version(opts = {}) ⇒ Object
121 122 123 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 |
# File 'lib/dor/datastreams/version_metadata_ds.rb', line 121 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 |