moab-versioning 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # A class to represent the SDR repository store
6
5
  #
7
6
  # ====Data Model
@@ -14,7 +13,6 @@ module Moab
14
13
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
15
14
  # All rights reserved. See {file:LICENSE.rdoc} for details.
16
15
  class StorageRepository
17
-
18
16
  # Note that Moab::Config is not initialized from environment config file until after
19
17
  # this object is initialized by StorageServices
20
18
  # (see sequence of requires in spec_helper.rb and in applications that use)
@@ -23,9 +21,9 @@ module Moab
23
21
  def storage_roots
24
22
  unless defined?(@storage_roots)
25
23
  raise "Moab::Config.storage_roots not found in config file" if Moab::Config.storage_roots.nil?
26
- @storage_roots = [Moab::Config.storage_roots].flatten.collect{|filesystem| Pathname(filesystem)}
27
- raise "Moab::Config.storage_roots empty" if @storage_roots.empty?
28
- @storage_roots.each{|root| raise "Storage root #{root} not found on system" unless root.exist?}
24
+ @storage_roots = [Moab::Config.storage_roots].flatten.collect { |filesystem| Pathname(filesystem) }
25
+ raise "Moab::Config.storage_roots empty" if @storage_roots.empty?
26
+ @storage_roots.each { |root| raise "Storage root #{root} not found on system" unless root.exist? }
29
27
  end
30
28
  @storage_roots
31
29
  end
@@ -33,7 +31,7 @@ module Moab
33
31
  # @return [String] The trunk segment of the object storage path
34
32
  def storage_trunk
35
33
  unless defined?(@storage_trunk)
36
- raise "oab::Config.storage_trunk not found in config file" if Moab::Config.storage_trunk.nil?
34
+ raise "Moab::Config.storage_trunk not found in config file" if Moab::Config.storage_trunk.nil?
37
35
  @storage_trunk = Moab::Config.storage_trunk
38
36
  end
39
37
  @storage_trunk
@@ -69,7 +67,7 @@ module Moab
69
67
  # @param object_id [String] The identifier of the digital object whose version is desired
70
68
  # @param include_deposit [Boolean] specifies whether to look in deposit areas for objects in process of initial ingest
71
69
  # @return [Pathname] The location of the desired object's home directory (default=pairtree)
72
- def find_storage_root(object_id, include_deposit=false)
70
+ def find_storage_root(object_id, include_deposit = false)
73
71
  # Search for the object's home directory in the storage areas
74
72
  branch = storage_branch(object_id)
75
73
  storage_roots.each do |root|
@@ -95,7 +93,7 @@ module Moab
95
93
  # @param object_id [String] The identifier of the digital object whose version is desired
96
94
  # @param include_deposit [Boolean] specifies whether to look in deposit areas for objects in process of initial ingest
97
95
  # @return [StorageObject] The representation of a digitial object's storage directory, which might not exist yet.
98
- def find_storage_object(object_id, include_deposit=false)
96
+ def find_storage_object(object_id, include_deposit = false)
99
97
  root = find_storage_root(object_id, include_deposit)
100
98
  storage_pathname = root.join(storage_trunk, storage_branch(object_id))
101
99
  storage_object = StorageObject.new(object_id, storage_pathname)
@@ -106,7 +104,7 @@ module Moab
106
104
  # @param object_id [String] The identifier of the digital object whose size is desired
107
105
  # @param include_deposit [Boolean] specifies whether to look in deposit areas for objects in process of initial ingest
108
106
  # @return [Integer] the size occupied on disk by the storage object, in bytes. this is the entire moab (all versions).
109
- def object_size(object_id, include_deposit=false)
107
+ def object_size(object_id, include_deposit = false)
110
108
  storage_pathname = find_storage_object(object_id, include_deposit).object_pathname
111
109
  size = 0
112
110
  Find.find(storage_pathname) do |path|
@@ -118,27 +116,25 @@ module Moab
118
116
  # @param object_id [String] The identifier of the digital object whose version is desired
119
117
  # @param create [Boolean] If true, the object home directory should be created if it does not exist
120
118
  # @return [StorageObject] The representation of a digitial object's storage directory, which must exist.
