fedora-migrate 0.2.0 → 0.3.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 -1
- data/.travis.yml +6 -8
- data/README.md +3 -1
- data/fedora-migrate.gemspec +2 -2
- data/lib/fedora_migrate/file_configurator.rb +1 -1
- data/lib/fedora_migrate/migration_options.rb +5 -0
- data/lib/fedora_migrate/migration_report.rb +32 -6
- data/lib/fedora_migrate/repository_migrator.rb +53 -30
- data/lib/fedora_migrate/version.rb +1 -1
- data/spec/fixtures/reports/failed/sufia_5m60qr94g.json +7 -0
- data/spec/fixtures/reports/failed/sufia_5m60qr95r.json +58 -0
- data/spec/fixtures/reports/failed/sufia_5m60qr961.json +58 -0
- data/spec/fixtures/reports/failed/sufia_5m60qr979.json +34 -0
- data/spec/fixtures/reports/failed/sufia_rb68xc089.json +7 -0
- data/spec/fixtures/reports/failed/sufia_rb68xc09k.json +21 -0
- data/spec/fixtures/reports/failed/sufia_rb68xc10b.json +49 -0
- data/spec/fixtures/reports/failed/sufia_rb68xc11m.json +49 -0
- data/spec/fixtures/reports/failed/sufia_xp68km39w.json +54 -0
- data/spec/fixtures/reports/sample/scholarsphere_000000000.json +26 -0
- data/spec/fixtures/reports/sample/scholarsphere_000000018.json +102 -0
- data/spec/fixtures/reports/sample/scholarsphere_05741r698.json +26 -0
- data/spec/fixtures/reports/sample/scholarsphere_6395wb555.json +5 -0
- data/spec/fixtures/reports/sample/scholarsphere_x346dm27k.json +5 -0
- data/spec/integration/repository_migration_spec.rb +21 -10
- data/spec/integration/versions_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/example_model.rb +8 -1
- data/spec/unit/migration_options_spec.rb +18 -0
- data/spec/unit/migration_report_spec.rb +16 -13
- data/spec/unit/repository_migrator_spec.rb +2 -8
- metadata +35 -11
- data/spec/fixtures/failed-report.json +0 -339
- data/spec/fixtures/sample-report.json +0 -166
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 127fba59aedee21753a2ab76236f32f9fd405dc3
|
4
|
+
data.tar.gz: 18b7cafa6247b840afcf79924565859333d99c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 468b7a0174d44e48b7c8b4d55c8ed6036e835a73e55cf3076f378806477e940c1cee5ebe96476cb6316a6582746d8dd5ace72f51c03813dcb56ad4cc500e9683
|
7
|
+
data.tar.gz: 0d961a07e3c4dc51691b5caa0c28065d6900b4c8dbe15c8d4e97ca1a8fe6f2a770d366894ec8b6c0b80e4cf225daccd568e94633f13cef6faa1f95d93c76f10d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
sudo: false
|
2
4
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.0
|
5
|
+
- 2.2
|
5
6
|
env:
|
6
7
|
global:
|
7
|
-
|
8
|
+
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
8
9
|
notifications:
|
9
|
-
email:
|
10
|
-
recipients:
|
11
|
-
- "ul-dlt-hydra@lists.psu.edu"
|
12
|
-
on_success: "change"
|
13
|
-
on_failure: "always"
|
14
10
|
irc:
|
15
11
|
channels:
|
16
12
|
- "irc.freenode.org#scholarsphere"
|
17
13
|
- "irc.freenode.org#projecthydra"
|
18
14
|
template:
|
19
15
|
- "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
|
16
|
+
before_script:
|
17
|
+
- jdk_switcher use oraclejdk8
|
data/README.md
CHANGED
@@ -52,11 +52,13 @@ as an example:
|
|
52
52
|
``` ruby
|
53
53
|
desc "Migrate all my objects"
|
54
54
|
task migrate: :environment do
|
55
|
-
results = FedoraMigrate.migrate_repository(
|
55
|
+
results = FedoraMigrate.migrate_repository("mynamespace")
|
56
56
|
puts results
|
57
57
|
end
|
58
58
|
```
|
59
59
|
|
60
|
+
Where `mynamespace` is your Fedora 3 pid namespace.
|
61
|
+
|
60
62
|
Run the task
|
61
63
|
|
62
64
|
$ bundle exec rake migrate
|
data/fedora-migrate.gemspec
CHANGED
@@ -18,13 +18,13 @@ 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 "hydra-head", "~> 9.
|
21
|
+
spec.add_dependency "hydra-head", "~> 9.5"
|
22
22
|
spec.add_dependency "rubydora", "~> 1.8"
|
23
23
|
spec.add_dependency "rchardet"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
26
|
spec.add_development_dependency "equivalent-xml"
|
27
|
-
spec.add_development_dependency "hydra-collections", "~>
|
27
|
+
spec.add_development_dependency "hydra-collections", "~> 5.0"
|
28
28
|
spec.add_development_dependency "jettywrapper"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "rspec"
|
@@ -8,7 +8,7 @@ module FedoraMigrate
|
|
8
8
|
|
9
9
|
def load_fedora3_config
|
10
10
|
return @fedora_config unless @fedora_config.empty?
|
11
|
-
@fedora_config_path =
|
11
|
+
@fedora_config_path = config_path(:fedora3)
|
12
12
|
Logger.info("loading fedora config from #{::File.expand_path(@fedora_config_path)}")
|
13
13
|
|
14
14
|
begin
|
@@ -1,10 +1,18 @@
|
|
1
1
|
module FedoraMigrate
|
2
2
|
class MigrationReport
|
3
3
|
|
4
|
-
attr_accessor :results
|
4
|
+
attr_accessor :path, :results
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
DEFAULT_PATH = "migration_report".freeze
|
7
|
+
|
8
|
+
def initialize path=nil
|
9
|
+
@path = path.nil? ? DEFAULT_PATH : path
|
10
|
+
FileUtils::mkdir_p(@path)
|
11
|
+
reload
|
12
|
+
end
|
13
|
+
|
14
|
+
def reload
|
15
|
+
@results = load_results_from_directory
|
8
16
|
end
|
9
17
|
|
10
18
|
def empty?
|
@@ -30,11 +38,29 @@ module FedoraMigrate
|
|
30
38
|
output
|
31
39
|
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
file =
|
41
|
+
# Receives and individual report and writes it to the MigrationReport directory
|
42
|
+
def save pid, report
|
43
|
+
file = File.join(path,file_from_pid(pid))
|
44
|
+
json = JSON.load(report.to_json)
|
36
45
|
File.write(file, JSON.pretty_generate(json))
|
37
46
|
end
|
38
47
|
|
48
|
+
private
|
49
|
+
|
50
|
+
def load_results_from_directory assembled = Hash.new
|
51
|
+
Dir.glob(File.join(path,"*.json")).each do |file|
|
52
|
+
assembled[pid_from_file(file)] = JSON.parse(File.read(file))
|
53
|
+
end
|
54
|
+
assembled
|
55
|
+
end
|
56
|
+
|
57
|
+
def pid_from_file file
|
58
|
+
File.basename(file, ".*").gsub(/_/,":")
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_from_pid pid
|
62
|
+
pid.gsub(/:/,"_")+".json"
|
63
|
+
end
|
64
|
+
|
39
65
|
end
|
40
66
|
end
|
@@ -3,7 +3,7 @@ module FedoraMigrate
|
|
3
3
|
|
4
4
|
include MigrationOptions
|
5
5
|
|
6
|
-
attr_accessor :source_objects, :namespace, :report
|
6
|
+
attr_accessor :source_objects, :namespace, :report, :source, :result
|
7
7
|
|
8
8
|
SingleObjectReport = Struct.new(:status, :object, :relationships)
|
9
9
|
|
@@ -16,20 +16,36 @@ module FedoraMigrate
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def migrate_objects
|
19
|
-
source_objects.each
|
19
|
+
source_objects.each do |object|
|
20
|
+
@source = object
|
21
|
+
migrate_current_object
|
22
|
+
end
|
23
|
+
report.reload
|
24
|
+
end
|
25
|
+
|
26
|
+
def migrate_current_object
|
27
|
+
return unless migration_required?
|
28
|
+
initialize_report
|
29
|
+
migrate_object
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize_report
|
33
|
+
@result = SingleObjectReport.new
|
34
|
+
@result.status = false
|
35
|
+
report.save(source.pid, @result)
|
20
36
|
end
|
21
37
|
|
22
38
|
def migrate_relationships
|
23
39
|
return "Relationship migration halted because #{failures.to_s} objects didn't migrate successfully." if failures > 0 && not_forced?
|
24
|
-
source_objects.each
|
40
|
+
source_objects.each do |object|
|
41
|
+
@source = object
|
42
|
+
@result = find_or_create_single_object_report
|
43
|
+
migrate_relationship unless blacklist.include?(source.pid)
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
47
|
def get_source_objects
|
28
|
-
|
29
|
-
FedoraMigrate.source.connection.search(nil).collect { |o| qualifying_object(o) }.compact
|
30
|
-
else
|
31
|
-
report.failed_objects.map { |o| FedoraMigrate.source.connection.find(o) }
|
32
|
-
end
|
48
|
+
FedoraMigrate.source.connection.search(nil).collect { |o| qualifying_object(o) }.compact
|
33
49
|
end
|
34
50
|
|
35
51
|
def failures
|
@@ -38,28 +54,24 @@ module FedoraMigrate
|
|
38
54
|
|
39
55
|
private
|
40
56
|
|
41
|
-
def migrate_object
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
report.results[source.pid] = object_report
|
57
|
+
def migrate_object
|
58
|
+
result.object = FedoraMigrate::ObjectMover.new(source, nil, options).migrate
|
59
|
+
result.status = true
|
60
|
+
rescue StandardError => e
|
61
|
+
result.object = e.inspect
|
62
|
+
result.status = false
|
63
|
+
ensure
|
64
|
+
report.save(source.pid, result)
|
51
65
|
end
|
52
66
|
|
53
|
-
def migrate_relationship
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
report.results[source.pid] = relationship_report
|
67
|
+
def migrate_relationship
|
68
|
+
result.relationships = FedoraMigrate::RelsExtDatastreamMover.new(source).migrate
|
69
|
+
result.status = true
|
70
|
+
rescue StandardError => e
|
71
|
+
result.relationships = e.inspect
|
72
|
+
result.status = false
|
73
|
+
ensure
|
74
|
+
report.save(source.pid, result)
|
63
75
|
end
|
64
76
|
|
65
77
|
def repository_namespace
|
@@ -71,8 +83,19 @@ module FedoraMigrate
|
|
71
83
|
return object if name.match(namespace)
|
72
84
|
end
|
73
85
|
|
74
|
-
def
|
75
|
-
|
86
|
+
def migration_required?
|
87
|
+
return false if blacklist.include?(source.pid)
|
88
|
+
return true if report.results[source.pid].nil?
|
89
|
+
!report.results[source.pid]["status"]
|
76
90
|
end
|
91
|
+
|
92
|
+
def find_or_create_single_object_report
|
93
|
+
if report.results[source.pid].nil?
|
94
|
+
SingleObjectReport.new
|
95
|
+
else
|
96
|
+
SingleObjectReport.new(report.results[source.pid]["status"],report.results[source.pid]["object"],report.results[source.pid]["relationships"])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
77
100
|
end
|
78
101
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"status": true,
|
3
|
+
"object": {
|
4
|
+
"id": "5m60qr95r",
|
5
|
+
"class": "GenericFile",
|
6
|
+
"content_datastreams": [
|
7
|
+
{
|
8
|
+
"ds": "content",
|
9
|
+
"versions": [
|
10
|
+
{
|
11
|
+
"name": "file2.txt",
|
12
|
+
"mime_type": "text/plain",
|
13
|
+
"original_date": "2015-01-19T21:32:47Z"
|
14
|
+
}
|
15
|
+
]
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"ds": "thumbnail",
|
19
|
+
"versions": [
|
20
|
+
{
|
21
|
+
"error": "Nil source -- it's probably defined in the target but not present in the source"
|
22
|
+
}
|
23
|
+
]
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"ds": "characterization",
|
27
|
+
"versions": [
|
28
|
+
{
|
29
|
+
"error": "Nil source -- it's probably defined in the target but not present in the source"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"rdf_datastreams": [
|
35
|
+
{
|
36
|
+
"ds": "descMetadata",
|
37
|
+
"status": [
|
38
|
+
|
39
|
+
]
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"permissions": [
|
43
|
+
"read_groups = []",
|
44
|
+
"edit_groups = []",
|
45
|
+
"discover_groups = []",
|
46
|
+
"read_users = []",
|
47
|
+
"edit_users = [\"awead@psu.edu\"]",
|
48
|
+
"discover_users = []"
|
49
|
+
],
|
50
|
+
"dates": {
|
51
|
+
"uploaded": null,
|
52
|
+
"modified": null
|
53
|
+
}
|
54
|
+
},
|
55
|
+
"relationships": [
|
56
|
+
"http://localhost:8983/fedora/rest/test/5m60qr95r--info:fedora/fedora-system:def/relations-external#isPartOf--http://localhost:8983/fedora/rest/test/5m60qr94g"
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"status": true,
|
3
|
+
"object": {
|
4
|
+
"id": "5m60qr961",
|
5
|
+
"class": "GenericFile",
|
6
|
+
"content_datastreams": [
|
7
|
+
{
|
8
|
+
"ds": "content",
|
9
|
+
"versions": [
|
10
|
+
{
|
11
|
+
"name": "file1.txt",
|
12
|
+
"mime_type": "text/plain",
|
13
|
+
"original_date": "2015-01-19T21:32:49Z"
|
14
|
+
}
|
15
|
+
]
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"ds": "thumbnail",
|
19
|
+
"versions": [
|
20
|
+
{
|
21
|
+
"error": "Nil source -- it's probably defined in the target but not present in the source"
|
22
|
+
}
|
23
|
+
]
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"ds": "characterization",
|
27
|
+
"versions": [
|
28
|
+
{
|
29
|
+
"error": "Nil source -- it's probably defined in the target but not present in the source"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"rdf_datastreams": [
|
35
|
+
{
|
36
|
+
"ds": "descMetadata",
|
37
|
+
"status": [
|
38
|
+
|
39
|
+
]
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"permissions": [
|
43
|
+
"read_groups = []",
|
44
|
+
"edit_groups = []",
|
45
|
+
"discover_groups = []",
|
46
|
+
"read_users = []",
|
47
|
+
"edit_users = [\"awead@psu.edu\"]",
|
48
|
+
"discover_users = []"
|
49
|
+
],
|
50
|
+
"dates": {
|
51
|
+
"uploaded": null,
|
52
|
+
"modified": null
|
53
|
+
}
|
54
|
+
},
|
55
|
+
"relationships": [
|
56
|
+
"http://localhost:8983/fedora/rest/test/5m60qr961--info:fedora/fedora-system:def/relations-external#isPartOf--http://localhost:8983/fedora/rest/test/5m60qr94g"
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"status": true,
|
3
|
+
"object": {
|
4
|
+
"id": "5m60qr979",
|
5
|
+
"class": "Collection",
|
6
|
+
"content_datastreams": [
|
7
|
+
|
8
|
+
],
|
9
|
+
"rdf_datastreams": [
|
10
|
+
{
|
11
|
+
"ds": "descMetadata",
|
12
|
+
"status": [
|
13
|
+
|
14
|
+
]
|
15
|
+
}
|
16
|
+
],
|
17
|
+
"permissions": [
|
18
|
+
"read_groups = [\"public\"]",
|
19
|
+
"edit_groups = []",
|
20
|
+
"discover_groups = []",
|
21
|
+
"read_users = []",
|
22
|
+
"edit_users = [\"awead@psu.edu\"]",
|
23
|
+
"discover_users = []"
|
24
|
+
],
|
25
|
+
"dates": {
|
26
|
+
"uploaded": "2015-01-19T21:34:23.805Z",
|
27
|
+
"modified": "2015-03-03T18:48:51.16Z"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"relationships": [
|
31
|
+
"http://localhost:8983/fedora/rest/test/5m60qr979--info:fedora/fedora-system:def/relations-external#hasCollectionMember--http://localhost:8983/fedora/rest/test/5m60qr95r",
|
32
|
+
"http://localhost:8983/fedora/rest/test/5m60qr979--info:fedora/fedora-system:def/relations-external#hasCollectionMember--http://localhost:8983/fedora/rest/test/5m60qr961"
|
33
|
+
]
|
34
|
+
}
|