Class: Replication::Replica

Inherits:
Object
  • Object
show all
Defined in:
lib/replication/replica.rb

Overview

Note:

Copyright © 2014 by The Board of Trustees of the Leland Stanford Junior University. All rights reserved. See LICENSE for details.

The metadata concerning the digital object/version that is the subject of replication.

Constant Summary collapse

@@replica_cache_pathname =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(replica_id, home_repository) ⇒ Replica

Returns Initialize a new Replica object.

Parameters:

  • replica_id (String)

    The unique identifier for the digital object replica

  • home_repository (String)

    The original home location of the replica (sdr or dpn)



49
50
51
52
# File 'lib/replication/replica.rb', line 49

def initialize(replica_id, home_repository)
  @replica_id = replica_id
  @home_repository = home_repository
end

Instance Attribute Details

#bagit_bagBagitBag

Returns A bag containing a copy of the replica.

Returns:

  • (BagitBag)

    A bag containing a copy of the replica



35
36
37
# File 'lib/replication/replica.rb', line 35

def bagit_bag
  @bagit_bag
end

#create_dateTime

Returns The timestamp of the datetime at which the replica was created.

Returns:

  • (Time)

    The timestamp of the datetime at which the replica was created



32
33
34
# File 'lib/replication/replica.rb', line 32

def create_date
  @create_date
end

#home_repositoryString

Returns The original home location of the replica (sdr or dpn).

Returns:

  • (String)

    The original home location of the replica (sdr or dpn)



29
30
31
# File 'lib/replication/replica.rb', line 29

def home_repository
  @home_repository
end

#payload_fixityString

Returns The value of the checksum/digest.

Returns:

  • (String)

    The value of the checksum/digest



44
45
46
# File 'lib/replication/replica.rb', line 44

def payload_fixity
  @payload_fixity
end

#payload_fixity_typeString

Returns The type of checksum/digest type (:sha1, :sha256).

Returns:

  • (String)

    The type of checksum/digest type (:sha1, :sha256)



41
42
43
# File 'lib/replication/replica.rb', line 41

def payload_fixity_type
  @payload_fixity_type
end

#payload_sizeInteger

Returns The size (in bytes) of the replic bag’s payload.

Returns:

  • (Integer)

    The size (in bytes) of the replic bag’s payload



38
39
40
# File 'lib/replication/replica.rb', line 38

def payload_size
  @payload_size
end

#replica_idString

Returns The unique identifier for the digital object replica.

Returns:

  • (String)

    The unique identifier for the digital object replica



26
27
28
# File 'lib/replication/replica.rb', line 26

def replica_id
  @replica_id
end

Class Method Details

.replica_cache_pathnamePathname

Returns The base location of the replica cache.

Returns:

  • (Pathname)

    The base location of the replica cache



15
16
17
# File 'lib/replication/replica.rb', line 15

def Replica.replica_cache_pathname
  @@replica_cache_pathname
end

.replica_cache_pathname=(replica_cache_pathname) ⇒ Pathname

Returns Set the base location of the replica cache.

Parameters:

  • replica_cache_pathname (Pathname, String)

    The base location of the replica cache

Returns:

  • (Pathname)

    Set the base location of the replica cache



21
22
23
# File 'lib/replication/replica.rb', line 21

def Replica.replica_cache_pathname=(replica_cache_pathname)
  @@replica_cache_pathname = Pathname(replica_cache_pathname)
end

Instance Method Details

#bag_pathnamePathname

Returns The location of the replica bag.

Returns:

  • (Pathname)

    The location of the replica bag



55
56
57
# File 'lib/replication/replica.rb', line 55

def bag_pathname
  @@replica_cache_pathname.join(@home_repository,@replica_id)
end

#catalog_replica_dataBoolean

Returns Update the replicas table of the Archive Catalog.

Returns:

  • (Boolean)

    Update the replicas table of the Archive Catalog



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/replication/replica.rb', line 74

def catalog_replica_data
  replica_data = {
      :replica_id => @replica_id,
      :home_repository => @home_repository,
      :create_date => @create_date,
      :payload_size => @payload_size,
      :payload_fixity_type => @payload_fixity_type,
      :payload_fixity => @payload_fixity
  }
  ArchiveCatalog.add_or_update_item(:replicas, replica_data)
  true
end

#get_bag_dataReplica

Returns Open the replica’s bag and extract its properties.

Returns:

  • (Replica)

    Open the replica’s bag and extract its properties



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/replication/replica.rb', line 60

def get_bag_data
  bag = BagitBag.open_bag(bag_pathname)
  @create_date = UtcTime.output(bag_pathname.ctime)
  size_hash = bag.info_payload_size
  @payload_size = size_hash[:bytes]
  file_fixity_hash = bag.read_manifest_files('manifest')
  tarfile_fixity = file_fixity_hash.values.first
  checksums = tarfile_fixity.checksums
  @payload_fixity_type = checksums.keys.last.to_s
  @payload_fixity = checksums[@payload_fixity_type.to_sym]
  self
end