fedora_2_to_3_pid_renamer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32a1feca267687e4004907cff55c5600d2f91567
4
+ data.tar.gz: 9db15e938991fae0bf87d1027ef5d5a38efad5b6
5
+ SHA512:
6
+ metadata.gz: 5ceb7ef9e389863a7efba063a63b45de307a38ab94d4de64b0df837448fd52efb14df4bb99fb5b27179acb0982a35bd590b2ef3783859775ddd67e7a5a67de1e
7
+ data.tar.gz: e4d6212a162251f325bc47d8ed4a5b2a103cd30abbb257e0ef82b63a73aa90c747f990af7422e1be68f73bfa4ae7d6d80b0028a081d9624c3c79082ecf809cae
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'nokogiri'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Rob Nichols
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # fedora_2_to_3_pid_renamer
2
+ A small Ruby app used to apply alternative pid names to configuration files
3
+ created during the migration of fedora 2 data to fedora 3
4
+
5
+ ## Migration process
6
+
7
+ [Fedora](https://wiki.duraspace.org/display/FF/Fedora+Repository+Home) is an
8
+ open source repository system for the management and dissemination of digital content.
9
+
10
+ When [migrating from version 2 to 3](http://fedorarepository.org/sites/fedorarepository.org/files/documentation/3.2.1/index.html)
11
+ the process involves running an Analyzer, that outputs a series of files.
12
+ Among these files are a some XML files that describe the data objects that
13
+ are in the existing Fedora 2 database. These files need to be manipulated
14
+ so as to modify the Fedora 2 objects so that they will suitable to be inserted
15
+ into a Fedora 3 database.
16
+
17
+ This app will carry out the manipulation of the XML files generated by the
18
+ Analyser
19
+
20
+ ## Installation
21
+
22
+ Within an environment with ruby installed:
23
+
24
+ gem install fedora_2_to_3_pid_renamer
25
+
26
+ ## Configuration
27
+
28
+ To use this app, you must first create a config.yml file. For example:
29
+
30
+ ```
31
+ changes:
32
+ CModel1: thesis
33
+ CModel1-SDep1: thesis-SDep1
34
+
35
+ changeme: foo
36
+
37
+ folders:
38
+ input: 'path/to/analyser/files'
39
+ output: 'path/to/output/location'
40
+
41
+ locations:
42
+ - "//foxml:digitalObject/@PID"
43
+ - "//rdf:Description/@rdf:about"
44
+ - "//fedora-model:isContractorOf/@rdf:resource"
45
+
46
+ namespaces:
47
+ foxml: "info:fedora/fedora-system:def/foxml#"
48
+ rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
49
+ fedora-model: "info:fedora/fedora-system:def/model#"
50
+ ```
51
+
52
+ ### changes
53
+
54
+ The Analyzer will create model names from the Fedora 2 data. These often need to
55
+ be changed to domain specific names.
56
+
57
+ Each change has a key and value where the key is the Analyzer generated name and
58
+ the value is the domain specific name that should replace it.
59
+
60
+ ### changeme
61
+
62
+ The Analyser flags the elements that need to be changed by adding a 'changeme'
63
+ namespace to each one. This needs to be replaced with a domain specific
64
+ namespace.
65
+
66
+ ### folders
67
+
68
+ Defines the paths to the input and output folders.
69
+
70
+ The input folder should contain the XML files generated by the Analyser
71
+
72
+ An output folder is used so that Analyser files are not directly modified by
73
+ this process. The files can be deleted and the process repeated any number
74
+ of times until the output is satisfactory.
75
+
76
+ ### locations
77
+
78
+ The locations in the XML files, where the content should be modified. Each
79
+ location is defined via [XPath](http://www.w3.org/TR/xpath20/). If no suitable
80
+ content is found (as defined in changes and changeme), that location will be
81
+ ignored.
82
+
83
+ The locations given in the example above should work for most cases.
84
+
85
+ ### namespaces
86
+
87
+ For the XML file to be parsed correctly, the namespaces for the locations need
88
+ to be specified.
89
+
90
+ The namespaces in the example above should work in most cases.
91
+
92
+ ## Execution
93
+
94
+ To run the process, enter the following command in the same location as the
95
+ config.yml file:
96
+
97
+ ```
98
+ fedora_2_to_3_pid_renamer
99
+ ```
100
+
101
+ Alternatively, you can specify the location of the config.yml:
102
+
103
+ ```
104
+ fedora_2_to_3_pid_renamer -c /path/to/config.yml
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rdoc/task'
5
+ require 'rake/testtask'
6
+
7
+ Rake::RDocTask.new do |rdoc|
8
+ files =['README.rdoc', 'MIT-LICENSE', 'lib/**/*.rb']
9
+ rdoc.rdoc_files.add(files)
10
+ rdoc.main = "README.rdoc" # page to start on
11
+ rdoc.title = "Dibber Docs"
12
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
13
+ rdoc.options << '--line-numbers'
14
+ end
15
+
16
+ Rake::TestTask.new do |t|
17
+ t.test_files = FileList['test/**/*_test.rb']
18
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fedora_2_to_3_pid_renamer'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+
8
+ opt_parser = OptionParser.new do |opt|
9
+
10
+ opt.banner = "Usage: fedora_2_to_3_pid_renamer [OPTIONS]"
11
+ opt.separator ""
12
+ opt.separator "Options"
13
+
14
+ opt.on("-c","--config PATH","the PATH to the config file") do |config|
15
+ options[:config] = config
16
+ end
17
+
18
+ opt.on("-h","--help","help") do
19
+ options[:help] = true
20
+ end
21
+ end
22
+
23
+ opt_parser.parse!
24
+
25
+ config_path = options[:config] || 'config.yml'
26
+
27
+ if options[:help]
28
+
29
+ puts opt_parser
30
+
31
+ elsif !File.exist?(config_path)
32
+
33
+ puts "Config file not found: #{config_path}\n"
34
+ puts opt_parser
35
+
36
+ else
37
+
38
+ config = Fedora2To3PidRenamer::Config.load config_path
39
+
40
+ puts 'Creating files:'
41
+ manager = Fedora2To3PidRenamer::Manager.new config
42
+ manager.run_manipulation
43
+
44
+ puts 'Process complete'
45
+
46
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fedora_2_to_3_pid_renamer/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rob Nichols"]
6
+ gem.email = ["rob@undervale.com"]
7
+ gem.description = %q{Interates through a series of xml files and modifies their content based on the setting defined in a configuration file}
8
+ gem.summary = %q{A small Ruby app used to apply alternative pid names to configuration files created during the migration of fedora 2 data to fedora 3}
9
+ gem.homepage = "https://github.com/reggieb/fedora_2_to_3_pid_renamer"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = ["fedora_2_to_3_pid_renamer"]
13
+ gem.test_files = gem.files.grep(%r{^test/})
14
+ gem.name = "fedora_2_to_3_pid_renamer"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Fedora2To3PidRenamer::VERSION
17
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'fedora_2_to_3_pid_renamer/config'
2
+ require_relative 'fedora_2_to_3_pid_renamer/manipulator'
3
+ require_relative 'fedora_2_to_3_pid_renamer/manager'
4
+
5
+ module Fedora2To3PidRenamer
6
+ # TODO Put your code here
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+ module Fedora2To3PidRenamer
3
+ class Config
4
+
5
+ attr_reader :source
6
+
7
+ def self.load(path)
8
+ new File.read(path)
9
+ end
10
+
11
+ def initialize(source)
12
+ @source = source
13
+ end
14
+
15
+ def namespaces
16
+ @namespaces ||= yaml['namespaces']
17
+ end
18
+
19
+ def locations
20
+ @locations ||= yaml['locations']
21
+ end
22
+
23
+ def changes
24
+ @changes ||= yaml['changes']
25
+ end
26
+
27
+ def folders
28
+ yaml['folders']
29
+ end
30
+
31
+ def change_for(original)
32
+ changes[original]
33
+ end
34
+
35
+ def changeme_replacement
36
+ yaml['changeme']
37
+ end
38
+
39
+ def input_folder
40
+ return unless folders
41
+ @input_folder ||= path_relative_to_working_directory folders['input']
42
+ end
43
+
44
+ def output_folder
45
+ return unless folders
46
+ @output_folder ||= path_relative_to_working_directory folders['output']
47
+ end
48
+
49
+ def yaml
50
+ @yaml ||= YAML.load(source)
51
+ end
52
+
53
+ def path_relative_to_working_directory(folder)
54
+ File.expand_path folder, Dir.pwd
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,31 @@
1
+
2
+ module Fedora2To3PidRenamer
3
+ class Manager
4
+
5
+ attr_accessor :config
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def create_output_folder
12
+ return false if Dir.exist?(config.output_folder)
13
+ FileUtils.mkdir config.output_folder
14
+ end
15
+
16
+ def run_manipulation
17
+ create_output_folder
18
+ Dir.glob(input_file_pattern).each do |input_file|
19
+ file_name = File.basename input_file
20
+ input = File.read input_file
21
+ output_file = File.join config.output_folder, file_name
22
+ File.write output_file, Manipulator.output_for(input, config)
23
+ puts output_file
24
+ end
25
+ end
26
+
27
+ def input_file_pattern
28
+ File.join config.input_folder, '*.xml'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ require 'nokogiri'
2
+ module Fedora2To3PidRenamer
3
+ class Manipulator
4
+
5
+ attr_accessor :raw_xml, :config
6
+
7
+ def self.output_for(raw_xml, config)
8
+ manipulator = new(raw_xml, config)
9
+ manipulator.run
10
+ manipulator.output
11
+ end
12
+
13
+ def initialize(raw_xml, config)
14
+ @raw_xml = raw_xml
15
+ @config = config
16
+ end
17
+
18
+ def run
19
+ modify_text_at_each_location_in_config
20
+ end
21
+
22
+ def xml
23
+ @xml ||= Nokogiri::XML(raw_xml)
24
+ end
25
+
26
+ def output
27
+ xml.to_s
28
+ end
29
+
30
+ private
31
+ def modify_text_at_each_location_in_config
32
+ config.locations.each do |location|
33
+
34
+ node = xml.xpath(location, config.namespaces).first
35
+ next unless node
36
+
37
+ text = node.value
38
+ config.changes.each do |before, after|
39
+ text.gsub! before, after
40
+ end
41
+
42
+ text.gsub! 'changeme:', (config.changeme_replacement + ':')
43
+
44
+ node.value = text
45
+
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Fedora2To3PidRenamer
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,181 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foxml:digitalObject VERSION="1.1" PID="changeme:CModel1-SDep1"
3
+ xmlns:foxml="info:fedora/fedora-system:def/foxml#"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
6
+ <foxml:objectProperties>
7
+ <foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="Generated deployment for changeme:CModel1 (copy of demo:9)"/>
8
+ </foxml:objectProperties>
9
+ <foxml:datastream ID="DSINPUTSPEC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
10
+ <foxml:datastreamVersion ID="DSINPUTSPEC1.0" LABEL="Datastream Input Specification for UVA MrSID service" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/xml" FORMAT_URI="info:fedora/fedora-system:FedoraDSInputSpec-1.1" SIZE="480">
11
+ <foxml:xmlContent>
12
+ <fbs:DSInputSpec xmlns:fbs="http://fedora.comm.nsdlib.org/service/bindspec" label="MrSID Service Datastream Input Specification">
13
+ <fbs:DSInput DSMax="1" DSMin="1" DSOrdinality="false" wsdlMsgPartName="DS1">
14
+ <fbs:DSInputLabel>MrSid file</fbs:DSInputLabel>
15
+ <fbs:DSMIME>image/x-mrsid-image</fbs:DSMIME>
16
+ <fbs:DSInputInstruction>MrSid wavelet encoded image file</fbs:DSInputInstruction>
17
+ </fbs:DSInput>
18
+ </fbs:DSInputSpec>
19
+ </foxml:xmlContent>
20
+ </foxml:datastreamVersion>
21
+ </foxml:datastream>
22
+ <foxml:datastream ID="METHODMAP" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
23
+ <foxml:datastreamVersion ID="METHODMAP1.0" LABEL="Mapping of WSDL to Fedora notion of Method Definitions" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/xml" FORMAT_URI="info:fedora/fedora-system:FedoraSDepMethodMap-1.1" SIZE="1477">
24
+ <foxml:xmlContent>
25
+ <fmm:MethodMap xmlns:fmm="http://fedora.comm.nsdlib.org/service/methodmap" name="MethodMap - MrSID BMech for UserInput Image BDEF">
26
+ <fmm:Method operationName="getThumbnail" wsdlMsgName="getThumbRequest" wsdlMsgOutput="mrsid_response">
27
+ <fmm:DatastreamInputParm parmName="DS1" passBy="URL_REF" required=""/>
28
+ <fmm:MethodReturnType wsdlMsgName="mrsid_response" wsdlMsgTOMIME="image/gif"/>
29
+ </fmm:Method>
30
+ <fmm:Method operationName="getImage" wsdlMsgName="getImageRequest" wsdlMsgOutput="mrsid_response">
31
+ <fmm:UserInputParm defaultValue="yes" parmName="ZOOM" passBy="VALUE" required="true">
32
+ <fmm:ValidParmValues>
33
+ <fmm:ValidParm value="yes"/>
34
+ <fmm:ValidParm value="no"/>
35
+ </fmm:ValidParmValues>
36
+ </fmm:UserInputParm>
37
+ <fmm:UserInputParm defaultValue="medium1" parmName="SIZE" passBy="VALUE" required="true">
38
+ <fmm:ValidParmValues>
39
+ <fmm:ValidParm value="small"/>
40
+ <fmm:ValidParm value="medium1"/>
41
+ <fmm:ValidParm value="medium2"/>
42
+ </fmm:ValidParmValues>
43
+ </fmm:UserInputParm>
44
+ <fmm:DatastreamInputParm parmName="DS1" passBy="URL_REF" required=""/>
45
+ <fmm:MethodReturnType wsdlMsgName="mrsid_response" wsdlMsgTOMIME="application/java image/gif"/>
46
+ </fmm:Method>
47
+ </fmm:MethodMap>
48
+ </foxml:xmlContent>
49
+ </foxml:datastreamVersion>
50
+ </foxml:datastream>
51
+ <foxml:datastream ID="WSDL" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
52
+ <foxml:datastreamVersion ID="WSDL1.0" LABEL="WSDL definition for UVA&apos;s MrSid service" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/xml" FORMAT_URI="http://schemas.xmlsoap.org/wsdl/" SIZE="3325">
53
+ <foxml:xmlContent>
54
+ <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap" xmlns:soapenc="http://schemas.xmlsoap.org/wsdl/soap/encoding" xmlns:this="mrsid" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MrSID Service" targetNamespace="mrsid">
55
+ <wsdl:types>
56
+ <xsd:schema targetNamespace="mrsid">
57
+ <xsd:simpleType name="MRSIDType">
58
+ <xsd:restriction base="xsd:string"/>
59
+ </xsd:simpleType>
60
+ <xsd:simpleType name="ZOOMType">
61
+ <xsd:restriction base="xsd:string">
62
+ <xsd:enumeration value="yes"/>
63
+ <xsd:enumeration value="no"/>
64
+ </xsd:restriction>
65
+ </xsd:simpleType>
66
+ <xsd:simpleType name="SIZEType">
67
+ <xsd:restriction base="xsd:string">
68
+ <xsd:enumeration value="small"/>
69
+ <xsd:enumeration value="medium1"/>
70
+ <xsd:enumeration value="medium2"/>
71
+ </xsd:restriction>
72
+ </xsd:simpleType>
73
+ </xsd:schema>
74
+ </wsdl:types>
75
+ <wsdl:message name="getThumbRequest">
76
+ <wsdl:part name="DS1" type="this:MRSIDType"/>
77
+ </wsdl:message>
78
+ <wsdl:message name="getImageRequest">
79
+ <wsdl:part name="DS1" type="this:MRSIDType"/>
80
+ <wsdl:part name="SIZE" type="this:SIZEType"/>
81
+ <wsdl:part name="ZOOM" type="this:ZOOMType"/>
82
+ </wsdl:message>
83
+ <wsdl:message name="mrsid_response">
84
+ <wsdl:part name="image" type="xsd:base64Binary"/>
85
+ </wsdl:message>
86
+ <wsdl:portType name="MrSIDPortType">
87
+ <wsdl:operation name="getThumbnail">
88
+ <wsdl:input message="this:getThumbRequest"/>
89
+ <wsdl:output message="this:mrsid_response"/>
90
+ </wsdl:operation>
91
+ <wsdl:operation name="getImage">
92
+ <wsdl:input message="this:getImageRequest"/>
93
+ <wsdl:output message="this:mrsid_response"/>
94
+ </wsdl:operation>
95
+ </wsdl:portType>
96
+ <wsdl:service name="MrSID">
97
+ <wsdl:port binding="this:MrSID_http" name="MrSID_port">
98
+ <http:address location="http://iris.lib.virginia.edu/mrsid/bin/"/>
99
+ </wsdl:port>
100
+ </wsdl:service>
101
+ <wsdl:binding name="MrSID_http" type="this:MrSIDPortType">
102
+ <http:binding verb="GET"/>
103
+ <wsdl:operation name="getThumbnail">
104
+ <http:operation location="get_mrsid_url.pl?image=(DS1)&amp;size=thumbnail"/>
105
+ <wsdl:input>
106
+ <http:urlReplacement/>
107
+ </wsdl:input>
108
+ <wsdl:output>
109
+ <mime:content type="image/gif"/>
110
+ </wsdl:output>
111
+ </wsdl:operation>
112
+ <wsdl:operation name="getImage">
113
+ <http:operation location="get_mrsid_url.pl?image=(DS1)&amp;size=(SIZE)&amp;zoom=(ZOOM)"/>
114
+ <wsdl:input>
115
+ <http:urlReplacement/>
116
+ </wsdl:input>
117
+ <wsdl:output>
118
+ <mime:content type="text/html"/>
119
+ <mime:content type="image/jpeg"/>
120
+ </wsdl:output>
121
+ </wsdl:operation>
122
+ </wsdl:binding>
123
+ </wsdl:definitions>
124
+ </foxml:xmlContent>
125
+ </foxml:datastreamVersion>
126
+ </foxml:datastream>
127
+ <foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
128
+ <foxml:datastreamVersion ID="RELS-EXT1.0" LABEL="RDF Statements about this object" CREATED="2015-09-16T10:16:38.426Z" MIMETYPE="application/rdf+xml" FORMAT_URI="info:fedora/fedora-system:FedoraRELSExt-1.0">
129
+ <foxml:xmlContent>
130
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:fedora-model="info:fedora/fedora-system:def/model#">
131
+ <rdf:Description rdf:about="info:fedora/changeme:CModel1-SDep1">
132
+ <fedora-model:isDeploymentOf rdf:resource="info:fedora/demo:8"/>
133
+ <fedora-model:isContractorOf rdf:resource="info:fedora/changeme:CModel1"/>
134
+ <fedora-model:hasModel rdf:resource="info:fedora/fedora-system:ServiceDeployment-3.0"/>
135
+ </rdf:Description>
136
+ </rdf:RDF>
137
+ </foxml:xmlContent>
138
+ </foxml:datastreamVersion>
139
+ </foxml:datastream>
140
+ <foxml:datastream ID="DS1" STATE="A" CONTROL_GROUP="E" VERSIONABLE="true">
141
+ <foxml:datastreamVersion ID="DS1.0" LABEL="Programmer documentation" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/html">
142
+ <foxml:contentLocation TYPE="URL" REF=" http://uva.lib.edu/mech/mrsid/doc/mrsid.html"/>
143
+ </foxml:datastreamVersion>
144
+ </foxml:datastream>
145
+ <foxml:datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
146
+ <foxml:datastreamVersion ID="DC1.0" LABEL="Dublin Core Metadata" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/xml" FORMAT_URI="http://www.openarchives.org/OAI/2.0/oai_dc/" SIZE="306">
147
+ <foxml:xmlContent>
148
+ <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
149
+ <dc:title>Behavior Mechanism Object implementing the UserInput Image BDEF contract using the UVA MrSID Service.</dc:title>
150
+ <dc:identifier>demo:9</dc:identifier>
151
+ </oai_dc:dc>
152
+ </foxml:xmlContent>
153
+ </foxml:datastreamVersion>
154
+ </foxml:datastream>
155
+ <foxml:datastream ID="SERVICE-PROFILE" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
156
+ <foxml:datastreamVersion ID="SERVICE-PROFILE1.0" LABEL="Service Profile - Technical description of the service" CREATED="2015-09-15T13:08:26.575Z" MIMETYPE="text/xml" SIZE="1310">
157
+ <foxml:xmlContent>
158
+ <fsvp:serviceProfile xmlns:fsvp="http://fedora.comm.nsdlib.org/service/profile" bDefPID="demo:8" name="MrSID Service">
159
+ <fsvp:serviceDescription>MrSID service for providing different image resolutions from a wavelet encoded file, along with zoom capability </fsvp:serviceDescription>
160
+ <fsvp:serviceImplementation>
161
+ <fsvp:serviceLiveTestURL>http://iris.lib.virginia.edu/mrsid</fsvp:serviceLiveTestURL>
162
+ <fsvp:serviceMessagingProtocol>HTTP GET</fsvp:serviceMessagingProtocol>
163
+ <fsvp:serviceInputFormats>
164
+ <fsvp:MIMEType>image/x-mrsid-image</fsvp:MIMEType>
165
+ </fsvp:serviceInputFormats>
166
+ <fsvp:serviceOutputFormats>
167
+ <fsvp:MIMEType>text/html</fsvp:MIMEType>
168
+ <fsvp:MIMEType>image/gif</fsvp:MIMEType>
169
+ <fsvp:MIMEType>image/jpeg</fsvp:MIMEType>
170
+ <fsvp:MIMEType>application/java</fsvp:MIMEType>
171
+ </fsvp:serviceOutputFormats>
172
+ <fsvp:serviceImplDependencies>
173
+ <fsvp:software license="Commercial" name="MrSID Image Server" opensource="false" type="Server_Application" version="2.2"></fsvp:software>
174
+ <fsvp:software license="GNU_GPL" name="perl" opensource="true" type="Programming_Language" version="5.6"></fsvp:software>
175
+ </fsvp:serviceImplDependencies>
176
+ </fsvp:serviceImplementation>
177
+ </fsvp:serviceProfile>
178
+ </foxml:xmlContent>
179
+ </foxml:datastreamVersion>
180
+ </foxml:datastream>
181
+ </foxml:digitalObject>
@@ -0,0 +1,79 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foxml:digitalObject VERSION="1.1" PID="changeme:CModel1"
3
+ xmlns:foxml="info:fedora/fedora-system:def/foxml#"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
6
+ <foxml:objectProperties>
7
+ <foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="Generated CModel"/>
8
+ </foxml:objectProperties>
9
+ <foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
10
+ <foxml:datastreamVersion ID="RELS-EXT1.0" LABEL="RDF Statements about this object" CREATED="2015-09-16T10:16:15.130Z" MIMETYPE="application/rdf+xml" FORMAT_URI="info:fedora/fedora-system:FedoraRELSExt-1.0">
11
+ <foxml:xmlContent>
12
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:fedora-model="info:fedora/fedora-system:def/model#">
13
+ <rdf:Description rdf:about="info:fedora/changeme:CModel1">
14
+ <fedora-model:hasService rdf:resource="info:fedora/demo:8"/>
15
+ <fedora-model:hasModel rdf:resource="info:fedora/fedora-system:ContentModel-3.0"/>
16
+ </rdf:Description></rdf:RDF>
17
+ </foxml:xmlContent>
18
+ </foxml:datastreamVersion>
19
+ </foxml:datastream>
20
+ <foxml:datastream ID="DS-COMPOSITE-MODEL" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
21
+ <foxml:datastreamVersion ID="DS-COMPOSITE-MODEL1.0" LABEL="Datastream Composite Model" CREATED="2015-09-16T10:16:15.130Z" MIMETYPE="text/xml" FORMAT_URI="info:fedora/fedora-system:FedoraDSCompositeModel-1.0">
22
+ <foxml:xmlContent>
23
+ <dsCompositeModel xmlns="info:fedora/fedora-system:def/dsCompositeModel#">
24
+ <dsTypeModel ID="DIGIPROV1">
25
+ <form MIME="text/xml"/>
26
+ </dsTypeModel>
27
+ <dsTypeModel ID="DS1">
28
+ <form MIME="image/x-mrsid-image"/>
29
+ </dsTypeModel>
30
+ <dsTypeModel ID="SOURCE1">
31
+ <form MIME="text/xml"/>
32
+ </dsTypeModel>
33
+ <dsTypeModel ID="DESC1">
34
+ <form MIME="text/xml"/>
35
+ </dsTypeModel>
36
+ <dsTypeModel ID="RIGHTS1">
37
+ <form MIME="text/xml"/>
38
+ </dsTypeModel>
39
+ <dsTypeModel ID="TECH1">
40
+ <form MIME="text/xml"/>
41
+ </dsTypeModel>
42
+ </dsCompositeModel>
43
+ </foxml:xmlContent>
44
+ </foxml:datastreamVersion>
45
+ </foxml:datastream>
46
+ <foxml:datastream ID="CLASS-DESCRIPTION" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
47
+ <foxml:datastreamVersion ID="CLASS-DESCRIPTION1.0" LABEL="Technical description of the class of objects assigned to this content model" CREATED="2015-09-16T10:16:15.130Z" MIMETYPE="text/xml">
48
+ <foxml:xmlContent>
49
+ <class-description>
50
+ OrigContentModel
51
+ 'UVA_MRSID_IMAGE'
52
+ BDefPIDs
53
+ 'demo:8'
54
+ BMechPIDs
55
+ 'demo:9'
56
+ BindingKeyAssignments
57
+ for demo:9
58
+ 'MRSID=DS1'
59
+ DatastreamIDs
60
+ 'DIGIPROV1', 'DS1', 'SOURCE1', 'DESC1', 'RIGHTS1', 'TECH1'
61
+ MIMETypes
62
+ for DIGIPROV1, 'text/xml'
63
+ for DS1, 'image/x-mrsid-image'
64
+ for SOURCE1, 'text/xml'
65
+ for DESC1, 'text/xml'
66
+ for RIGHTS1, 'text/xml'
67
+ for TECH1, 'text/xml'
68
+ FormatURIs
69
+ for DIGIPROV1, none
70
+ for DS1, none
71
+ for SOURCE1, none
72
+ for DESC1, none
73
+ for RIGHTS1, none
74
+ for TECH1, none
75
+ </class-description>
76
+ </foxml:xmlContent>
77
+ </foxml:datastreamVersion>
78
+ </foxml:datastream>
79
+ </foxml:digitalObject>
@@ -0,0 +1,27 @@
1
+ # See http://fedorarepository.org/sites/fedorarepository.org/files/documentation/3.2.1/index.html
2
+ # How names generated by migration analyser will be converted to local names
3
+ changes:
4
+ CModel1: thesis
5
+ CModel1-SDep1: thesis-SDep1
6
+
7
+ # How changeme text will be renamed
8
+ changeme: foo
9
+
10
+ # folders where target files are located (input),
11
+ # and where the modified files will be placed (output)
12
+ # relative paths will be relative to the working directory
13
+ folders:
14
+ input: 'test/data/input'
15
+ output: 'test/data/output'
16
+
17
+ # Xpath locations where elements need to be renamed
18
+ locations:
19
+ - "//foxml:digitalObject/@PID"
20
+ - "//rdf:Description/@rdf:about"
21
+ - "//fedora-model:isContractorOf/@rdf:resource"
22
+
23
+ # Namespaces within documents - needed to process XML
24
+ namespaces:
25
+ foxml: "info:fedora/fedora-system:def/foxml#"
26
+ rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
27
+ fedora-model: "info:fedora/fedora-system:def/model#"
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foo ID="bar">
3
+ </foo>
@@ -0,0 +1,30 @@
1
+ require 'minitest/autorun'
2
+ require 'nokogiri'
3
+ require_relative '../lib/fedora_2_to_3_pid_renamer'
4
+
5
+ class Minitest::Test
6
+ def xml_load(file_name)
7
+ file = file_read(file_name)
8
+ Nokogiri::XML file
9
+ end
10
+
11
+ def data_file_path(file_name)
12
+ File.expand_path("data/#{file_name}", File.dirname(__FILE__))
13
+ end
14
+
15
+ def file_read(file_name)
16
+ File.read data_file_path(file_name)
17
+ end
18
+
19
+ def config
20
+ @config ||= Fedora2To3PidRenamer::Config.new(config_source)
21
+ end
22
+
23
+ def config_source
24
+ @config_source ||= File.read config_file_path
25
+ end
26
+
27
+ def config_file_path
28
+ data_file_path 'config.yml'
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Fedora2To3PidRenamer
4
+ class ConfigTest < Minitest::Test
5
+
6
+ def test_namespaces
7
+ assert_equal config_yml['namespaces'], config.namespaces
8
+ end
9
+
10
+ def test_locations
11
+ assert_equal config_yml['locations'], config.locations
12
+ end
13
+
14
+ def test_changes
15
+ assert_equal config_yml['changes'], config.changes
16
+ end
17
+
18
+ def test_change_for
19
+ changes = config_yml['changes']
20
+ changes.each do |original, becomes|
21
+ assert_equal becomes, config.change_for(original), "#{original} should become #{becomes}"
22
+ end
23
+ end
24
+
25
+ def test_changeme_replacement
26
+ assert_equal config_yml['changeme'], config.changeme_replacement
27
+ end
28
+
29
+ def test_load
30
+ config = Config.load(config_file_path)
31
+ assert_equal config_yml['changes'], config.changes
32
+ end
33
+
34
+ def test_input_folder
35
+ assert_match File.join('test', 'data', 'input'), config.input_folder
36
+ end
37
+
38
+ def test_input_folder
39
+ assert_match File.join('test', 'data', 'output'), config.output_folder
40
+ end
41
+
42
+ private
43
+
44
+ def config_yml
45
+ @config_yml ||= YAML.load(config_source)
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../test_helper'
2
+ require 'fileutils'
3
+
4
+ module Fedora2To3PidRenamer
5
+ class ManagerTest < Minitest::Test
6
+
7
+ def setup
8
+ FileUtils.mkdir data_file_path('input')
9
+ FileUtils.mkdir data_file_path('output')
10
+ target_files.each do |file|
11
+ destination = File.join 'input', file
12
+ FileUtils.cp data_file_path(file), data_file_path(destination)
13
+ end
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.remove_dir data_file_path('input'), true
18
+ FileUtils.remove_dir data_file_path('output'), true
19
+ end
20
+
21
+ def test_before
22
+ output_files = Dir.glob(data_file_path 'output/*.xml')
23
+ assert output_files.empty?, "There should be no files in output: #{output_files}"
24
+ end
25
+
26
+ def test_create_output_folder
27
+ assert_equal false, manager.create_output_folder
28
+ assert_equal true, Dir.exist?(config.output_folder)
29
+ end
30
+
31
+ def test_create_output_folder_when_none_exists
32
+ FileUtils.remove_dir data_file_path('output'), true
33
+ assert manager.create_output_folder, 'Should return truthy if folder created'
34
+ assert_equal true, Dir.exist?(config.output_folder)
35
+ end
36
+
37
+ def test_run_manipulation
38
+ manager.run_manipulation
39
+ target_files.each do |file|
40
+ output_file = data_file_path(File.join('output', file))
41
+ assert File.exist?(output_file), "#{output_file} should exist"
42
+ end
43
+ end
44
+
45
+ def test_run_manipulation_alters_content
46
+ manager.run_manipulation
47
+ xml = xml_load File.join('output', target_files.first)
48
+ xpath = config.locations.first
49
+ text = xml.xpath(xpath).text
50
+ assert_match config.changeme_replacement, text
51
+ end
52
+
53
+ def manager
54
+ @manager ||= Manager.new(config)
55
+ end
56
+
57
+ def target_files
58
+ [
59
+ 'cmodel-1.xml',
60
+ 'cmodel-1.deployment1.xml'
61
+ ]
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Fedora2To3PidRenamer
4
+ class ManipulatorTest < Minitest::Test
5
+
6
+ def test_run
7
+ before, after = config.changes.first
8
+ assert_at_xpath_text_changes(before, after) { manipulator.run }
9
+ end
10
+
11
+ def test_run_modifies_changeme_namespace
12
+ before = 'changeme:'
13
+ after = config.changeme_replacement + ':'
14
+ assert_at_xpath_text_changes(before, after) { manipulator.run }
15
+ end
16
+
17
+ def test_output
18
+ assert_equal Nokogiri::XML(xml_raw).to_s, manipulator.output
19
+ end
20
+
21
+ def test_run_alters_output
22
+ manipulator.run
23
+ refute_equal Nokogiri::XML(xml_raw).to_s, manipulator.output
24
+ end
25
+
26
+ def test_run_produces_well_formed_xml
27
+ manipulator.run
28
+ doc = Nokogiri::XML manipulator.output
29
+ assert doc.errors.empty?, "Nokogiri should not find errors: #{doc.errors}"
30
+ end
31
+
32
+ def test_output_for
33
+ manipulator.run
34
+ assert_equal manipulator.output, Manipulator.output_for(xml_raw, config)
35
+ end
36
+
37
+ private
38
+ def assert_at_xpath_text_changes(before, after)
39
+ xpath = config.locations.first
40
+
41
+ text_before = manipulator.xml.xpath(xpath, config.namespaces).text
42
+ assert_match before, text_before
43
+ refute_match after, text_before
44
+
45
+ yield
46
+
47
+ text_after = manipulator.xml.xpath(xpath, config.namespaces).text
48
+ refute_match before, text_after
49
+ assert_match after, text_after
50
+ end
51
+
52
+
53
+ def manipulator
54
+ @manipulator ||= Manipulator.new(xml_raw, config)
55
+ end
56
+
57
+ def xml_raw
58
+ @xml_raw ||= file_read 'cmodel-1.xml'
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../test_helper'
2
+
3
+ class Fedora2To3PidRenamerTest < Minitest::Test
4
+
5
+ def test_environment
6
+ assert_equal true, true
7
+ end
8
+
9
+ def test_data_can_be_loaded
10
+ lines = File.readlines(xml_file_path)
11
+ expected = '<?xml version="1.0" encoding="UTF-8"?>'
12
+ assert_equal expected, lines.first.strip
13
+ end
14
+
15
+ def test_xml_load
16
+ file = File.read(xml_file_path)
17
+ xml = Nokogiri::XML(file)
18
+ assert_equal Nokogiri::XML::Document, xml_load(xml_file_name).class
19
+ assert_equal xml.children.size, xml_load(xml_file_name).children.size
20
+ assert_equal xml.to_s, xml_load(xml_file_name).to_s
21
+ end
22
+
23
+ def test_get_xml_attribute
24
+ expected = 'changeme:CModel1'
25
+ xml = xml_load(xml_file_name)
26
+ namespaces = {'foxml' => 'info:fedora/fedora-system:def/foxml#'}
27
+ node = xml.xpath('//foxml:digitalObject/@PID', namespaces)
28
+ assert_equal expected, node.text
29
+ end
30
+
31
+ def test_get_xml_attribute_from_simple
32
+ xml = xml_load('simple.xml')
33
+ node = xml.xpath('//foo/@ID')
34
+ assert_equal 'bar', node.text
35
+ end
36
+
37
+ def xml_file_path
38
+ File.expand_path("../data/#{xml_file_name}", File.dirname(__FILE__))
39
+ end
40
+
41
+ def xml_file_name
42
+ 'cmodel-1.xml'
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fedora_2_to_3_pid_renamer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob Nichols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Interates through a series of xml files and modifies their content based
14
+ on the setting defined in a configuration file
15
+ email:
16
+ - rob@undervale.com
17
+ executables:
18
+ - fedora_2_to_3_pid_renamer
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/fedora_2_to_3_pid_renamer
28
+ - fedora_2_to_3_pid_renamer.gemspec
29
+ - lib/fedora_2_to_3_pid_renamer.rb
30
+ - lib/fedora_2_to_3_pid_renamer/config.rb
31
+ - lib/fedora_2_to_3_pid_renamer/manager.rb
32
+ - lib/fedora_2_to_3_pid_renamer/manipulator.rb
33
+ - lib/fedora_2_to_3_pid_renamer/version.rb
34
+ - test/data/cmodel-1.deployment1.xml
35
+ - test/data/cmodel-1.xml
36
+ - test/data/config.yml
37
+ - test/data/simple.xml
38
+ - test/test_helper.rb
39
+ - test/units/fedora_2_to_3_pid_renamer/config_test.rb
40
+ - test/units/fedora_2_to_3_pid_renamer/manager_test.rb
41
+ - test/units/fedora_2_to_3_pid_renamer/manipulator_test.rb
42
+ - test/units/fedora_2_to_3_pid_renamer_test.rb
43
+ homepage: https://github.com/reggieb/fedora_2_to_3_pid_renamer
44
+ licenses: []
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.6
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: A small Ruby app used to apply alternative pid names to configuration files
66
+ created during the migration of fedora 2 data to fedora 3
67
+ test_files:
68
+ - test/data/cmodel-1.deployment1.xml
69
+ - test/data/cmodel-1.xml
70
+ - test/data/config.yml
71
+ - test/data/simple.xml
72
+ - test/test_helper.rb
73
+ - test/units/fedora_2_to_3_pid_renamer/config_test.rb
74
+ - test/units/fedora_2_to_3_pid_renamer/manager_test.rb
75
+ - test/units/fedora_2_to_3_pid_renamer/manipulator_test.rb
76
+ - test/units/fedora_2_to_3_pid_renamer_test.rb