121
- def storage_object(object_id, create=false)
122
- storage_object = find_storage_object(object_id)
123
- unless storage_object.object_pathname.exist?
124
- if create
119
+ def storage_object(object_id, create = false)
120
+ storage_object = find_storage_object(object_id)
121
+ unless storage_object.object_pathname.exist?
122
+ if create
125
123
  storage_object.object_pathname.mkpath
126
- else
127
- raise Moab::ObjectNotFoundException, "No storage object found for #{object_id}"
124
+ else
125
+ raise Moab::ObjectNotFoundException, "No storage object found for #{object_id}"
126
+ end
128
127
  end
129
- end
130
- storage_object
128
+ storage_object
131
129
  end
132
130
 
133
131
  # @depricated Please use StorageObject#ingest_bag
134
132
  # @param druid [String] The object identifier
135
133
  # @return [void] transfer the object to the preservation repository
136
- def store_new_object_version(druid, bag_pathname )
137
- storage_object = self.storage_object(druid, create=true)
134
+ def store_new_object_version(druid, bag_pathname)
135
+ storage_object = self.storage_object(druid, create = true)
138
136
  new_version = storage_object.ingest_bag(bag_pathname)
139
137
  new_version
140
138
  end
141
-
142
139
  end
143
-
144
140
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # An interface class to support access to SDR storage via a RESTful server
6
5
  #
7
6
  # ====Data Model
@@ -14,7 +13,6 @@ module Moab
14
13
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
15
14
  # All rights reserved. See {file:LICENSE.rdoc} for details.
16
15
  class StorageServices
17
-
18
16
  # @return [StorageRepository] an instance of the interface to SDR storage
19
17
  @@repository = Moab::StorageRepository.new
20
18
 
@@ -41,21 +39,21 @@ module Moab
41
39
  # @param object_id [String] The identifier of the digital object
42
40
  # @param [Object] include_deposit
43
41
  # @return [StorageObject] The representation of a digitial object's storage directory, which might not exist yet.
44
- def self.find_storage_object(object_id, include_deposit=false)
42
+ def self.find_storage_object(object_id, include_deposit = false)
45
43
  @@repository.find_storage_object(object_id, include_deposit)
46
44
  end
47
45
 
48
46
  # @param object_id [String] The identifier of the digital object whose size is desired
49
47
  # @param include_deposit [Boolean] specifies whether to look in deposit areas for objects in process of initial ingest
50
48
  # @return [Integer] the size occupied on disk by the storage object, in bytes. this is the entire moab (all versions).
51
- def self.object_size(object_id, include_deposit=false)
49
+ def self.object_size(object_id, include_deposit = false)
52
50
  @@repository.object_size(object_id, include_deposit)
53
51
  end
54
52
 
55
53
  # @param object_id [String] The identifier of the digital object whose version is desired
56
54
  # @param create [Boolean] If true, the object home directory should be created if it does not exist
57
55
  # @return [StorageObject] The representation of a digitial object's storage directory, which must exist.
58
- def self.storage_object(object_id, create=false)
56
+ def self.storage_object(object_id, create = false)
59
57
  @@repository.storage_object(object_id, create)
60
58
  end
61
59
 
@@ -68,7 +66,7 @@ module Moab
68
66
  # @param object_id [String] The digital object identifier of the object
69
67
  # @param [Integer] version_id The ID of the version, if nil use latest version
70
68
  # @return [String] the location of the storage object version
71
- def self.object_version_path(object_id,version_id=nil)
69
+ def self.object_version_path(object_id, version_id = nil)
72
70
  @@repository.storage_object(object_id).find_object_version(version_id).version_pathname.to_s
73
71
  end
74
72
 
@@ -87,7 +85,7 @@ module Moab
87
85
  # @param [String] object_id The digital object identifier of the object
88
86
  # @param [Integer] version_id The ID of the version, if nil use latest version
89
87
  # @return [FileInventory] the file inventory for the specified object version
90
- def self.retrieve_file_group(file_category, object_id, version_id=nil)
88
+ def self.retrieve_file_group(file_category, object_id, version_id = nil)
91
89
  storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
92
90
  if file_category =~ /manifest/
