Class: ROF::Ingesters::RightsMetadataIngester

Inherits:
Object
  • Object
show all
Defined in:
lib/rof/ingesters/rights_metadata_ingester.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ RightsMetadataIngester

Returns a new instance of RightsMetadataIngester.



9
10
11
12
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 9

def initialize(attributes = {})
  @item = attributes.fetch(:item)
  @fdoc = attributes.fetch(:fedora_document, nil)
end

Instance Attribute Details

#fdocObject (readonly)

Returns the value of attribute fdoc.



8
9
10
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 8

def fdoc
  @fdoc
end

#itemObject (readonly)

Returns the value of attribute item.



8
9
10
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 8

def item
  @item
end

Class Method Details

.call(attributes) ⇒ Object



4
5
6
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 4

def self.call(attributes)
  new(attributes).call
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 14

def call
  rights = item["rights"]
  return if rights.nil?
  #
  # we really should be building this using an xml engine.
  #
  content = %Q{<rightsMetadata xmlns="http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1" version="0.1">\n}
  # TODO(dbrower): Does the copyright need to be exposed in the rof?
  content += %Q{  <copyright>\n    <human type="title"/>\n    <human type="description"/>\n    <machine type="uri"/>\n  </copyright>\n}
  content += format_rights_section("discover", rights["discover"], rights["discover-groups"])
  content += format_rights_section("read", rights["read"], rights["read-groups"])
  content += format_rights_section("edit", rights["edit"], rights["edit-groups"])
  # TODO(dbrower): expose embargo information
  content += %Q{  <embargo>\n    <human/>\n}
  if rights["embargo-date"]
    content += %Q{    <machine>\n}
    content += %Q{      <date>#{rights["embargo-date"]}</date>\n}
    content += %Q{    </machine>\n}
  else
    content += %Q{    <machine/>\n}
  end
  content += %Q{  </embargo>\n}
  content += %Q{</rightsMetadata>\n}

  if fdoc
    ds = fdoc['rightsMetadata']
    ds.mimeType = 'text/xml'
    ds.content = content
    ds.save
  end
  content
end

#format_rights_section(section_name, people, groups) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rof/ingesters/rights_metadata_ingester.rb', line 47

def format_rights_section(section_name, people, groups)
  people = [people] if people.is_a? String
  groups = [groups] if groups.is_a? String
  result = "  <access type=\"#{section_name}\">\n    <human/>\n"
  if people || groups
    result += "    <machine>\n"
    (people || []).each do |person|
      result += "      <person>#{person}</person>\n"
    end
    (groups || []).each do |group|
      result += "      <group>#{group}</group>\n"
    end
    result += "    </machine>\n"
  else
    result += "    <machine/>\n"
  end
  result += "  </access>\n"
  result
end