fedora-migrate 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -8
  4. data/README.md +3 -1
  5. data/fedora-migrate.gemspec +2 -2
  6. data/lib/fedora_migrate/file_configurator.rb +1 -1
  7. data/lib/fedora_migrate/migration_options.rb +5 -0
  8. data/lib/fedora_migrate/migration_report.rb +32 -6
  9. data/lib/fedora_migrate/repository_migrator.rb +53 -30
  10. data/lib/fedora_migrate/version.rb +1 -1
  11. data/spec/fixtures/reports/failed/sufia_5m60qr94g.json +7 -0
  12. data/spec/fixtures/reports/failed/sufia_5m60qr95r.json +58 -0
  13. data/spec/fixtures/reports/failed/sufia_5m60qr961.json +58 -0
  14. data/spec/fixtures/reports/failed/sufia_5m60qr979.json +34 -0
  15. data/spec/fixtures/reports/failed/sufia_rb68xc089.json +7 -0
  16. data/spec/fixtures/reports/failed/sufia_rb68xc09k.json +21 -0
  17. data/spec/fixtures/reports/failed/sufia_rb68xc10b.json +49 -0
  18. data/spec/fixtures/reports/failed/sufia_rb68xc11m.json +49 -0
  19. data/spec/fixtures/reports/failed/sufia_xp68km39w.json +54 -0
  20. data/spec/fixtures/reports/sample/scholarsphere_000000000.json +26 -0
  21. data/spec/fixtures/reports/sample/scholarsphere_000000018.json +102 -0
  22. data/spec/fixtures/reports/sample/scholarsphere_05741r698.json +26 -0
  23. data/spec/fixtures/reports/sample/scholarsphere_6395wb555.json +5 -0
  24. data/spec/fixtures/reports/sample/scholarsphere_x346dm27k.json +5 -0
  25. data/spec/integration/repository_migration_spec.rb +21 -10
  26. data/spec/integration/versions_spec.rb +1 -0
  27. data/spec/spec_helper.rb +1 -0
  28. data/spec/support/example_model.rb +8 -1
  29. data/spec/unit/migration_options_spec.rb +18 -0
  30. data/spec/unit/migration_report_spec.rb +16 -13
  31. data/spec/unit/repository_migrator_spec.rb +2 -8
  32. metadata +35 -11
  33. data/spec/fixtures/failed-report.json +0 -339
  34. data/spec/fixtures/sample-report.json +0 -166
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce0bad9581c3b5b080d0a73a26792ee7942ce1b3
4
- data.tar.gz: 79932ebfe5726d0ef5dd67b1a5598847ed056175
3
+ metadata.gz: 127fba59aedee21753a2ab76236f32f9fd405dc3
4
+ data.tar.gz: 18b7cafa6247b840afcf79924565859333d99c2c
5
5
  SHA512:
6
- metadata.gz: 79d5f57909a5a92ea9155b6b09b2e85733df39212e62e9c227e9732d5c5eeb8c286e1c8905c52fb40d511e8c5641568c763327405593bf1c2583ef97e0a81222
7
- data.tar.gz: 5a57b9afc653f14a33dcffaad44fc15bd5c9cde314b785e866b2786d8af92336dcfc8bcb212e24362cc6f7162e599bd9b7b41f0cd43761d6f26f23da0effab01
6
+ metadata.gz: 468b7a0174d44e48b7c8b4d55c8ed6036e835a73e55cf3076f378806477e940c1cee5ebe96476cb6316a6582746d8dd5ace72f51c03813dcb56ad4cc500e9683
7
+ data.tar.gz: 0d961a07e3c4dc51691b5caa0c28065d6900b4c8dbe15c8d4e97ca1a8fe6f2a770d366894ec8b6c0b80e4cf225daccd568e94633f13cef6faa1f95d93c76f10d
data/.gitignore CHANGED
@@ -15,4 +15,4 @@ mkmf.log
15
15
  jetty
16
16
  .ruby-version
17
17
  .rvmrc
18
- report.json
18
+ migration_report
@@ -1,19 +1,17 @@
1
1
  language: ruby
2
+ cache: bundler
3
+ sudo: false
2
4
  rvm:
3
- - 2.1
4
- - 2.0
5
+ - 2.2
5
6
  env:
6
7
  global:
7
- - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
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(namespace: "mynamespace")
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
@@ -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.0"
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", "~> 4.0"
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 = get_config_path(:fedora3)
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
@@ -18,6 +18,11 @@ module FedoraMigrate
18
18
  def application_creates_versions?
19
19
  option_true?(:application_creates_versions)
20
20
  end
21
+
22
+ def blacklist
23
+ return [] if options.nil?
24
+ options.fetch(:blacklist, [])
25
+ end
21
26
 
22
27
  private
23
28
 
@@ -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
- def initialize report=nil
7
- @results = report.nil? ? Hash.new : JSON.parse(File.read(report))
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
- def save path=nil
34
- json = JSON.load(results.to_json)
35
- file = path.nil? ? "report.json" : File.join(path,"report.json")
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 { |source| migrate_object(source) }
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 { |source| migrate_relationship(source) }
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
- if report.empty?
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 source
42
- object_report = SingleObjectReport.new
43
- begin
44
- object_report.object = FedoraMigrate::ObjectMover.new(source, nil, options).migrate
45
- object_report.status = true
46
- rescue StandardError => e
47
- object_report.object = e.inspect
48
- object_report.status = false
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 source
54
- relationship_report = find_or_create_single_object_report(source)
55
- begin
56
- relationship_report.relationships = FedoraMigrate::RelsExtDatastreamMover.new(source).migrate
57
- relationship_report.status = true
58
- rescue StandardError => e
59
- relationship_report.relationships = e.inspect
60
- relationship_report.status = false
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 find_or_create_single_object_report source
75
- report.results[source.pid] || SingleObjectReport.new
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
@@ -1,3 +1,3 @@
1
1
  module FedoraMigrate
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ {
2
+ "status": false,
3
+ "object": "Sample object migration failure",
4
+ "relationships": [
5
+
6
+ ]
7
+ }
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "status": false,
3
+ "object": "Sample object migration failure",
4
+ "relationships": [
5
+
6
+ ]
7
+ }