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



42
43
44
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 42

def to_oai_dc
  OAIDCMapper.new.map_oai_record(self)
end

#to_oai_dctermsObject



46
47
48
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 46

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
# 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 = ASpaceExport.model(:marc21).from_resource(@jsonmodel_record)
    remove_xml_declaration(ASpaceExport::serialize(marc))
  end
end

#to_oai_modsObject



50
51
52
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 50

def to_oai_mods
  OAIMODSMapper.new.map_oai_record(self)
end

#updated_atObject



54
55
56
# File 'backend/app/lib/oai/aspace_oai_record.rb', line 54

def updated_at
  @sequel_record.system_mtime
end