Class: AgentPerson

Inherits:
Record show all
Defined in:
backend/app/model/agent_person.rb,
public/app/models/agent_person.rb

Constant Summary

Constants inherited from Record

Record::ABSTRACT

Instance Attribute Summary

Attributes inherited from Record

#agents, #classifications, #container_display, #container_summary_for_badge, #container_titles_and_uris, #criteria, #dates, #display_string, #extents, #external_documents, #full, #highlights, #identifier, #json, #lang_materials, #level, #linked_digital_objects, #notes, #other_level, #primary_type, #raw, #repository_information, #resolved_repository, #resolved_resource, #resolved_top_container, #subjects, #uri

Instance Method Summary collapse

Methods inherited from Record

#[], #apply_highlighting, #dig, #initialize, #note, #parse_full_title, #request_item

Constructor Details

This class inherits a constructor from Record

Instance Method Details

#deleteObject



39
40
41
42
43
44
45
# File 'backend/app/model/agent_person.rb', line 39

def delete
  if User.filter(:agent_record_id => self.id).count > 0
    raise ConflictException.new("linked_to_user")
  else
    super
  end
end

#metadataObject



3
4
5
6
7
8
9
10
11
12
13
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'public/app/models/agent_person.rb', line 3

def 
  md = {
    '@context' => "http://schema.org/",
    '@type' => 'Person',
    '@id' => AppConfig[:public_proxy_url] + uri,
    'name' => json['display_name']['sort_name'],
    'sameAs' => raw['authority_id'],
    'alternateName' => json['names'].select {|n| !n['is_display_name']}.map {|n| n['sort_name']}
  }

  if (dates = json['dates_of_existence'].first)
    md['birthDate'] = dates['begin'] if dates['begin']
    md['deathDate'] = dates['end'] if dates['end']
  end

  md['description'] = json['notes'].select {|n| n['jsonmodel_type'] == 'note_bioghist'}.map {|note|
                        strip_mixed_content(note['subnotes'].map {|s| s['content']}.join(' '))
                      }
  md['description'] = md['description'][0] if md['description'].length == 1

  md['knows'] = json['related_agents'].select {|ra|
    ra['relator'] == 'is_associative_with' && ra['_resolved']['jsonmodel_type'] == json['jsonmodel_type']}.map do |ag|
    res = ag['_resolved']

    out = {}
    out['@id'] = res['display_name']['authority_id'] if res['display_name']['authority_id']
    out['name'] = res['display_name']['sort_name']
    out['url'] = AppConfig[:public_proxy_url] + res['uri']

    knows = {}

    if ag['dates']
      knows['startDate'] = ag['dates']['begin'] if ag['dates']['begin']
      knows['endDate'] = ag['dates']['end'] if ag['dates']['end']
    end

    knows['description'] = ag['description'] if ag['description']
    knows['@type'] = 'Role' unless knows.empty?

    out['knows'] = knows unless knows.empty?

    out
  end

  md['parent'] = json['related_agents'].select {|ra| ra['relator'] == 'is_child_of'}.map do |ag|
    res = ag['_resolved']
    out = {}
    out['@id'] = res['display_name']['authority_id'] if res['display_name']['authority_id']
    out['name'] = res['display_name']['sort_name']
    out['url'] = AppConfig[:public_proxy_url] + res['uri']

    out
  end

  md['children'] = json['related_agents'].select {|ra| ra['relator'] == 'is_parent_of'}.map do |ag|
    res = ag['_resolved']
    out = {}
    out['@id'] = res['display_name']['authority_id'] if res['display_name']['authority_id']
    out['name'] = res['display_name']['sort_name']
    out['url'] = AppConfig[:public_proxy_url] + res['uri']

    out
  end

  md['affiliation'] = json['related_agents'].select {|ra|
    ra['relator'] == 'is_associative_with' && ra['_resolved']['jsonmodel_type'] != json['jsonmodel_type']}.map do |ag|
    res = ag['_resolved']
    out = {}
    out['@id'] = res['display_name']['authority_id'] if res['display_name']['authority_id']
    out['name'] = res['display_name']['sort_name']
    out['url'] = AppConfig[:public_proxy_url] + res['uri']

    out
  end

  md.compact.delete_if { |key, value| value.empty? }
end


82
83
84
85
86
# File 'public/app/models/agent_person.rb', line 82

def related_agents
  ASUtils.wrap(json['related_agents']).select {|rel|
    rel['_resolved']['publish']
  }
end