Class: ArchivesSpaceResumptionToken
- Inherits:
-
Object
- Object
- ArchivesSpaceResumptionToken
- Defined in:
- backend/app/lib/oai/aspace_resumption_token.rb
Constant Summary collapse
- PRODUCING_RECORDS_STATE =
'producing_records'
- PRODUCING_DELETES_STATE =
'producing_deletes'
Class Method Summary collapse
Instance Method Summary collapse
-
#any_records_left? ⇒ Boolean
-
#format ⇒ Object
-
#from ⇒ Object
-
#initialize(options, available_record_types) ⇒ ArchivesSpaceResumptionToken
constructor
A new instance of ArchivesSpaceResumptionToken.
-
#last_delete_id ⇒ Object
-
#last_delete_id=(value) ⇒ Object
-
#remaining_types ⇒ Object
-
#serialize ⇒ Object
-
#set ⇒ Object
-
#set_last_seen(oai_record) ⇒ Object
-
#start_deletes! ⇒ Object
-
#state ⇒ Object
-
#to_xml ⇒ Object
-
#until ⇒ Object
-
#update_depleted(types) ⇒ Object
Constructor Details
#initialize(options, available_record_types) ⇒ ArchivesSpaceResumptionToken
Returns a new instance of ArchivesSpaceResumptionToken.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 6 def initialize(, available_record_types) = Hash[.map {|k, v| [k.to_s, v]}] ['state'] ||= PRODUCING_RECORDS_STATE ['last_delete_id'] ||= 0 unless .has_key?('remaining_types') types_for_format = available_record_types.fetch(format) { raise OAI::FormatException.new } ['remaining_types'] = Hash[types_for_format.record_types.map {|type| [type.to_s, 0]}] end end |
Class Method Details
.extract_format(token) ⇒ Object
18 19 20 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 18 def self.extract_format(token) self.parse(token, {}).format end |
.parse(token, available_record_types) ⇒ Object
83 84 85 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 83 def self.parse(token, available_record_types) new(ASUtils.json_parse(Base64::urlsafe_decode64(token)), available_record_types) end |
Instance Method Details
#any_records_left? ⇒ Boolean
66 67 68 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 66 def any_records_left? !remaining_types.empty? end |
#format ⇒ Object
38 39 40 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 38 def format .fetch('metadata_prefix') end |
#from ⇒ Object
46 47 48 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 46 def from .fetch('from', nil) end |
#last_delete_id ⇒ Object
30 31 32 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 30 def last_delete_id .fetch('last_delete_id') end |
#last_delete_id=(value) ⇒ Object
34 35 36 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 34 def last_delete_id=(value) ['last_delete_id'] = value end |
#remaining_types ⇒ Object
54 55 56 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 54 def remaining_types .fetch('remaining_types').sort_by {|type, _| type} end |
#serialize ⇒ Object
87 88 89 90 91 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 87 def serialize issue_time = (Time.now.to_f * 1000).to_i Base64::urlsafe_encode64(.merge('issue_time' => issue_time).to_json) end |
#set ⇒ Object
42 43 44 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 42 def set .fetch('set', nil) end |
#set_last_seen(oai_record) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 70 def set_last_seen(oai_record) return self unless oai_record aspace_record = oai_record.sequel_record # We've already depleted this record type return self unless ['remaining_types'].has_key?(aspace_record.class.to_s) ['remaining_types'][aspace_record.class.to_s] = aspace_record.id self end |
#start_deletes! ⇒ Object
26 27 28 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 26 def start_deletes! ['state'] = PRODUCING_DELETES_STATE end |
#state ⇒ Object
22 23 24 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 22 def state .fetch('state') end |
#to_xml ⇒ Object
93 94 95 96 97 98 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 93 def to_xml xml = Builder::XmlMarkup.new xml.resumptionToken(self.serialize) xml.target! end |
#until ⇒ Object
50 51 52 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 50 def until .fetch('until', nil) end |
#update_depleted(types) ⇒ Object
58 59 60 61 62 63 64 |
# File 'backend/app/lib/oai/aspace_resumption_token.rb', line 58 def update_depleted(types) types.each do |depleted_type| ['remaining_types'].delete(depleted_type) end self end |