# Copyright © 2012 The Pennsylvania State University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # sufia-fixtures # # This was extracted from the original Hydra version in # ~/rvm/gems/@sufia/bundler/gems/lib/railties # It has been changed to read all files out of a directory and pass those as fixtures. # Any _ in the file name will be modified to a : for the id, since colons are not valid in a file name. # The files should be named id_[fixture id] which should relates to the id within the foxml sufia:[fixture id] where # [fixture id] is some alpha numeric id ('test1') # # There are 2 sets of data needed to attach to a sufia fixture, 1 the data file, and 2 the metadata. # It is important that the meta-data contains the appropriate id, or solor will not index it! # # Usage: rake sufia:fixtures:create [DIR=] [FIXTURE_ID=] [FIXTURE_TITLE=] [FIXTURE_USER=] # is an optional directory under spec/fixtures to find the fixtures to load # DEFAULT: sufia # is the id given to this fixture with fedora and solr. # This must be unique and any old files will be overwritten. # DEFAULT: sufia # is the title given to the fixture in fedora and solor, # along with being put in the description and subject by default. # DEFAULT: sufia test # is the user given to the fixture in fedora and solor, # along with being put in the contributor and rights. # DEFAULT: archivist1 # # # Creates new fixture files including the erb, descMeta, and text for loading into sufia. # The Files are named based on the sufia: id_.foxml.erb, id_.descMeta.txt, and id_.txt # The foxml.erb file references the descMeta.txt and .txt file. You can edit the erb to point to other data and/or edit the # .descMeta.txt and/or .txt file to contain the data you wish. # # *** Please note that the id must be changed in the file name, foxml.erb, and descMeta.txt if you change it after creation. *** # # rake sufia:fixtures:generate [DIR=] # is an optional directory under spec/fixtures to find the fixtures to load # DEFAULT: sufia # # Creates foxml.xml files from the foxml.erb files doing any erb substitutions within the erb file. # This task is mostly used to put the appropriate Rails.root into the foxml.xml file so that # the data and meta-data files can be located on load. # # rake sufia:fixtures:delete [DIR=] # is an optional directory under spec/fixtures to find the fixtures to load # DEFAULT: sufia # # Remove any fixtures defined by .xml.foxml files in Rais.root/spec/fixtures/ from fedora and solr. # # rake sufia:fixtures:load [DIR=] # is an optional directory under spec/fixtures to find the fixtures to load # DEFAULT: sufia # # load any fixtures defined by .xml.foxml files in Rais.root/spec/fixtures/ into fedora and solr. # # rake sufia:fixtures:refresh [DIR=] # is an optional directory under spec/fixtures to find the fixtures to load # DEFAULT: sufia # # delete then load any fixtures defined by .xml.foxml files in Rais.root/spec/fixtures/ into fedora and solr. # # Example meta-data: # # "archivist1" . # "MP3 Description" . # "04/12/2012" . # "archivist1" . # "MP3" . # "test" . # "MP3 Test" . # "En" . # "State College" . # "archivist1" . # "archivist1" . # "Test" . # # Example foxml: (note the ID needs to be unique) (the binary data in the xml below was generated using base64 on the text) # # # # # # # # # # # # testFixture2.txt # sufia:[fixture id] # # # # # # # PGluZm86ZmVkb3JhL2lkOnRlc3QyPiA8aHR0cDovL3B1cmwub3JnL2RjL3Rlcm1zL3B1Ymxpc2hl # cj4gIkNBQyIgLgo8aW5mbzpmZWRvcmEvaWQ6dGVzdDI+IDxodHRwOi8vcHVybC5vcmcvZGMvdGVy # bXMvZGVzY3JpcHRpb24+ICJUZXN0IEZpeHR1cmUgMiIgLgo8aW5mbzpmZWRvcmEvaWQ6dGVzdDI+ # IDxodHRwOi8vcHVybC5vcmcvZGMvdGVybXMvY3JlYXRlZD4gIjQvNi8yMDEyIiAuCjxpbmZvOmZl # ZG9yYS9pZDp0ZXN0Mj4gPGh0dHA6Ly9wdXJsLm9yZy9kYy90ZXJtcy9jb250cmlidXRvcj4gIkNB # QyIgLgo8aW5mbzpmZWRvcmEvaWQ6dGVzdDI+IDxodHRwOi8vcHVybC5vcmcvZGMvdGVybXMvdGl0 # bGU+ICJUZXN0IEZpeHR1cmUgMiAoVGl0bGUpIiAuCjxpbmZvOmZlZG9yYS9pZDp0ZXN0Mj4gPGh0 # dHA6Ly9wdXJsLm9yZy9kYy90ZXJtcy9yZWxhdGlvbj4gInRlc3QiIC4KPGluZm86ZmVkb3JhL2lk # OnRlc3QyPiA8aHR0cDovL3B1cmwub3JnL2RjL3Rlcm1zL3N1YmplY3Q+ICJUZXN0aW5nIEZpeHR1 # cmUgMiIgLgo8aW5mbzpmZWRvcmEvaWQ6dGVzdDI+IDxodHRwOi8vcHVybC5vcmcvZGMvdGVybXMv # bGFuZ3VhZ2U+ICJFbiIgLgo8aW5mbzpmZWRvcmEvaWQ6dGVzdDI+IDxodHRwOi8veG1sbnMuY29t # L2ZvYWYvMC4xL2Jhc2VkX25lYXI+ICJTdGF0ZSBDb2xsZWdlIiAuCjxpbmZvOmZlZG9yYS9pZDp0 # ZXN0Mj4gPGh0dHA6Ly9wdXJsLm9yZy9kYy90ZXJtcy9yaWdodHM+ICJjYWMiIC4KPGluZm86ZmVk # b3JhL2lkOnRlc3QyPiA8aHR0cDovL3B1cmwub3JnL2RjL3Rlcm1zL2NyZWF0b3I+ICJDQUMiIC4K # PGluZm86ZmVkb3JhL2lkOnRlc3QyPiA8aHR0cDovL3B1cmwub3JnL2RjL3Rlcm1zL2lkZW50aWZp # ZXI+ICJmaXh0dXJlIiAuCg== # # # # # # # # # # # # # # # # # VGhpcyBpcyBhIHRlc3QgZml4dHVyZS4gCkJpbmFyeSBkYXRhIGZvciBmaXh0dXJlIDIuCg== # # # # # # # # # # no # # # # # # # # # # # # # # cam156@psu.edu # # # # # # # # # # # # # # require 'active_fedora' SUFIA_TEST_NS = 'sufia' #this must be the same as id_namespace in the test applications config namespace :sufia do namespace :fixtures do @localDir = File.expand_path("../../../spec/fixtures", __FILE__) @dir = ENV["FIXTURE_DIR"] || 'sufia' desc "Load default Sufia Hydra fixtures" task :load => :environment do dir = File.join(@localDir, @dir) loader = ActiveFedora::FixtureLoader.new(dir) fixtures = find_fixtures(@dir) fixtures.each do |fixture| puts "Fixture is #{fixture}" loader.import_and_index(fixture) puts "Loaded '#{fixture}'" # Rake::Task["repo:load"].reenable # Rake::Task["repo:load"].invoke end raise "No fixtures found; you may need to generate from erb, use: rake sufia:fixtures:generate" if fixtures.empty? end desc "Remove default Sufia Hydra fixtures" task :delete do ENV["dir"] = File.join(@localDir, @dir) fixtures = find_fixtures(@dir) fixtures.each do |fixture| ENV["pid"] = fixture Rake::Task["repo:delete"].reenable Rake::Task["repo:delete"].invoke end end desc "Refresh default Sufia Hydra fixtures" task :refresh => [:delete, :load] desc "Fix fixtures so they work with Cucumber [KLUDGE]" task :fix do puts "Attempting to fix fixtures that break cuke" ## Kludgy workarounds to get past lack of depositor in fixtures # First, create a user record User.create(email: 'archivist1@example.com')#, display_name: 'Captain Archivist') # Then, set this user as the depositor of test4 to appease this damn failing cuke gf = GenericFile.find('sufia:test4') gf.apply_depositor_metadata('archivist1@example.com') gf.save end private def find_fixtures(dir) Dir.glob(File.join(@localDir, dir, '*.foxml.xml')).map do |fixture_file| File.basename(fixture_file, '.foxml.xml').gsub('_',':') end end end end