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

Commit

Permalink
Add a path to get all collections in one manifest.
Browse files Browse the repository at this point in the history
Closes #339
  • Loading branch information
Trey Terrell committed Jan 12, 2016
1 parent 20c9831 commit 889e055
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 13 deletions.
13 changes: 13 additions & 0 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CollectionsController < ApplicationController
include CurationConcerns::CollectionsControllerBehavior
skip_load_and_authorize_resource only: :index_manifest

def form_class
CollectionEditForm
Expand All @@ -17,12 +18,24 @@ def manifest
end
end

def index_manifest
respond_to do |f|
f.json do
render json: all_manifests_builder
end
end
end

private

def manifest_builder
ManifestBuilder.new(presenter, ssl: request.ssl?, services: AuthManifestBuilder.auth_services(login_url, logout_url))
end

def all_manifests_builder
AllCollectionsManifestBuilder.new(nil, ssl: request.ssl?)
end

def login_url
main_app.user_omniauth_authorize_url(:cas)
end
Expand Down
23 changes: 23 additions & 0 deletions app/presenters/all_collections_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class AllCollectionsPresenter < CollectionShowPresenter
def initialize(current_ability = nil)
@current_ability = current_ability
end

def title
"Plum Collections"
end

def description
"All collections which are a part of Plum."
end

def creator
nil
end

private

def ordered_ids
ActiveFedora::SolrService.query("active_fedora_model_ssi:Collection", rows: 10_000, fl: "id").map { |x| x["id"] }
end
end
27 changes: 27 additions & 0 deletions app/services/all_collections_manifest_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class AllCollectionsManifestBuilder < ManifestBuilder
def initialize(record = nil, ssl: false)
super
end

private

def root_path
"#{helper.root_url(protocol: protocol)}collections/manifest"
end

def protocol
if @ssl
:https
else
:http
end
end

def helper
@helper ||= ManifestBuilder::ManifestHelper.new
end

def record
@record ||= AllCollectionsPresenter.new
end
end
3 changes: 1 addition & 2 deletions app/services/manifest_builder/record_property_builder.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
class ManifestBuilder
class RecordPropertyBuilder
attr_reader :record, :path
def initialize(record, path, ssl: false)
def initialize(record, path)
@record = record
@path = path
@ssl = ssl
end

def apply(manifest)
Expand Down
25 changes: 14 additions & 11 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@
end
mount Hydra::RoleManagement::Engine => '/'

mount Hydra::Collections::Engine => '/'
mount CurationConcerns::Engine, at: '/'
resources :welcome, only: 'index'
root to: 'welcome#index'
# Add URL options
default_url_options Rails.application.config.action_mailer.default_url_options

# Collections have to go before CC routes, to add index_manifest.
resources :collections, only: [] do
member do
get :manifest, defaults: { format: :json }
end
collection do
get :manifest, defaults: { format: :json }, action: :index_manifest
end
end
mount Hydra::Collections::Engine => '/'
mount CurationConcerns::Engine, at: '/'
curation_concerns_collections
curation_concerns_basic_routes
curation_concerns_embargo_management

# Add URL options
default_url_options Rails.application.config.action_mailer.default_url_options

namespace :curation_concerns, path: :concern do
resources :multi_volume_works, only: [] do
member do
Expand All @@ -40,12 +49,6 @@
end
end

resources :collections do
member do
get :manifest, defaults: { format: :json }
end
end

namespace :curation_concerns, path: :concern do
resources :scanned_resources, only: [:new, :create, :show], path: 'container/:parent_id/scanned_resources', as: 'member_scanned_resource'
end
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/collection_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@
expect(response).to be_success
end
end

describe "#index_manifest" do
let(:user) { FactoryGirl.create(:admin) }
before do
sign_in user
end
it "returns a manifest for all collections" do
FactoryGirl.create(:collection)
allow(AllCollectionsManifestBuilder).to receive(:new).and_call_original

get :index_manifest, format: :json

expect(AllCollectionsManifestBuilder).to have_received(:new).with(nil, ssl: false)
expect(response).to be_success
end
end
end
17 changes: 17 additions & 0 deletions spec/presenters/all_collections_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.describe AllCollectionsPresenter do
subject { described_class.new }

it "can be used to build a manifest" do
expect { AllCollectionsManifestBuilder.new(subject).to_json }.not_to raise_error
end

it "has a title" do
expect(subject.title).to eq "Plum Collections"
end

it "has a description" do
expect(subject.description).to eq "All collections which are a part of Plum."
end
end
4 changes: 4 additions & 0 deletions spec/routing/collection_manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
it "routes to the manifest action" do
expect(get manifest_collection_path(id: "1")).to route_to controller: "collections", action: "manifest", format: :json, id: "1"
end

it "can route an index manifest" do
expect(get "/collections/manifest").to route_to controller: "collections", action: "index_manifest", format: :json
end
end
22 changes: 22 additions & 0 deletions spec/services/all_collections_manifest_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rails_helper'

RSpec.describe AllCollectionsManifestBuilder do
subject { described_class.new }
context "when there are collections" do
let(:manifest_json) { JSON.parse(subject.to_json) }
it "builds them as sub-manifests" do
FactoryGirl.create(:collection)

expect(manifest_json["manifests"].length).to eq 1
end
it "has an ID" do
expect(manifest_json["@id"]).to eq "http://plum.com/collections/manifest"
end
context "when SSL is set" do
subject { described_class.new(nil, ssl: true) }
it "can have an SSL ID" do
expect(manifest_json["@id"]).to eq "https://plum.com/collections/manifest"
end
end
end
end

0 comments on commit 889e055

Please sign in to comment.