93
91
  inventory_type = file_category = 'manifests'
@@ -103,7 +101,7 @@ module Moab
103
101
  # @param [String] object_id The digital object identifier of the object
104
102
  # @param [Integer] version_id The ID of the version, if nil use latest version
105
103
  # @return [Pathname] Pathname object containing the full path for the specified file
106
- def self.retrieve_file(file_category, file_id, object_id, version_id=nil)
104
+ def self.retrieve_file(file_category, file_id, object_id, version_id = nil)
107
105
  storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
108
106
  file_pathname = storage_object_version.find_filepath(file_category, file_id)
109
107
  end
@@ -113,7 +111,7 @@ module Moab
113
111
  # @param [String] object_id The digital object identifier of the object
114
112
  # @param [Integer] version_id The ID of the version, if nil use latest version
115
113
  # @return [Pathname] Pathname object containing the full path for the specified file
116
- def self.retrieve_file_using_signature(file_category, file_signature, object_id, version_id=nil)
114
+ def self.retrieve_file_using_signature(file_category, file_signature, object_id, version_id = nil)
117
115
  storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
118
116
  file_pathname = storage_object_version.find_filepath_using_signature(file_category, file_signature)
119
117
  end
@@ -123,7 +121,7 @@ module Moab
123
121
  # @param [String] object_id The digital object identifier of the object
124
122
  # @param [Integer] version_id The ID of the version, if nil use latest version
125
123
  # @return [FileSignature] The signature of the file
126
- def self.retrieve_file_signature(file_category, file_id, object_id, version_id=nil)
124
+ def self.retrieve_file_signature(file_category, file_id, object_id, version_id = nil)
127
125
  storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
128
126
  file_pathname = storage_object_version.find_signature(file_category, file_id)
129
127
  end
@@ -132,12 +130,12 @@ module Moab
132
130
  # @param [Object] base_version_id The identifier of the base version to be compared
133
131
  # @param [Object] compare_version_id The identifier of the version to be compared to the base version
134
132
  # @return [FileInventoryDifference] The report of the version differences
135
- def self.version_differences(object_id, base_version_id,compare_version_id)
133
+ def self.version_differences(object_id, base_version_id, compare_version_id)
136
134
  base_version = @@repository.storage_object(object_id).storage_object_version(base_version_id)
137
135
  compare_version = @@repository.storage_object(object_id).storage_object_version(compare_version_id)
138
- base_inventory=base_version.file_inventory('version')
139
- compare_inventory=compare_version.file_inventory('version')
140
- FileInventoryDifference.new.compare(base_inventory,compare_inventory)
136
+ base_inventory = base_version.file_inventory('version')
137
+ compare_inventory = compare_version.file_inventory('version')
138
+ FileInventoryDifference.new.compare(base_inventory, compare_inventory)
141
139
  end
142
140
  end
143
141
  end
data/lib/moab/utc_time.rb CHANGED
@@ -3,21 +3,20 @@ require 'time'
3
3
  module Moab
4
4
  # Timestamp conversion methods.
5
5
  class UtcTime
6
-
7
6
  # @param datetime [Time,String,Nil] The input datetime
8
7
  # @return [void] Convert input datetime to a Time object, or nil if input is empty.
9
8
  def self.input(datetime)
10
9
  case datetime
11
- when nil
12
- nil
13
- when ""
14
- nil
15
- when String
16
- Time.parse(datetime)
17
- when Time
18
- datetime
19
- else
20
- raise "unknown time format #{datetime.inspect}"
10
+ when nil
11
+ nil
12
+ when ""
13
+ nil
14
+ when String
15
+ Time.parse(datetime)
16
+ when Time
17
+ datetime
18
+ else
19
+ raise "unknown time format #{datetime.inspect}"
21
20
  end
22
21
  end
23
22
 
@@ -25,14 +24,14 @@ module Moab
25
24
  # @return [String] Convert the datetime into a ISO 8601 formatted string
26
25
  def self.output(datetime)
27
26
  case datetime
