Class: ArchivesSpaceOAIRecord

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/oai/aspace_oai_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequel_record, jsonmodel_record) ⇒ ArchivesSpaceOAIRecord

Returns a new instance of ArchivesSpaceOAIRecord.



9
10
11
12
13
14
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 9

def initialize(sequel_record, jsonmodel_record)
  @jsonmodel_record = jsonmodel_record

  JSONModel::set_publish_flags!(@jsonmodel_record)
  @sequel_record = sequel_record
end

Instance Attribute Details

#jsonmodel_recordObject (readonly)

Returns the value of attribute jsonmodel_record



7
8
9
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 7

def jsonmodel_record
  @jsonmodel_record
end

#sequel_recordObject (readonly)

Returns the value of attribute sequel_record



7
8
9
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 7

def sequel_record
  @sequel_record
end

Instance Method Details

#idObject



16
17
18
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 16

def id
  @jsonmodel_record.uri
end

#to_oai_dcObject



48
49
50
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 48

def to_oai_dc
  OAIDCMapper.new.map_oai_record(self)
end

#to_oai_dctermsObject



52
53
54
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 52

def to_oai_dcterms
  OAIDCTermsMapper.new.map_oai_record(self)
end

#to_oai_eadObject

Raises:

  • (OAI::FormatException)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 20

def to_oai_ead
  raise OAI::FormatException.new unless @jsonmodel_record['jsonmodel_type'] == 'resource'

  RequestContext.open(:repo_id => @sequel_record.repo_id) do
    ead = ASpaceExport.model(:ead).from_resource(@jsonmodel_record, @sequel_record.tree(:all, mode = :sparse), AppConfig[:oai_ead_options])

    record = []
    ASpaceExport::stream(ead).each do |chunk|
      record << chunk
    end

    remove_xml_declaration(record.join(""))
  end
end

#to_oai_marcObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 35

def to_oai_marc
  RequestContext.open(:repo_id => @sequel_record.repo_id) do
    marc = if @jsonmodel_record['jsonmodel_type'] == 'resource'
             ASpaceExport.model(:marc21).from_resource(@jsonmodel_record)
           elsif @jsonmodel_record['jsonmodel_type'] == 'archival_object'
             ASpaceExport.model(:marc21).from_archival_object(@jsonmodel_record)
           else
             raise OAI::FormatException.new
           end
    remove_xml_declaration(ASpaceExport::serialize(marc))
  end
end

#to_oai_modsObject



56
57
58
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 56

def to_oai_mods
  OAIMODSMapper.new.map_oai_record(self)
end

#updated_atObject



60
61
62
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 60

def updated_at
  @sequel_record.system_mtime
end