Skip to content

Commit

Permalink
Create the collections that are required for the contribute deposits
Browse files Browse the repository at this point in the history
* Create the collections that are required for the contribute deposits
* If a collection gets deleted, eradicate it so the id can be used
again and re-create the collection
* Make a rake task so this can be run easily from the command line
* Add it to capistrano to ensure they exist whenever we deploy
  • Loading branch information
bess committed Dec 27, 2017
1 parent 00e2dae commit 2f00f01
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ RSpec/MultipleExpectations:
- 'spec/controllers/hyrax/audios_controller_spec.rb'
- 'spec/features/**/*'
- 'spec/jobs/**/*'
- 'spec/lib/tufts/contribute_collections_spec.rb'
- 'spec/lib/tufts/workflow_setup_spec.rb'
- 'spec/services/**/*'
Style/FileName:
Expand Down
85 changes: 85 additions & 0 deletions app/lib/tufts/contribute_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module Tufts
class ContributeCollections
attr_reader :seed_data

def initialize
@seed_data = SEED_DATA
end

def self.create
Tufts::ContributeCollections.new.create
end

# Convert a legacy Tufts identifier into a predictable and valid Fedora identifier
# @param [String] id
def convert_id(id)
newid = id.downcase
newid.slice!('tufts:')
newid.tr!('.', '_')
end

def create
@seed_data.each do |collection_hash|
find_or_create_collection(collection_hash)
end
end

# Given a hash of collection values, find or create the collection.
# If the collection has been deleted, eradicate it so the id can be
# re-used, and re-create the collection object.
# @param [Hash] collection_hash
def find_or_create_collection(collection_hash)
id = convert_id(collection_hash[:identifier])
begin
Collection.find(id)
rescue ActiveFedora::ObjectNotFoundError
create_collection(collection_hash)
rescue Ldp::Gone
Collection.eradicate(id)
create_collection(collection_hash)
end
end

def create_collection(collection_hash)
id = convert_id(collection_hash[:identifier])
collection = Collection.new(id: id)
collection.title = Array(collection_hash[:title])
collection.identifier = Array(collection_hash[:identifier])
collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
collection.save
end

SEED_DATA = [
{
title: "Tufts Published Scholarship, 1987-2014",
identifier: "tufts:UA069.001.DO.PB",
object_types: [GenericDeposit, GenericTischDeposit, GisPoster, UndergradSummerScholar, FacultyScholarship]
},
{
title: "Fletcher School Records, 1923 -- 2016",
identifier: "tufts:UA069.001.DO.UA015",
object_type: [CapstoneProject]
},
{
title: "Cummings School of Veterinary Medicine records, 1969-2012",
identifier: "tufts:UA069.001.DO.UA041",
object_type: [CummingsThesis]
},
{
title: "Undergraduate honors theses, 1929-2015",
identifier: "tufts:UA069.001.DO.UA005",
object_type: [HonorsThesis]
},
{
title: "Public Health and Professional Degree Programs Records, 1990 -- 2011",
identifier: "tufts:UA069.001.DO.UA187",
object_type: [PublicHealth]
},
{
title: "Department of Education records, 2007-02-01-2014",
identifier: "tufts:UA069.001.DO.UA071",
object_type: [QualifyingPaper]
}
].freeze
end
end
Empty file.
11 changes: 11 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
end
after 'deploy:restart', 'load_workflows'

# Ensure contribution collections are created whenever we deploy. Otherwise the
# /contribute deposits won't have the right collections to go into
task :create_contribute_collections do
on roles(:app) do
within release_path do
execute :bundle, 'exec rake tufts:create_contribute_collections RAILS_ENV=production'
end
end
end
after 'deploy:restart', 'create_contribute_collections'

# Passenger is not consistently restarting, but the problem seems to
# be fixed by making it restart twice.
task :reenable_deploy_restart do
Expand Down
8 changes: 8 additions & 0 deletions lib/tasks/create_contribute_collections.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rake'

namespace :tufts do
desc "Create contribute collections"
task create_contribute_collections: :environment do
Tufts::ContributeCollections.create
end
end
26 changes: 26 additions & 0 deletions spec/lib/tufts/contribute_collections_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rails_helper'

RSpec.describe Tufts::ContributeCollections, :clean do
let(:cc) { described_class.new }

it "has a hash of all the collections to be made, with their ids and titles" do
expect(cc.seed_data).to be_instance_of(Array)
end
it "converts a legacy identifier into a predictable valid fedora id" do
expect(cc.convert_id('tufts:UA069.001.DO.PB')).to eq("ua069_001_do_pb")
end

context "creating all the collections" do
before do
described_class.create
end
it "creates a collection object for each item in the seed array" do
expect(Collection.count).to eq(6)
end
it "populates title and legacy identifier" do
c = Collection.find("ua069_001_do_pb")
expect(c.title.first).to eq("Tufts Published Scholarship, 1987-2014")
expect(c.identifier.first).to eq("tufts:UA069.001.DO.PB")
end
end
end

0 comments on commit 2f00f01

Please sign in to comment.