Module: AgentNames::ClassMethods

Defined in:
backend/app/model/mixins/agent_names.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) apply_authority_id(obj, json)



51
52
53
54
55
56
57
58
59
60
# File 'backend/app/model/mixins/agent_names.rb', line 51

def apply_authority_id(obj, json)
  obj.name_authority_id_dataset.delete

  if json['authority_id']
    obj.name_authority_id = NameAuthorityId.create(:authority_id => json['authority_id'],
                                                   :lock_version => 0)
  end

  obj
end

- (Object) assemble_hash_fields(json)



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
# File 'backend/app/model/mixins/agent_names.rb', line 82

def assemble_hash_fields(json)
  name = my_jsonmodel.from_hash(json)
  hash_fields = []
  name_fields = %w(dates qualifier source rules) + type_specific_hash_fields

  name['use_dates'].each do |date|
    hash_fields << [:date_type,
                    :label, 
                    :certainty,
                    :expression, 
                    :begin, 
                    :end, 
                    :era, 
                    :calendar].map {|property|
      date[property.to_s] || ' '
    }.join('_')
  end


  hash_fields << name_fields.uniq.map {|property|
    if !name[property]
      ' '
    elsif name.class.schema["properties"][property]["dynamic_enum"]
      enum = name.class.schema["properties"][property]["dynamic_enum"]
      BackendEnumSource.id_for_value(enum, name[property])
    else
      name[property.to_s]
    end
  }.join('_')

  hash_fields

end

- (Object) calculate_object_graph(object_graph, opts = {})



38
39
40
41
42
43
44
45
46
47
48
# File 'backend/app/model/mixins/agent_names.rb', line 38

def calculate_object_graph(object_graph, opts = {})
  super

  # Add the rows for authority IDs too
  column = "#{self.table_name}_id".intern

  ids = NameAuthorityId.filter(column => object_graph.ids_for(self)).
                        map {|row| row[:id]}

  object_graph.add_objects(NameAuthorityId, ids)
end

- (Object) create_from_json(json, opts = {})



63
64
65
66
# File 'backend/app/model/mixins/agent_names.rb', line 63

def create_from_json(json, opts = {})
  obj = super
  apply_authority_id(obj, json)
end

- (Object) sequel_to_jsonmodel(objs, opts = {})



69
70
71
72
73
74
75
76
77
78
79
# File 'backend/app/model/mixins/agent_names.rb', line 69

def sequel_to_jsonmodel(objs, opts = {})
  jsons = super

  jsons.zip(objs).each do |json, obj|
    if obj.name_authority_id
      json['authority_id'] = obj.name_authority_id.authority_id
    end
  end

  jsons
end