28
- when nil, ""
29
- ""
30
- when String
31
- Time.parse(datetime).utc.iso8601
32
- when Time
33
- datetime.utc.iso8601
34
- else
35
- raise "unknown time format #{datetime.inspect}"
27
+ when nil, ""
28
+ ""
29
+ when String
30
+ Time.parse(datetime).utc.iso8601
31
+ when Time
32
+ datetime.utc.iso8601
33
+ else
34
+ raise "unknown time format #{datetime.inspect}"
36
35
  end
37
36
  end
38
37
  end
@@ -1,9 +1,8 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
4
+ # A recursive "Tree" type object for verifications
5
5
  class VerificationResult
6
-
7
6
  # @return [String] The name of the entity that was verified
8
7
  attr_accessor :entity
9
8
 
@@ -16,69 +15,59 @@ module Moab
16
15
  # @return [Array<VerificationResult>] The subentities, if any, on which this verification is based
17
16
  attr_accessor :subentities
18
17
 
19
- # @param entity [Object] The name of the entity being verified
20
- def initialize(entity)
21
- @entity = entity
22
- @verified = false
23
- @details = nil
18
+ # @param entity [#to_s] The name of the entity being verified
19
+ # @param verified [Boolean]
20
+ # @param details [Hash]
21
+ def initialize(entity, verified = false, details = nil)
22
+ @entity = entity.to_s # force to string
23
+ @verified = !!verified # rubocop:disable Style/DoubleNegation
24
+ @details = details
24
25
  @subentities = Array.new
25
26
  end
26
27
 
27
- # @param entity [Symbol] The name of the entity being verified
28
+ # @param entity [#to_s] The name of the entity being verified
28
29
  # @param expected [Object] The expected value
29
30
  # @param found [Object] The found value
30
31
  # @return [VerificationResult] The result of comparing the expected and found values
31
32
  def self.verify_value(entity, expected, found)
32
- result = VerificationResult.new(entity.to_s)
33
- result.verified = (expected == found)
34
- result.details = {'expected' => expected, 'found' => found}
35
- result
33
+ details = { 'expected' => expected, 'found' => found }
34
+ new(entity, (expected == found), details)
36
35
  end
37
36
 
38
- # @param entity [Symbol] The name of the entity being verified
37
+ # @deprecated Just use the constructor
38
+ # @param entity [#to_s] The name of the entity being verified
39
39
  # @param expression [Object] The expression that will be evaluated as true or false
40
40
  # @param details [Object] optional details that could be reported
41
41
  # @return [VerificationResult] The result of evaluating the expression
42
- def self.verify_truth(entity,expression,details=nil)
43
- result = VerificationResult.new(entity.to_s)
44
- # TODO: add expression.empty?
45
- result.verified = !(expression.nil? or (expression == false))
46
- result.details = details
47
- result
42
+ def self.verify_truth(entity, expression, details = nil)
43
+ new(entity, expression, details)
48
44
  end
49
45
 
50
46
  # @param verbose [Boolean] If true, always provide all details of the verification
51
47
  # @return [String] The verification result serialized to JSON
52
- def to_json(verbose=false)
48
+ def to_json(verbose = false)
53
49
  JSON.pretty_generate(to_hash(verbose))
54
50
  end
55
51
 
56
52
  # @param verbose [Boolean] If true, always provide all details of the verification
57
53
  # @param level [Integer] Used to test the depth of recursion
58
54
  # @return [Hash] The verification result serialized to a hash
59
- def to_hash(verbose=false,level=0)
60
- hash = Hash.new
61
- hash['verified'] = @verified
62
- if (verbose or @verified == false)
63
- hash['details'] = @details ? @details : subentities_to_hash(verbose,level)
64
- end
65
- if level > 0
66
- hash
67
- else
68
- {@entity => hash}
55
+ def to_hash(verbose = false, level = 0)
56
+ hash = { 'verified' => verified }
57
+ if verbose || !verified
58
+ hash['details'] = details || subentities_to_hash(verbose, level)
69
59
  end
60
+ return hash if level > 0
61
+ { entity => hash }
70
62
  end
71
63
 
64
+ private
65
+
72
66
  # @param verbose [Boolean] If true, always provide all details of the verification
73
67
  # @param level [Integer] Used to increment the depth of recursion
74
68
  # @return [Hash] The verification result of subentities serialized to a hash
