Skip to content

Commit

Permalink
use repository info via api. datacite/datacite#336
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 23, 2018
1 parent 122862c commit dc77071
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 139 deletions.
40 changes: 0 additions & 40 deletions app/controllers/repositories_controller.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def as_indexed_json(options={})
"updated" => updated,
"deleted_at" => deleted_at,
"provider" => provider.as_indexed_json,
"repository" => repository.try(:as_indexed_json)
"repository" => repository
}
end

def self.query_fields
['symbol^10', 'name^10', 'contact_name^10', 'contact_email^10', 'domains', 'url', '_all']
['symbol^10', 'name^10', 'contact_name^10', 'contact_email^10', 'domains', 'url', 'repository.software.name^3', '_all']
end

def self.query_aggregations
Expand Down
9 changes: 6 additions & 3 deletions app/models/concerns/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ def cached_resource_type_response(id)
end

def cached_repository_response(id, options={})
Rails.cache.fetch("repository_response/#{id}", expires_in: 7.days) do
repository = Repository.where(id: id)
repository.present? ? repository[:data] : nil
Rails.cache.fetch("repository_response/#{id}", expires_in: 1.day) do
url = Rails.env.production? ? "https://api.datacite.org" : "https://api.test.datacite.org"
response = Maremma.get(url + "/repositories/" + id)
attributes = response.body.dig("data", "attributes").to_h
attributes = attributes.transform_keys! { |key| key.tr('-', '_') }
attributes.merge("id" => id, "cache_key" => "repositories/#{id}-#{attributes["updated"]}")
end
end
end
Expand Down
87 changes: 0 additions & 87 deletions app/models/repository.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/serializers/client_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ClientSerializer
set_key_transform :dash
set_type :clients
set_id :uid
cache_options enabled: true, cache_length: 24.hours
#cache_options enabled: true, cache_length: 24.hours

attributes :name, :symbol, :year, :contact_name, :contact_email, :domains, :url, :created, :updated

Expand Down
7 changes: 5 additions & 2 deletions app/serializers/repository_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class RepositorySerializer
include FastJsonapi::ObjectSerializer
set_key_transform :dash
set_type :repositories
cache_options enabled: true, cache_length: 24.hours
#cache_options enabled: true, cache_length: 24.hours

attributes :name, :additional_name, :description, :repository_url, :repository_contact, :subject, :repository_software, :created, :updated
attributes :repository_name, :repository_url, :repository_contacts, :description, :certificates, :types,
:additional_names, :subjects, :content_types, :provider_types,
:keywords, :institutions, :data_accesses, :data_uploads, :data_upload_licenses, :pid_systems,
:apis, :pid_systems, :software, :start_date, :end_date, :created, :updated
end
4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
end
resources :providers, constraints: { :id => /.+/ }

# re3data
resources :repositories, only: [:show, :index]
get "/repositories/:id/badge", to: "repositories#badge", format: :svg

resources :resource_types, path: 'resource-types', only: [:show, :index]

# custom routes for maintenance tasks
Expand Down

0 comments on commit dc77071

Please sign in to comment.