Class: LargeTreeResource

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/large_tree_resource.rb

Instance Method Summary collapse

Instance Method Details

#node(response, node_record) ⇒ Object



46
47
48
49
# File 'backend/app/model/large_tree_resource.rb', line 46

def node(response, node_record)
  response['identifier'] = node_record.component_id
  response
end

#root(response, root_record) ⇒ Object



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
# File 'backend/app/model/large_tree_resource.rb', line 3

def root(response, root_record)
  response['level'] = root_record.other_level || root_record.level
  response['identifier'] = (0...4).map {|i| root_record["id_#{i}".to_sym]}.compact.join("-")

  # Collect all container data
  Instance
    .left_join(:sub_container, :sub_container__instance_id => :instance__id)
    .left_join(:top_container_link_rlshp, :sub_container_id => :sub_container__id)
    .left_join(:top_container, :id => :top_container_link_rlshp__top_container_id)
    .left_join(Sequel.as(:enumeration_value, :top_container_type), :id => :top_container__type_id)
    .left_join(Sequel.as(:enumeration_value, :type_2), :id => :sub_container__type_2_id)
    .left_join(Sequel.as(:enumeration_value, :type_3), :id => :sub_container__type_3_id)
    .left_join(Sequel.as(:enumeration_value, :instance_type), :id => :instance__instance_type_id)
    .filter(:resource_id => root_record.id)
    .select(Sequel.as(:instance_type__value, :instance_type),
            Sequel.as(:top_container_type__value, :top_container_type),
            Sequel.as(:top_container__indicator, :top_container_indicator),
            Sequel.as(:top_container__barcode, :top_container_barcode),
            Sequel.as(:type_2__value, :type_2),
            Sequel.as(:sub_container__indicator_2, :indicator_2),
            Sequel.as(:sub_container__barcode_2, :barcode_2),
            Sequel.as(:type_3__value, :type_3),
            Sequel.as(:sub_container__indicator_3, :indicator_3))
  .each do |row|
    response['containers'] ||= []

    container_data = {}
    container_data['instance_type'] = row[:instance_type] if row[:instance_type]
    container_data['top_container_type'] = row[:top_container_type] if row[:top_container_type]
    container_data['top_container_indicator'] = row[:top_container_indicator] if row[:top_container_indicator]
    container_data['top_container_barcode'] = row[:top_container_barcode] if row[:top_container_barcode]
    container_data['type_2'] = row[:type_2] if row[:type_2]
    container_data['indicator_2'] = row[:indicator_2] if row[:indicator_2]
    container_data['barcode_2'] = row[:barcode_2] if row[:barcode_2]
    container_data['type_3'] = row[:type_3] if row[:type_3]
    container_data['indicator_3'] = row[:indicator_3] if row[:indicator_3]

    response['containers'] << container_data
  end

  response
end

#waypoint(response, record_ids) ⇒ Object



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'backend/app/model/large_tree_resource.rb', line 51

def waypoint(response, record_ids)
  # Load the instance type and record level
  ArchivalObject
    .left_join(Sequel.as(:enumeration_value, :level_enum), :id => :archival_object__level_id)
    .filter(:archival_object__id => record_ids)
    .select(Sequel.as(:archival_object__id, :id),
            Sequel.as(:archival_object__component_id, :component_id),
            Sequel.as(:level_enum__value, :level),
            Sequel.as(:archival_object__other_level, :other_level))
    .each do |row|
    id = row[:id]
    result_for_record = response.fetch(record_ids.index(id))

    result_for_record['identifier'] = row[:component_id]
    result_for_record['level'] = row[:other_level] || row[:level]
  end

  ASDate
    .left_join(Sequel.as(:enumeration_value, :date_type), :id => :date__date_type_id)
    .left_join(Sequel.as(:enumeration_value, :date_label), :id => :date__label_id)
    .filter(:archival_object_id => record_ids)
    .select(:archival_object_id,
            Sequel.as(:date_type__value, :type),
            Sequel.as(:date_label__value, :label),
            :expression,
            :begin,
            :end)
    .each do |row|

    id = row[:archival_object_id]

    result_for_record = response.fetch(record_ids.index(id))
    result_for_record['dates'] ||= []

    date_data = {}
    date_data['type'] = row[:type] if row[:type]
    date_data['label'] = row[:label] if row[:label]
    date_data['expression'] = row[:expression] if row[:expression]
    date_data['begin'] = row[:begin] if row[:begin]
    date_data['end'] = row[:end] if row[:end]

    result_for_record['dates'] << date_data
  end

  # Display container information
  Instance
    .left_join(:sub_container, :sub_container__instance_id => :instance__id)
    .left_join(:top_container_link_rlshp, :sub_container_id => :sub_container__id)
    .left_join(:top_container, :id => :top_container_link_rlshp__top_container_id)
    .left_join(Sequel.as(:enumeration_value, :top_container_type), :id => :top_container__type_id)
    .left_join(Sequel.as(:enumeration_value, :type_2), :id => :sub_container__type_2_id)
    .left_join(Sequel.as(:enumeration_value, :type_3), :id => :sub_container__type_3_id)
    .left_join(Sequel.as(:enumeration_value, :instance_type), :id => :instance__instance_type_id)
    .filter(:archival_object_id => record_ids)
    .select(:archival_object_id,
            Sequel.as(:instance_type__value, :instance_type),
            Sequel.as(:top_container_type__value, :top_container_type),
            Sequel.as(:top_container__indicator, :top_container_indicator),
            Sequel.as(:top_container__barcode, :top_container_barcode),
            Sequel.as(:type_2__value, :type_2),
            Sequel.as(:sub_container__indicator_2, :indicator_2),
            Sequel.as(:sub_container__barcode_2, :barcode_2),
            Sequel.as(:type_3__value, :type_3),
            Sequel.as(:sub_container__indicator_3, :indicator_3))
    .each do |row|
    id = row[:archival_object_id]

    result_for_record = response.fetch(record_ids.index(id))
    result_for_record['containers'] ||= []

    container_data = {}
    container_data['instance_type'] = row[:instance_type] if row[:instance_type]
    container_data['top_container_type'] = row[:top_container_type] if row[:top_container_type]
    container_data['top_container_indicator'] = row[:top_container_indicator] if row[:top_container_indicator]
    container_data['top_container_barcode'] = row[:top_container_barcode] if row[:top_container_barcode]
    container_data['type_2'] = row[:type_2] if row[:type_2]
    container_data['indicator_2'] = row[:indicator_2] if row[:indicator_2]
    container_data['barcode_2'] = row[:barcode_2] if row[:barcode_2]
    container_data['type_3'] = row[:type_3] if row[:type_3]
    container_data['indicator_3'] = row[:indicator_3] if row[:indicator_3]

    result_for_record['containers'] << container_data
  end

  response
end