Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Looking up manifest by ARK
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Mar 14, 2017
1 parent 635e5ac commit 0215ff1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,17 @@ def admin_state_facet
return unless can? :create, ScannedResource
blacklight_config.add_facet_field 'workflow_state_name_ssim', label: 'State'
end

def lookup_manifest
ark = "#{params[:prefix]}/#{params[:naan]}/#{params[:arkid]}"
_, result = search_results(q: "identifier_ssim:#{RSolr.solr_escape(ark)}", fl: "id, has_model_ssim", rows: 1)

if result.first
object_id = result.first['id']
model_name = result.first['has_model_ssim'].first
redirect_to polymorphic_url([:manifest, :hyrax, model_name.underscore.to_sym], id: object_id)
else
render json: { message: "No manifest found for #{ark}" }, status: 404
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

mount GeoWorks::Engine => '/'
get "/iiif/collections", defaults: { format: :json }, controller: 'hyrax/collections', action: :index_manifest
get "/iiif/lookup/:prefix/:naan/:arkid", controller: 'catalog', action: :lookup_manifest, as: :lookup_manifest

namespace :hyrax, path: :concern do
resources :parent, only: [] do
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@
end
end

describe "manifest lookup" do
context "when the manifest is found" do
it "redirects to the manifest" do
resource = FactoryGirl.create(:complete_scanned_resource, identifier: 'ark:/99999/12345678')
resource.save

get :lookup_manifest, params: { prefix: 'ark:', naan: '99999', arkid: '12345678' }
expect(response).to redirect_to "http://test.host/concern/scanned_resources/#{resource.id}/manifest?locale=en"
end
end

context "when the manifeset is not found" do
it "sends a 404 error" do
get :lookup_manifest, params: { prefix: 'ark:', naan: '99999', arkid: '99999999' }
expect(response.status).to be 404
end
end
end

def document_ids
assigns[:document_list].map do |x|
x["id"]
Expand Down

0 comments on commit 0215ff1

Please sign in to comment.