Skip to content

Commit

Permalink
make sure repeatable DOI fields are always an array in the API. datac…
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 17, 2020
1 parent e35244b commit c5bc107
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def self.query_fields

def self.query_aggregations
{
years: { date_histogram: { field: 'created', interval: 'year', format: 'year', min_doc_count: 1 } },
years: { date_histogram: { field: 'created', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 },
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } },
cumulative_years: { terms: { field: 'cumulative_years', size: 15, min_doc_count: 1, order: { _count: "asc" } } },
providers: { terms: { field: 'provider_id', size: 15, min_doc_count: 1 } },
software: { terms: { field: 'software.keyword', size: 15, min_doc_count: 1 } },
Expand Down
3 changes: 2 additions & 1 deletion app/models/client_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def as_indexed_json(options={})

def self.query_aggregations
{
years: { date_histogram: { field: "created_at", interval: "year", min_doc_count: 1 } },
years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 },
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } },
providers: { terms: { field: "provider_id", size: 15, min_doc_count: 1 } },
clients: { terms: { field: "client_id", size: 15, min_doc_count: 1 } },
}
Expand Down
28 changes: 28 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,34 @@ def sizes=(value)
write_attribute(:sizes, Array.wrap(value))
end

def dates=(value)
write_attribute(:dates, Array.wrap(value))
end

def subjects=(value)
write_attribute(:subjects, Array.wrap(value))
end

def rights_list=(value)
write_attribute(:rights_list, Array.wrap(value))
end

def identifiers=(value)
write_attribute(:identifiers, Array.wrap(value))
end

def related_identifiers=(value)
write_attribute(:related_identifiers, Array.wrap(value))
end

def funding_references=(value)
write_attribute(:funding_references, Array.wrap(value))
end

def geo_locations=(value)
write_attribute(:geo_locations, Array.wrap(value))
end

def content_url=(value)
write_attribute(:content_url, Array.wrap(value))
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def as_indexed_json(options={})
def self.query_aggregations
{
states: { terms: { field: 'state', size: 3, min_doc_count: 1 } },
years: { date_histogram: { field: 'created_at', interval: 'year', min_doc_count: 1 } },
years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 },
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } },
providers: { terms: { field: 'provider_ids', size: 15, min_doc_count: 1 } },
clients: { terms: { field: 'client_ids', size: 15, min_doc_count: 1 } },
}
Expand Down
3 changes: 2 additions & 1 deletion app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ def self.query_fields

def self.query_aggregations
{
years: { date_histogram: { field: 'created', interval: 'year', format: 'year', min_doc_count: 1 } },
years: { date_histogram: { field: 'created', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 },
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } },
cumulative_years: { terms: { field: 'cumulative_years', size: 15, min_doc_count: 1, order: { _count: "asc" } } },
regions: { terms: { field: 'region', size: 10, min_doc_count: 1 } },
member_types: { terms: { field: 'member_type', size: 10, min_doc_count: 1 } },
Expand Down
3 changes: 2 additions & 1 deletion app/models/provider_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def as_indexed_json(options={})
def self.query_aggregations
{
states: { terms: { field: 'state', size: 2, min_doc_count: 1 } },
years: { date_histogram: { field: 'created_at', interval: 'year', min_doc_count: 1 } },
years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 },
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } },
providers: { terms: { field: 'provider_id', size: 15, min_doc_count: 1 } },
}
end
Expand Down
32 changes: 32 additions & 0 deletions app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ class DoiSerializer
Array.wrap(object.rights_list)
end

attribute :funding_references do |object|
Array.wrap(object.funding_references)
end

attribute :identifiers do |object|
Array.wrap(object.identifiers)
end

attribute :related_identifiers do |object|
Array.wrap(object.related_identifiers)
end

attribute :geo_locations do |object|
Array.wrap(object.geo_locations)
end

attribute :dates do |object|
Array.wrap(object.dates)
end

attribute :subjects do |object|
Array.wrap(object.subjects)
end

attribute :sizes do |object|
Array.wrap(object.sizes)
end

attribute :formats do |object|
Array.wrap(object.formats)
end

attribute :container do |object|
object.container || {}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@
expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/pat.pdf")
expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 'attributes', 'dates')).to eq("date"=>":tba", "dateType"=>"Issued")
expect(json.dig('data', 'attributes', 'dates')).to eq([{"date"=>":tba", "dateType"=>"Issued"}])
end

it 'sets state to findable' do
Expand Down Expand Up @@ -2690,7 +2690,7 @@
expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703")
expect(json.dig('data', 'attributes', 'titles')).to eq([{"title"=>"Analysis Tools for Crossover Experiment of UI using Choice Architecture"}])
expect(json.dig('data', 'attributes', 'dates')).to eq("date"=>"2016-03-27", "dateType"=>"Issued")
expect(json.dig('data', 'attributes', 'dates')).to eq([{"date"=>"2016-03-27", "dateType"=>"Issued"}])
end
end

Expand Down

0 comments on commit c5bc107

Please sign in to comment.