fedora-migrate 0.0.1 → 0.1.0
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/LICENSE +14 -0
- data/README.md +201 -6
- data/config/jetty.yml +2 -2
- data/fedora-migrate.gemspec +7 -6
- data/lib/fedora-migrate.rb +7 -24
- data/lib/fedora_migrate/content_mover.rb +49 -0
- data/lib/fedora_migrate/datastream_mover.rb +19 -34
- data/lib/fedora_migrate/datastream_verification.rb +36 -0
- data/lib/fedora_migrate/dates_mover.rb +14 -0
- data/lib/fedora_migrate/hooks.rb +23 -0
- data/lib/fedora_migrate/migration_options.rb +18 -0
- data/lib/fedora_migrate/mover.rb +12 -0
- data/lib/fedora_migrate/object_mover.rb +20 -9
- data/lib/fedora_migrate/rdf_datastream_mover.rb +31 -14
- data/lib/fedora_migrate/rels_ext_datastream_mover.rb +28 -62
- data/lib/fedora_migrate/repository_migrator.rb +30 -25
- data/lib/fedora_migrate/rubydora_connection.rb +0 -2
- data/lib/fedora_migrate/target_constructor.rb +39 -0
- data/lib/fedora_migrate/version.rb +1 -1
- data/spec/fixtures/objects/scholarsphere_5712mc568.xml +7284 -0
- data/spec/fixtures/objects/scholarsphere_7d279232g.xml +20120 -0
- data/spec/fixtures/objects/scholarsphere_sf2686078.xml +8823 -0
- data/spec/fixtures/objects/scholarsphere_x346dj04v.xml +188 -0
- data/spec/fixtures/objects/scholarsphere_x346dj06d.xml +255 -0
- data/spec/fixtures/objects/scholarsphere_x346dj08z.xml +1242 -0
- data/spec/fixtures/objects/sufia_5m60qr94g.xml +68 -0
- data/spec/fixtures/objects/sufia_5m60qr95r.xml +133 -0
- data/spec/fixtures/objects/sufia_5m60qr961.xml +133 -0
- data/spec/fixtures/objects/sufia_5m60qr979.xml +118 -0
- data/spec/integration/content_versions_spec.rb +24 -1
- data/spec/integration/missing_relationships_spec.rb +30 -0
- data/spec/integration/object_migration_spec.rb +49 -5
- data/spec/integration/rdf_migration_spec.rb +38 -13
- data/spec/integration/relationship_migration_spec.rb +10 -9
- data/spec/integration/repository_migration_spec.rb +46 -19
- data/spec/integration/versions_spec.rb +32 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/support/example_model.rb +56 -0
- data/spec/unit/content_mover_spec.rb +78 -0
- data/spec/unit/datastream_verification_spec.rb +60 -0
- data/spec/unit/dates_mover_spec.rb +33 -0
- data/spec/unit/migration_options_spec.rb +61 -0
- data/spec/unit/mover_spec.rb +35 -1
- data/spec/unit/object_mover_spec.rb +1 -3
- data/spec/unit/rels_ext_datastream_mover_spec.rb +28 -18
- data/spec/unit/repository_migrator_spec.rb +16 -5
- data/spec/unit/target_constructor_spec.rb +34 -0
- data/tasks/dev.rake +1 -1
- metadata +80 -38
- data/LICENSE.txt +0 -22
- data/lib/fedora_migrate/rdf_datastream_parser.rb +0 -29
- data/lib/fedora_migrate/triple_converter.rb +0 -39
- data/spec/fixtures/datastreams/rdf_ntriples_datastream.txt +0 -2
- data/spec/unit/rdf_datastream_mover_spec.rb +0 -8
- data/spec/unit/rdf_datastream_parser_spec.rb +0 -38
- data/spec/unit/triple_converter_spec.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c6f75dc48d80e784199985d948420c2c449de4
|
4
|
+
data.tar.gz: 0002dcb8c3e0508510359bc427c70cd2cf0b1f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc62419d71580ecda28950eea55ada46b397d517730eff12f3d3bdbfb3b184565a1499f8ec2e219d24f61395b7be42ea2f357b18ec772d4887b6706786a97301
|
7
|
+
data.tar.gz: e2adbf133dc201a4176958a53b83fe9dfc32351dfd59a72651e73ac527b4be01adf8ee762e76ac6233bb118b88daca67af1091ac4e09291fb2b888d28a56d4f6
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright © 2015 The Pennsylvania State University
|
2
|
+
Additional copyright may be held by others, as reflected in the commit history.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,22 +1,211 @@
|
|
1
|
-
# FedoraMigrate
|
1
|
+
# FedoraMigrate [](http://badge.fury.io/gh/projecthydra-labs%2Ffedora-migrate) [](https://travis-ci.org/projecthydra-labs/fedora-migrate)
|
2
2
|
|
3
3
|
Migrates content from a Fedora3 repository to a Fedora4 one.
|
4
4
|
|
5
5
|
## Status
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
This has been tested against Penn State's existing Scholarsphere applications, as well as generic Sufia applications.
|
8
|
+
Other uses are presently unknown.
|
9
9
|
|
10
|
-
##
|
10
|
+
## Overview
|
11
11
|
|
12
|
-
|
12
|
+
FedoraMigrate iterates over your existing Fedora3 application using the Rubydora gem. For each object it finds, it
|
13
|
+
creates a new object with the same id in Fedora4 and proceeds to migrate each datastream, including versions if
|
14
|
+
they are defined, and verifies the checksum of each. Permissions and relationships are migrated as well but using
|
15
|
+
different procedures due to the changes in Fedora4.
|
16
|
+
|
17
|
+
The entire migration process takes place in two steps. In the first, all objects, including datastreams and permissions,
|
18
|
+
are copied over to Fedora4; in the second, relationships are migrated.
|
19
|
+
|
20
|
+
## Requirements
|
21
|
+
|
22
|
+
1. A working Hydra application using Fedora4
|
23
|
+
2. An existing Fedora3 instance
|
24
|
+
3. All models defined in your Hydra/Fedora4 application
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Add the fedora-migrate gem to your existing Fedora4-based Hydra head
|
29
|
+
|
30
|
+
gem 'fedora-migrate'
|
31
|
+
|
32
|
+
Then run `bundle update`
|
33
|
+
|
34
|
+
Create a `config/fedora3.yml` file and point it to your current Fedora3 repository
|
35
|
+
|
36
|
+
development:
|
37
|
+
user: fedoraAdmin
|
38
|
+
password: fedoraAdmin
|
39
|
+
url: http://localhost:8983/fedora3
|
40
|
+
test:
|
41
|
+
user: fedoraAdmin
|
42
|
+
password: fedoraAdmin
|
43
|
+
url: http://localhost:8983/fedora3
|
44
|
+
production:
|
45
|
+
user: fedoraAdmin
|
46
|
+
password: fedoraAdmin
|
47
|
+
url: http://localhost:8983/fedora3
|
48
|
+
|
49
|
+
Create a rake task to migrate your repository. You can use the following, taken from `lib/tasks/fedora-migrate.rake`,
|
50
|
+
as an example:
|
51
|
+
|
52
|
+
``` ruby
|
53
|
+
desc "Migrate all my objects"
|
54
|
+
task migrate: :environment do
|
55
|
+
results = FedoraMigrate.migrate_repository(namespace: "mynamespace")
|
56
|
+
puts results
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
Run the task
|
61
|
+
|
62
|
+
$ bundle exec rake migrate
|
63
|
+
|
64
|
+
By default, messages are logged to your Rails environment logs.
|
65
|
+
|
66
|
+
## Configuration
|
67
|
+
|
68
|
+
FedoraMigrate uses your existing Hydra/Fedora4 application as the basis for migrating objects. For example,
|
69
|
+
given the model
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
class MyModel < ActiveFedora::Base
|
73
|
+
contains "content", class_name: "ActiveFedora::File"
|
74
|
+
contains "thumbnail", class_name: "ActiveFedora::File"
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
When the migrator finds an object in your Fedora3 repository that has the name _MyModel_ it attempts to instantiate the
|
79
|
+
object `MyModel` in the context of your Hydra application. Only the datastreams, or files, that are defined in the model will
|
80
|
+
be migrated from Fedora3. This means if your Fedora3 object has the datastream "special" but it is not in your Hydra
|
81
|
+
model, it will not be migrated. DC datastreams are not migrated by default, and RELS-EXT and rightsMetdata datastreams are treated
|
82
|
+
differently. See [FedoraMigrate::RelsExtDatastreamMover](lib/fedora_migrate/rels_ext_datastream_mover.rb) and
|
83
|
+
[FedoraMigrate::PermissionsMover](lib/fedora_migrate/permissions_mover.rb).
|
84
|
+
|
85
|
+
If your model contains a file or datastream that is versioned, then all versions of that datastream will be migrated from
|
86
|
+
Fedora3. If the model does not define something as versioned, yet the Fedora3 datastream is versioned, then only the current
|
87
|
+
version will be migrated to Fedora4.
|
88
|
+
|
89
|
+
### RDF Conversion
|
90
|
+
|
91
|
+
If you elect to do so, FedoraMigrate will attempt to convert ActiveFedora::NtriplesRDFDatastream objects into RDF properties
|
92
|
+
defined on your object. You can configure this as an option passed to the migrator.
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
FedoraMigrate.migrate_repository(namespace: "mynamespace", options: {convert: "descMetadata"})
|
96
|
+
```
|
97
|
+
|
98
|
+
However, you are required to define any and all RDF properties on your object in Hydra. For example, given
|
99
|
+
|
100
|
+
``` ruby
|
101
|
+
class RDFObject < ActiveFedora::Base
|
102
|
+
property :title, predicate: ::RDF::DC.title do |index|
|
103
|
+
index.as :stored_searchable, :facetable
|
104
|
+
end
|
105
|
+
contains "content", class_name: "ActiveFedora::File"
|
106
|
+
contains "thumbnail", class_name: "ActiveFedora::File"
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
If your descMetadata RDF datastream in Fedora3 contains the triple
|
111
|
+
|
112
|
+
<info:fedora/mynamespace:xp68km39w> <http://purl.org/dc/terms/title> "My Title" .
|
113
|
+
|
114
|
+
Then FedoraMigrate will define that property on your Fedora4 object using the DC term.
|
115
|
+
|
116
|
+
### Object Migration
|
117
|
+
|
118
|
+
By default, FedoraMigrate will use [FedoraMigrate::TargetConstructor](lib/fedora_migrate/target_constructor.rb)
|
119
|
+
to find a model in your Hydra application that matches
|
120
|
+
the Fedora3 source object. The constructor is designed to work with Hydra applications. If need be, you can override this
|
121
|
+
class by creating a new one that determines a model name based on your own criteria.
|
122
|
+
|
123
|
+
``` ruby
|
124
|
+
module FedoraMigrate
|
125
|
+
class TargetConstructor
|
126
|
+
|
127
|
+
attr_accessor :candidates, :target
|
128
|
+
|
129
|
+
def initialize candidates
|
130
|
+
@candidates = candidates
|
131
|
+
end
|
132
|
+
|
133
|
+
def build
|
134
|
+
# set target to whichever model you need based on candidates
|
135
|
+
return self
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
You can also opt to provide your own model, if you wish, by passing it as a second argument to the object mover class.
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
source = FedoraMigrate.source.connection.find("mynamespace:rb68xc089")
|
145
|
+
mover = FedoraMigrate::ObjectMover.new source, CustomObject.new
|
146
|
+
mover.migrate
|
147
|
+
```
|
148
|
+
|
149
|
+
### Configuration Hooks
|
150
|
+
|
151
|
+
Because the migration process will be different for each user, overridable methods are placed before and after each step in the
|
152
|
+
migration process. These can be used if your source or target objects need additional preparation before they can be
|
153
|
+
migrated. A good example is in Sufia, where a depositor must be applied before the object can be saved.
|
154
|
+
|
155
|
+
To use the hooks, simply define them in your migration task
|
156
|
+
|
157
|
+
``` ruby
|
158
|
+
module FedoraMigrate::Hooks
|
159
|
+
|
160
|
+
# Both @source and @target are available, as the Rubydora object and ActiveFedora model, respectively
|
161
|
+
|
162
|
+
# Apply depositor metadata before you migrate an object
|
163
|
+
def before_object_migration
|
164
|
+
xml = Nokogiri::XML(source.datastreams["properties"].content)
|
165
|
+
target.apply_depositor_metadata xml.xpath("//depositor").text
|
166
|
+
end
|
167
|
+
|
168
|
+
def after_object_migration
|
169
|
+
# additional actions as needed
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
desc "Migrate all my objects"
|
175
|
+
task migrate: :environment do
|
176
|
+
results = FedoraMigrate.migrate_repository(namespace: "mynamespace", options: {convert: "descMetadata"})
|
177
|
+
puts results
|
178
|
+
end
|
179
|
+
```
|
180
|
+
|
181
|
+
## Testing
|
182
|
+
|
183
|
+
Execute `bundle exec rake` to run the test suite.
|
184
|
+
|
185
|
+
$ bundle exec rake jetty:clean jetty:start
|
186
|
+
$ bundle exec rake fixtures:load
|
187
|
+
$ bundle exec rspec
|
188
|
+
|
189
|
+
This will run all the spec tests and leave jetty running if you wish to run specific tests.
|
190
|
+
|
191
|
+
If you have sample objects that you feel should be used as relevant testing examples, please add them to
|
192
|
+
`spec/fixtures/objects` and re-run the tests. Sample objects should be exported from existing Fedora3
|
193
|
+
repositories as foxml files using the "archive" option. This can be done via the admin web interface,
|
194
|
+
[http://localhost:8983/fedora3/admin](http://localhost:8983/fedora3/admin), or using
|
195
|
+
`FEDORA_HOME/client/bin/fedora-export.sh`.
|
196
|
+
|
197
|
+
*Note that the script option may only work under full installs of Fedora3 and not hydra-jetty.*
|
198
|
+
|
199
|
+
## TODOs and Reporting Errors
|
200
|
+
|
201
|
+
See the list of issues for current bugs and feature needs. Add your own as needed.
|
13
202
|
|
14
203
|
## Contributing
|
15
204
|
|
16
205
|
### Hydra Developers
|
17
206
|
|
18
207
|
For Hydra developers, or anyone with a signed CLA, please clone the repo and submit PRs via
|
19
|
-
|
208
|
+
feature branches. If you don't have rights to projecthydra-labs and do have a signed
|
20
209
|
CLA, please send a note to [email protected].
|
21
210
|
|
22
211
|
1. Clone it
|
@@ -29,3 +218,9 @@ CLA, please send a note to [email protected].
|
|
29
218
|
|
30
219
|
Anyone is welcome to use this software and report issues.
|
31
220
|
In order to merge any work contributed, you'll need to sign a contributor license agreement.
|
221
|
+
For more information on signing a CLA, please contact `[email protected]`
|
222
|
+
# Project Hydra
|
223
|
+
This software has been developed by and is brought to you by the Hydra community. Learn more at the
|
224
|
+
[Project Hydra website](http://projecthydra.org)
|
225
|
+
|
226
|
+

|
data/config/jetty.yml
CHANGED
data/fedora-migrate.gemspec
CHANGED
@@ -18,13 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
22
|
-
spec.add_dependency "
|
23
|
-
|
21
|
+
spec.add_dependency "hydra-head", "~> 9.0"
|
22
|
+
spec.add_dependency "rubydora", "~> 1.8"
|
23
|
+
spec.add_dependency "rchardet"
|
24
|
+
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "equivalent-xml"
|
27
|
+
spec.add_development_dependency "hydra-collections", "~> 4.0"
|
28
|
+
spec.add_development_dependency "jettywrapper"
|
25
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
30
|
spec.add_development_dependency "rspec"
|
27
|
-
spec.add_development_dependency "jettywrapper"
|
28
|
-
spec.add_development_dependency "equivalent-xml"
|
29
|
-
spec.add_development_dependency "sufia", "~> 6.0.0.beta1"
|
30
31
|
end
|
data/lib/fedora-migrate.rb
CHANGED
@@ -1,36 +1,19 @@
|
|
1
1
|
require "fedora_migrate/version"
|
2
2
|
require "active_support"
|
3
3
|
require "active_fedora"
|
4
|
-
require "hydra
|
4
|
+
require "hydra/head"
|
5
|
+
require "rubydora"
|
5
6
|
|
6
7
|
# Loads rake tasks
|
7
8
|
Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
|
8
9
|
|
9
|
-
# Shenanigans because we're not in a Rails environment and we need
|
10
|
-
# Hydra::AccessControls
|
11
|
-
Hydra::Engine.config.autoload_paths.each { |path| $LOAD_PATH.unshift path }
|
12
|
-
# in gem version 2.4, .find_by_name isn't pulling up gems given in the Gemfile
|
13
|
-
# as opposed to those in the gemspec file.
|
14
|
-
# This is a workaround:
|
15
|
-
Gem::Specification.all.each do |g|
|
16
|
-
HAC_DIR = g.gem_dir if g.name.match("hydra-access-controls")
|
17
|
-
end
|
18
|
-
require HAC_DIR+'/app/vocabularies/acl'
|
19
|
-
require HAC_DIR+'/app/vocabularies/hydra/acl'
|
20
|
-
require HAC_DIR+'/app/models/role_mapper'
|
21
|
-
require HAC_DIR+'/app/models/ability'
|
22
|
-
require HAC_DIR+'/app/models/hydra/access_controls/access_control_list'
|
23
|
-
require HAC_DIR+'/app/models/hydra/access_controls/permission'
|
24
|
-
require HAC_DIR+'/app/models/hydra/access_controls/embargo'
|
25
|
-
require HAC_DIR+'/app/models/hydra/access_controls/lease'
|
26
|
-
require HAC_DIR+'/app/services/hydra/lease_service'
|
27
|
-
require HAC_DIR+'/app/services/hydra/embargo_service'
|
28
|
-
require HAC_DIR+'/app/validators/hydra/future_date_validator'
|
29
|
-
|
30
10
|
module FedoraMigrate
|
31
11
|
extend ActiveSupport::Autoload
|
32
12
|
|
13
|
+
autoload :ContentMover
|
33
14
|
autoload :DatastreamMover
|
15
|
+
autoload :DatastreamVerification
|
16
|
+
autoload :DatesMover
|
34
17
|
autoload :Errors
|
35
18
|
autoload :FileConfigurator
|
36
19
|
autoload :Hooks
|
@@ -46,6 +29,7 @@ module FedoraMigrate
|
|
46
29
|
autoload :RepositoryMigrator
|
47
30
|
autoload :RightsMetadata
|
48
31
|
autoload :RubydoraConnection
|
32
|
+
autoload :TargetConstructor
|
49
33
|
autoload :TripleConverter
|
50
34
|
|
51
35
|
class << self
|
@@ -62,7 +46,7 @@ module FedoraMigrate
|
|
62
46
|
|
63
47
|
def source
|
64
48
|
@source ||= FedoraMigrate::RubydoraConnection.new(fedora_config.credentials)
|
65
|
-
end
|
49
|
+
end
|
66
50
|
|
67
51
|
def find id
|
68
52
|
FedoraMigrate.source.connection.find(id)
|
@@ -72,7 +56,6 @@ module FedoraMigrate
|
|
72
56
|
migrator = FedoraMigrate::RepositoryMigrator.new(args[:namespace], args[:options])
|
73
57
|
migrator.migrate_objects
|
74
58
|
migrator.migrate_relationships
|
75
|
-
migrator.results
|
76
59
|
end
|
77
60
|
|
78
61
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module FedoraMigrate
|
2
|
+
class ContentMover < Mover
|
3
|
+
|
4
|
+
def migrate
|
5
|
+
return nil_content_message if source.content.nil?
|
6
|
+
move_content
|
7
|
+
insert_date_created_by_application
|
8
|
+
end
|
9
|
+
|
10
|
+
def move_content
|
11
|
+
target.content = source.content
|
12
|
+
target.original_name = source.label.try(:gsub, /"/, '\"')
|
13
|
+
target.mime_type = source.mimeType
|
14
|
+
Logger.info "#{target.inspect}"
|
15
|
+
save
|
16
|
+
end
|
17
|
+
|
18
|
+
def insert_date_created_by_application
|
19
|
+
result = perform_sparql_insert
|
20
|
+
return true if result.status == 204
|
21
|
+
raise FedoraMigrate::Errors::MigrationError, "problem with sparql #{result.status} #{result.body}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def sparql_insert
|
25
|
+
<<-EOF
|
26
|
+
PREFIX premis: <http://www.loc.gov/premis/rdf/v1#>
|
27
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
28
|
+
DELETE WHERE { ?s premis:hasDateCreatedByApplication ?o } ;
|
29
|
+
INSERT {
|
30
|
+
<> premis:hasDateCreatedByApplication "#{source.createDate.iso8601}"^^xsd:dateTime .
|
31
|
+
}
|
32
|
+
WHERE { }
|
33
|
+
EOF
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def nil_content_message
|
39
|
+
Logger.info "datastream '#{source.dsid}' is nil. It's probably defined in the target but not present in the source"
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def perform_sparql_insert
|
44
|
+
ActiveFedora.fedora.connection.patch(target.metadata.metadata_uri, sparql_insert, "Content-Type" => "application/sparql-update")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module FedoraMigrate
|
2
2
|
class DatastreamMover < Mover
|
3
3
|
|
4
|
+
include DatastreamVerification
|
5
|
+
|
4
6
|
attr_accessor :versionable
|
5
7
|
|
6
8
|
def post_initialize
|
@@ -14,12 +16,20 @@ module FedoraMigrate
|
|
14
16
|
def target_versionable?
|
15
17
|
if target.respond_to?(:versionable?)
|
16
18
|
target.versionable?
|
17
|
-
else
|
19
|
+
else
|
18
20
|
false
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
23
|
+
|
22
24
|
def migrate
|
25
|
+
before_datastream_migration
|
26
|
+
migrate_datastream
|
27
|
+
after_datastream_migration
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def migrate_datastream
|
23
33
|
if versionable?
|
24
34
|
migrate_versions
|
25
35
|
else
|
@@ -27,50 +37,25 @@ module FedoraMigrate
|
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
# Reloading the target, otherwise #get_checksum is nil
|
40
|
+
# Reload the target, otherwise the checksum is nil
|
33
41
|
def migrate_current
|
34
42
|
migrate_content
|
35
43
|
target.reload
|
36
|
-
|
44
|
+
valid?
|
37
45
|
end
|
38
46
|
|
47
|
+
# Rubydora stores the versions array as the most recent first. We explicitly sort them according to createDate
|
39
48
|
def migrate_versions
|
40
|
-
source.versions.each do |version|
|
49
|
+
source.versions.sort { |a,b| a.createDate <=> b.createDate }.each do |version|
|
41
50
|
migrate_content(version)
|
42
|
-
target.create_version
|
43
|
-
|
51
|
+
target.create_version unless application_creates_versions?
|
52
|
+
valid?(version)
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
47
|
-
# TODO: lastModified isn't the right place for the original creation date (issue #1)
|
48
56
|
def migrate_content datastream=nil
|
49
57
|
datastream ||= source
|
50
|
-
|
51
|
-
Logger.info "datastream '#{datastream.dsid}' is nil. It's probably defined in the target but not present in the source"
|
52
|
-
return true
|
53
|
-
end
|
54
|
-
target.content = datastream.content
|
55
|
-
target.original_name = datastream.label
|
56
|
-
target.mime_type = datastream.mimeType
|
57
|
-
target.last_modified = datastream.createDate
|
58
|
-
Logger.info "#{target.inspect}"
|
59
|
-
save
|
60
|
-
end
|
61
|
-
|
62
|
-
# TODO: Reporting mechanism? If there isn't a checksum it defaults to "none" (issue #4)
|
63
|
-
def verify datastream=nil
|
64
|
-
datastream ||= source
|
65
|
-
target_checksum = get_checksum
|
66
|
-
return true if datastream.checksum == "none"
|
67
|
-
unless datastream.checksum == target_checksum.split(/:/).last
|
68
|
-
Logger.fatal "expected #{datastream.dsid} #{datastream.checksumType} #{datastream.checksum} to match #{target_checksum}"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_checksum
|
73
|
-
target.digest.first.to_s
|
58
|
+
FedoraMigrate::ContentMover.new(datastream, target).migrate
|
74
59
|
end
|
75
60
|
|
76
61
|
end
|