75
- def subentities_to_hash(verbose,level)
76
- hash = Hash.new
77
- @subentities.each do |s|
78
- hash[s.entity] = s.to_hash(verbose, level+1)
79
- end
80
- hash
69
+ def subentities_to_hash(verbose, level)
70
+ subentities.map { |s| [s.entity, s.to_hash(verbose, level + 1)] }.to_h
81
71
  end
82
-
83
72
  end
84
73
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # The descriptive information about a digital object's collection of versions
6
5
  #
7
6
  # ====Data Model
@@ -13,14 +12,13 @@ module Moab
13
12
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
14
13
  # All rights reserved. See {file:LICENSE.rdoc} for details.
15
14
  class VersionMetadata < Serializer::Manifest
16
-
17
15
  include HappyMapper
18
16
 
19
17
  # The name of the XML element used to serialize this objects data
20
18
  tag 'versionMetadata'
21
19
 
22
20
  # (see Serializable#initialize)
23
- def initialize(opts={})
21
+ def initialize(opts = {})
24
22
  @versions = Array.new
25
23
  super(opts)
26
24
  end
@@ -32,7 +30,5 @@ module Moab
32
30
  # @attribute
33
31
  # @return [Array<VersionMetadataEntry>] An array of version metadata entries, one per version
34
32
  has_many :versions, VersionMetadataEntry, :tag => 'version'
35
-
36
33
  end
37
-
38
34
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # The descriptive attributes of a digital object version.
6
5
  #
7
6
  # ====Data Model
@@ -12,21 +11,20 @@ module Moab
12
11
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
13
12
  # All rights reserved. See {file:LICENSE.rdoc} for details.
14
13
  class VersionMetadataEntry < Serializer::Serializable
15
-
16
14
  include HappyMapper
17
15
 
18
16
  # The name of the XML element used to serialize this objects data
19
17
  tag 'version'
20
18
 
21
19
  # (see Serializable#initialize)
22
- def initialize(opts={})
20
+ def initialize(opts = {})
23
21
  @events = Array.new
24
22
  super(opts)
25
23
  end
26
24
 
27
25
  # @attribute
28
26
  # @return [Integer] The object version number (A sequential integer)
29
- attribute :version_id, Integer, :tag => 'versionId', :key => true, :on_save => Proc.new {|n| n.to_s}
27
+ attribute :version_id, Integer, :tag => 'versionId', :key => true, :on_save => Proc.new { |n| n.to_s }
30
28
 
31
29
  # @attribute
32
30
  # @return [String] "an external version label that increments the most significant digit for major revisions,
@@ -57,7 +55,5 @@ module Moab
57
55
  # @attribute
58
56
  # @return [Array<VersionMetadataEvent>] Array of events with timestamps that track lifecycle stages
59
57
  has_many :events, VersionMetadataEvent, :tag => 'event'
60
-
61
58
  end
62
-
63
59
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # A container element to record object version lifecycle events with timestamps
6
5
  #
7
6
  # ====Data Model
@@ -14,14 +13,13 @@ module Moab
14
13
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
15
14
  # All rights reserved. See {file:LICENSE.rdoc} for details.
16
15
  class VersionMetadataEvent < Serializer::Serializable
17
-
18
16
  include HappyMapper
19
17
 
20
18
  # The name of the XML element used to serialize this objects data
21
19
  tag 'event'
22
20
 
23
21
  # (see Serializable#initialize)
24
- def initialize(opts={})
22
+ def initialize(opts = {})
25
23
  super(opts)
26
24
  end
27
25
 
@@ -29,19 +27,16 @@ module Moab
29
27
  # @return [String] The type of event
30
28
  attribute :type, String
31
29
 
32
-
33
30
  # @attribute
34
31
  # @return [String] The date and time of an event
35
32
  attribute :datetime, String
36
33
 
37
34
  def datetime=(event_datetime)
38
- @datetime=Moab::UtcTime.input(event_datetime)
35
+ @datetime = Moab::UtcTime.input(event_datetime)
39
36
  end
40
37
 
41
38
  def datetime
42
39
  Moab::UtcTime.output(@datetime)
43
40
  end
44
-
45
41
  end
46
-
47
42
  end