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
|
# File 'backend/app/model/idlookup.rb', line 3
def find_by_ids(model, params)
filters = {}
params.each do |key, values|
next if Array(values).empty?
key = key.intern
next if [:repo_id, :resolve].include?(key)
if key == :identifier
identifiers = Array(values).map {|identifier|
parsed = ASUtils.json_parse(identifier)
if parsed.is_a?(Array) && parsed.length > 0 && parsed.length <= 4
padded = (parsed + ([nil] * 3)).take(4)
ASUtils.to_json(padded)
end
}.compact
filters[key] = Array(identifiers)
elsif key == :ark
fk_col = :"#{model.table_name}_id"
filters[:id] = ArkName.filter(:ark_value => values).map(fk_col)
else
filters[key] = Array(values)
end
end
return [] if filters.empty?
model.this_repo.where(filters).select(:id).map {|record|
{'ref' => record.uri}
}
end
|