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

Commit

Permalink
Prep for object-merge release
Browse files Browse the repository at this point in the history
- Update version of druid-tools gem
- Fix typo in MergeService
- Added script for a manual-integration test
  • Loading branch information
wmene committed Nov 8, 2013
1 parent 6936d95 commit 8e8e21a
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -77,7 +77,7 @@ GEM
confstruct
nokogiri
rest-client
druid-tools (0.2.6)
druid-tools (0.3.0)
equivalent-xml (0.3.0)
nokogiri (>= 1.4.3)
fakeweb (1.3.0)
Expand Down
2 changes: 1 addition & 1 deletion config/dev_console_env.rb.example
Expand Up @@ -22,7 +22,7 @@ Dor::Config.configure do
end

metadata do
exist.url 'http://viewer:l3l%40nd@lyberapps-dev.stanford.edu/exist/rest/'
exist.url 'http://server/exist/rest/'
catalog.url 'http://lyberservices-prod.stanford.edu/catalog/mods'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dor/services/merge_service.rb
Expand Up @@ -82,7 +82,7 @@ def decomission_secondaries
# Remove content from stacks
# TODO might set workflow status in future for robot to do
def unshelve
DigitalStacksService.remove_stacks_dir @current_secondary.pid
DigitalStacksService.prune_stacks_dir @current_secondary.pid
end

# Withdraw item from Purl
Expand Down
176 changes: 176 additions & 0 deletions script/manual_integration.rb
@@ -0,0 +1,176 @@
require 'rubygems'
require 'rubygems/package'
require 'zlib'
require 'fileutils'

module Util
module Tar
# Creates a tar file in memory recursively
# from the given path.
#
# Returns a StringIO whose underlying String
# is the contents of the tar file.
def tar(path)
tarfile = StringIO.new("")
Gem::Package::TarWriter.new(tarfile) do |tar|
Dir[File.join(path, "**/*")].each do |file|
mode = File.stat(file).mode
relative_file = file.sub /^#{Regexp::escape path}\/?/, ''

if File.directory?(file)
tar.mkdir relative_file, mode
else
tar.add_file relative_file, mode do |tf|
File.open(file, "rb") { |f| tf.write f.read }
end
end
end
end

tarfile.rewind
tarfile
end

# gzips the underlying string in the given StringIO,
# returning a new StringIO representing the
# compressed file.
def gzip(tarfile)
gz = StringIO.new("")
z = Zlib::GzipWriter.new(gz)
z.write tarfile.string
z.close # this is necessary!

# z was closed to write the gzip footer, so
# now we need a new StringIO
StringIO.new gz.string
end

# un-gzips the given IO, returning the
# decompressed version as a StringIO
def ungzip(tarfile)
z = Zlib::GzipReader.new(tarfile)
unzipped = StringIO.new(z.read)
z.close
unzipped
end

# untars the given IO into the specified
# directory
def untar(io, destination)
Gem::Package::TarReader.new io do |tar|
tar.each do |tarfile|
destination_file = File.join destination, tarfile.full_name

if tarfile.directory?
FileUtils.mkdir_p destination_file
else
destination_directory = File.dirname(destination_file)
FileUtils.mkdir_p destination_directory unless File.directory?(destination_directory)
File.open destination_file, "wb" do |f|
f.print tarfile.read
end
end
end
end
end
end
end


class MergeIntegrationTest
include Util::Tar

# pids without druid: prefix
def initialize(pids, fixture_dir)
@pids = pids
@fixture_dir = fixture_dir
end

def delete_objs
@pids.map{ |p| 'druid:' + p }.each do |pid|
begin
i = Dor::Item.find pid
i.delete if i
rescue
end
end
end

def load_foxml(delete = true)
delete_objs if delete
@pids.map{|p| File.join(@fixture_dir, "druid_#{p}.foxml.xml")}.each do |foxml|
ActiveFedora::FixtureLoader.import_to_fedora foxml
end
end

def untar_workspace
@pids.each do |pid|
dr = DruidTools::Druid.new 'druid:' + pid, Dor::Config.stacks.local_workspace_root
dr.prune!
dr.mkdir
tarfile = File.open(File.join(@fixture_dir, "#{pid}.tgz"), 'rb')
io = ungzip tarfile
untar(io, dr.pathname.parent)
end
end

def publish_shelve
@pids.map{|p| "druid:#{p}"}.each do |pid|
i = Dor::Item.find pid
change_manifest = Dor::Versioning::FileInventoryDifference.new(i.get_content_diff(:shelve))
Dor::DigitalStacksService.shelve_to_stacks i.pid, change_manifest.file_sets(:added, :content)
i.publish_metadata
end
end

def merge
druids = @pids.map{|p| "druid:#{p}"}
Dor::MergeService.merge_into_primary druids.shift, druids
end



end


#
# p_pid = 'druid:ps262bn7350'
# s_pid = 'druid:tw313dx4156'
#
# i = Dor::Item.find p_pid
# i.delete
# i = Dor::Item.find s_pid
# i.delete
# ActiveFedora::FixtureLoader.import_to_fedora Dir.glob('../frda/*.xml').first
# ActiveFedora::FixtureLoader.import_to_fedora Dir.glob('../frda/*.xml').last
#
# # retar workspace dirs
# [p_pid, s_pid].each do |pid|
# dr = DruidTools::Druid.new pid, Dor::Config.stacks.local_workspace_root
# dr.prune!
# dr.mkdir
# Dir.chdir dr.pathname.parent do |dir|
# pid =~ /(\d{4})$/
# exec "tar xvzf /home/lyberadmin/wmene/frda/#{$1}.tgz"
# end
# end
#
#
# # Add content to stacks and purl for secondary
# i = Dor::Item.find s_pid
# i.publish_metadata
# Dor::DigitalStacksService.shelve_to_stacks s_pid, ['T0000001.jp2']
#
# ms = Dor::MergeService.new p_pid, [s_pid]
# ms.check_objects_editable
# ms.move_metadata_and_content
# ms.decomission_secondaries


# 2nd merge druids
# %w(fq996gt6655 pf986hr8937 xz522yc4008 zf307yb9756)
# pids = %w(fq996gt6655 pf986hr8937 xz522yc4008 zf307yb9756)
# mit = MergeIntegrationTest.new pids, '/home/lyberadmin/wmene/frda2'



0 comments on commit 8e8e21a

Please sign in to comment.