Class: Dor::RoleMetadataDS

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Includes:
SolrDocHelper
Defined in:
lib/dor/datastreams/role_metadata_ds.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SolrDocHelper

#add_solr_value

Class Method Details

.xml_templateObject



31
32
33
34
35
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 31

def self.xml_template
  Nokogiri::XML::Builder.new do |xml|
    xml. {}
  end.doc
end

Instance Method Details

#add_roleplayer(role, entity, type = :workgroup) ⇒ Object

Adds a person or group to a role in the APO role metadata datastream

Parameters:

  • role (String)

    the role the group or person will be filed under, ex. dor-apo-manager

  • entity (String)

    the name of the person or group, ex dlss:developers or sunetid:someone

  • type (Symbol) (defaults to: :workgroup)

    :workgroup for a group or :person for a person



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 53

def add_roleplayer(role, entity, type = :workgroup)
  xml = ng_xml
  ng_xml_will_change!
  group = type == :workgroup ? 'group' : 'person'
  nodes = xml.search('/roleMetadata/role[@type=\'' + role + '\']')
  if nodes.length > 0
    group_node = Nokogiri::XML::Node.new(group, xml)
    id_node = Nokogiri::XML::Node.new('identifier', xml)
    group_node.add_child(id_node)
    id_node.content = entity
    id_node['type'] = type.to_s
    nodes.first.add_child(group_node)
  else
    node = Nokogiri::XML::Node.new('role', xml)
    node['type'] = role
    group_node = Nokogiri::XML::Node.new(group, xml)
    node.add_child group_node
    id_node = Nokogiri::XML::Node.new('identifier', xml)
    group_node.add_child(id_node)
    id_node.content = entity
    id_node['type'] = type.to_s
    xml.search('/roleMetadata').first.add_child(node)
  end
end

#prefixObject

maintain AF < 8 indexing behavior



97
98
99
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 97

def prefix
  ''
end

#purge_rolesObject

remove all people groups and roles from the APO role metadata datastream



79
80
81
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 79

def purge_roles
  ng_xml.search('/roleMetadata/role').each(&:remove)
end

#rolesHash

Get all roles defined in the role metadata, and the people or groups in those roles. Groups are prefixed with ‘workgroup:’

Returns:

  • (Hash)

    role => [‘person’,‘group’] ex. {“dor-apo-manager” => [“workgroup:dlss:developers”, “sunetid:lmcrae”]



85
86
87
88
89
90
91
92
93
94
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 85

def roles
  {}.tap do |roles|
    ng_xml.search('/roleMetadata/role').each do |role|
      roles[role['type']] = []
      role.search('identifier').each do |entity|
        roles[role['type']] << entity['type'] + ':' + entity.text
      end
    end
  end
end

#to_solr(solr_doc = {}, *_args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/dor/datastreams/role_metadata_ds.rb', line 37

def to_solr(solr_doc = {}, *_args)
  find_by_xpath('/roleMetadata/role/*').each do |actor|
    role_type = actor.parent['type']
    val = [actor.at_xpath('identifier/@type'), actor.at_xpath('identifier/text()')].join ':'
    add_solr_value(solr_doc, "apo_role_#{actor.name}_#{role_type}", val, :string, [:symbol])
    add_solr_value(solr_doc, "apo_role_#{role_type}", val, :string, [:symbol])
    add_solr_value(solr_doc, 'apo_register_permissions', val, :string, %i[symbol stored_searchable]) if ['dor-apo-manager', 'dor-apo-depositor'].include? role_type
  end
  solr_doc
end