-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the collections that are required for the contribute deposits
* 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
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |