rof 1.0.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -7
  3. data/LICENSE +201 -16
  4. data/Rakefile +46 -0
  5. data/bin/csv_to_rof +1 -2
  6. data/bin/fedora_to_rof +7 -1
  7. data/bin/jsonld_to_rof +26 -0
  8. data/bin/osf_to_rof +6 -2
  9. data/bin/rof +5 -19
  10. data/lib/rof.rb +2 -6
  11. data/lib/rof/access.rb +1 -1
  12. data/lib/rof/cli.rb +104 -67
  13. data/lib/rof/compare_rof.rb +68 -39
  14. data/lib/rof/filter.rb +21 -0
  15. data/lib/rof/filters.rb +38 -0
  16. data/lib/rof/filters/bendo.rb +15 -17
  17. data/lib/rof/filters/date_stamp.rb +5 -4
  18. data/lib/rof/filters/file_to_url.rb +5 -3
  19. data/lib/rof/filters/label.rb +9 -7
  20. data/lib/rof/filters/work.rb +7 -5
  21. data/lib/rof/ingest.rb +5 -0
  22. data/lib/rof/osf_context.rb +2 -2
  23. data/lib/rof/rdf_context.rb +2 -0
  24. data/lib/rof/translator.rb +18 -0
  25. data/lib/rof/translators.rb +23 -0
  26. data/lib/rof/{translate_csv.rb → translators/csv_to_rof.rb} +4 -3
  27. data/lib/rof/translators/fedora_to_rof.rb +244 -0
  28. data/lib/rof/translators/jsonld_to_rof.rb +112 -0
  29. data/lib/rof/translators/jsonld_to_rof/accumulator.rb +175 -0
  30. data/lib/rof/translators/jsonld_to_rof/predicate_handler.rb +223 -0
  31. data/lib/rof/translators/jsonld_to_rof/predicate_object_handler.rb +125 -0
  32. data/lib/rof/translators/jsonld_to_rof/statement_handler.rb +91 -0
  33. data/lib/rof/translators/osf_to_rof.rb +191 -0
  34. data/lib/rof/utility.rb +44 -1
  35. data/lib/rof/version.rb +1 -1
  36. data/rof.gemspec +10 -2
  37. data/spec/coverage_helper.rb +17 -0
  38. data/spec/fixtures/for_utility_load_items_from_json_file/multiple_items.json +8 -0
  39. data/spec/fixtures/for_utility_load_items_from_json_file/parse_error.json +3 -0
  40. data/spec/fixtures/for_utility_load_items_from_json_file/single_item.json +3 -0
  41. data/spec/fixtures/jsonld_to_rof/0g354f18610.jsonld +113 -0
  42. data/spec/fixtures/jsonld_to_rof/0g354f18610.rof +96 -0
  43. data/spec/fixtures/jsonld_to_rof/2j62s467216.jsonld +113 -0
  44. data/spec/fixtures/jsonld_to_rof/2j62s467216.rof +93 -0
  45. data/spec/fixtures/jsonld_to_rof/2v23vt16z2z.jsonld +70 -0
  46. data/spec/fixtures/jsonld_to_rof/2v23vt16z2z.rof +87 -0
  47. data/spec/fixtures/jsonld_to_rof/cr56n01253w.jsonld +84 -0
  48. data/spec/fixtures/jsonld_to_rof/cr56n01253w.rof +95 -0
  49. data/spec/fixtures/jsonld_to_rof/h989r21069m.jsonld +84 -0
  50. data/spec/fixtures/jsonld_to_rof/h989r21069m.rof +98 -0
  51. data/spec/fixtures/jsonld_to_rof/js956d59913.jsonld +79 -0
  52. data/spec/fixtures/jsonld_to_rof/js956d59913.rof +89 -0
  53. data/spec/fixtures/jsonld_to_rof/m039k358q5c.jsonld +80 -0
  54. data/spec/fixtures/jsonld_to_rof/m039k358q5c.rof +64 -0
  55. data/spec/fixtures/jsonld_to_rof/nk322b9161g.jsonld +89 -0
  56. data/spec/fixtures/jsonld_to_rof/nk322b9161g.rof +69 -0
  57. data/spec/fixtures/jsonld_to_rof/p8418k7430d.jsonld +84 -0
  58. data/spec/fixtures/jsonld_to_rof/p8418k7430d.rof +67 -0
  59. data/spec/fixtures/jsonld_to_rof/xg94hm53h0c.jsonld +98 -0
  60. data/spec/fixtures/jsonld_to_rof/xg94hm53h0c.rof +110 -0
  61. data/spec/fixtures/jsonld_to_rof/zk51vd69n1r.jsonld +94 -0
  62. data/spec/fixtures/jsonld_to_rof/zk51vd69n1r.rof +121 -0
  63. data/spec/fixtures/osf/phz6b.tar.gz +0 -0
  64. data/spec/lib/rof/access_spec.rb +30 -23
  65. data/spec/lib/rof/cli_spec.rb +83 -60
  66. data/spec/lib/rof/compare_rof_spec.rb +35 -24
  67. data/spec/lib/rof/filter_spec.rb +10 -0
  68. data/spec/lib/rof/filters/bendo_spec.rb +42 -0
  69. data/spec/lib/rof/filters/date_stamp_spec.rb +9 -5
  70. data/spec/lib/rof/filters/file_to_url_spec.rb +7 -3
  71. data/spec/lib/rof/filters/label_spec.rb +121 -77
  72. data/spec/lib/rof/filters/work_spec.rb +7 -4
  73. data/spec/lib/rof/filters_spec.rb +14 -0
  74. data/spec/lib/rof/translator_spec.rb +15 -0
  75. data/spec/lib/rof/{translate_csv_spec.rb → translators/csv_to_rof_spec.rb} +14 -14
  76. data/spec/lib/rof/translators/fedora_to_rof_spec.rb +64 -0
  77. data/spec/lib/rof/translators/jsonld_to_rof/accumulator_spec.rb +121 -0
  78. data/spec/lib/rof/translators/jsonld_to_rof/predicate_handler_spec.rb +73 -0
  79. data/spec/lib/rof/translators/jsonld_to_rof/predicate_object_handler_spec.rb +48 -0
  80. data/spec/lib/rof/translators/jsonld_to_rof/statement_handler_spec.rb +40 -0
  81. data/spec/lib/rof/translators/jsonld_to_rof_spec.rb +120 -0
  82. data/spec/lib/rof/{osf_to_rof_spec.rb → translators/osf_to_rof_spec.rb} +55 -25
  83. data/spec/lib/rof/translators_spec.rb +14 -0
  84. data/spec/lib/rof/utility_spec.rb +47 -1
  85. data/spec/spec_helper.rb +1 -1
  86. data/spec/support/an_rof_filter.rb +10 -0
  87. metadata +186 -15
  88. data/lib/rof/get_from_fedora.rb +0 -211
  89. data/lib/rof/osf_to_rof.rb +0 -123
  90. data/spec/lib/rof/get_from_fedora_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7f604446f5b61795e262bc554d46203d6ab3e00
4
- data.tar.gz: 433b2a744b3600fe9dbd15536d95daeb2796f9f1
3
+ metadata.gz: aa7099ebb75041867fac5b65720c86773fb645e0
4
+ data.tar.gz: 21ab74ec208d2e2e6b41ef3ffa061b0824e45674
5
5
  SHA512:
6
- metadata.gz: 4deb205a5a32c0a3c9765bd6e949a8e29063a23e6eb6f366012f71c75636cf0c26a3c298371651d1b646dadc4ef1002d64053c0b5345fd8574e917772d13d3bd
7
- data.tar.gz: 173692dabcdee2fbcb720cbdc7a991ddb3d16cd39aa3e681e9370450731e9a51c6f4a093e75df9f59f30ae130dbcd27ad66a65bde412751a3f1fa6e7d9acb253
6
+ metadata.gz: 3721b89f933f47cf9535718c3d35a1a2cc5664c3eccbb728a39494473f5e8c7411a33fd0171d204501a200c3b6074dea29b92384b97cb3274b69d4cc12511d73
7
+ data.tar.gz: eff5c5cce4953dcaca174fc0d51d682cbc811250f3b30090679bdce78821599c74c625c04a46bccc37feeab78032b7cc92e15f4bf3d52b8f11efc67e812b385b
@@ -1,16 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.0.0"
4
- - "2.1.1"
5
- - "2.2.4"
6
- - "2.3.0"
3
+ - "2.0.0-p648"
4
+ - "2.1.10"
5
+ - "2.2.6"
6
+ - "2.3.3"
7
+ - "2.4.0"
7
8
 
8
9
  matrix:
9
10
  allow_failures:
10
- - rvm: "2.3.0"
11
- - rvm: "2.2.4"
11
+ - rvm: "2.3.3"
12
+ - rvm: "2.2.6"
13
+ - rvm: "2.4.0"
12
14
 
13
- script: "bundle exec rspec"
15
+ script: "bundle exec rake"
14
16
 
15
17
  notifications:
16
18
  irc: "irc.freenode.org#ndlib"
data/LICENSE CHANGED
@@ -1,16 +1,201 @@
1
- ##########################################################################
2
- #
3
- # Copyright 2014 Notre Dame
4
- # Additional copyright may be held by others, as reflected in the commit log
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2014–2017 University of Notre Dame
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/Rakefile CHANGED
@@ -1 +1,47 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = "./spec/**/*_spec.rb"
7
+ ENV['COVERAGE'] = 'true'
8
+ end
9
+ task default: :spec
10
+ rescue LoadError
11
+ $stdout.puts "RSpec failed to load; You won't be able to run tests."
12
+ end
13
+
14
+ namespace :commitment do
15
+ task :configure_test_for_code_coverage do
16
+ ENV['COVERAGE'] = 'true'
17
+ end
18
+ desc "Check for code that can go faster"
19
+ task :fasterer do
20
+ require 'fasterer/file_traverser'
21
+ file_traverser = Fasterer::FileTraverser.new(nil)
22
+ file_traverser.traverse
23
+ if file_traverser.offenses_found?
24
+ $stderr.puts "You can make the code go faster, see above. You can add exceptions in .fasterer.yml"
25
+ abort
26
+ end
27
+ end
28
+ task :code_coverage do
29
+ require 'json'
30
+ # Our goal is to stay at this coverage level or higher; As the level increases, we bump up the goal
31
+ COVERAGE_GOAL = 95
32
+ $stdout.puts "Checking code_coverage"
33
+ lastrun_filename = File.expand_path('../coverage/.last_run.json', __FILE__)
34
+ if File.exist?(lastrun_filename)
35
+ coverage_percentage = JSON.parse(File.read(lastrun_filename)).fetch('result').fetch('covered_percent').to_i
36
+ if coverage_percentage < COVERAGE_GOAL
37
+ abort("ERROR: Code Coverage Goal Not Met:\n\t#{coverage_percentage}%\tExpected\n\t#{COVERAGE_GOAL}%\tActual")
38
+ else
39
+ $stdout.puts "Code Coverage Goal Met (#{COVERAGE_GOAL}%)"
40
+ end
41
+ else
42
+ abort "Expected #{lastrun_filename} to exist for code coverage"
43
+ end
44
+ end
45
+ end
46
+
47
+ task(default: ['commitment:configure_test_for_code_coverage', :spec, 'commitment:code_coverage'])
@@ -22,5 +22,4 @@ end
22
22
 
23
23
  STDIN.set_encoding("UTF-8")
24
24
  csv_contents = STDIN.read
25
- rof = ROF::TranslateCSV.run(csv_contents)
26
- puts JSON.pretty_generate(rof)
25
+ ROF::Translators.csv_to_rof(csv_contents, {}, STDOUT)
@@ -54,4 +54,10 @@ if fedora_info == nil || pids.empty? then
54
54
  end
55
55
 
56
56
  # perform conversion
57
- ROF::CLI.convert_to_rof(pids, fedora_info, file_path, config)
57
+ begin
58
+ config[:fedora_connection_information] = fedora_info
59
+ ROF::CLI.fedora_to_rof(pids, config, file_path)
60
+ rescue => e
61
+ STDERR.puts "ERROR: #{e}"
62
+ exit 1
63
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby -Ilib
2
+
3
+ require 'rof'
4
+ require 'optparse'
5
+ require 'json'
6
+
7
+ opt = OptionParser.new do |opts|
8
+ opts.banner = %q{Usage: jsonld_to_rof
9
+ Reads a JSON-LD file from stdin.
10
+ Writes a ROF file to stdout.
11
+
12
+ In case of an error, a message is written to stderr and the program
13
+ exits with a non-zero status.
14
+ }
15
+ end
16
+
17
+ opt.parse!
18
+
19
+ if ARGV.length != 0
20
+ abort opt.help
21
+ end
22
+
23
+ STDIN.set_encoding("UTF-8")
24
+ file_contents = STDIN.read
25
+ jsonld = JSON.parse(file_contents)
26
+ ROF::CLI.jsonld_to_rof(jsonld, {}, STDOUT)
@@ -10,11 +10,12 @@ file_path = STDOUT
10
10
  config['project_file'] = './osf_projects'
11
11
  config['package_dir'] = './FROM_OSF'
12
12
  config['output_dir'] = '.'
13
+ config['solr_url'] = 'http://localhost:8080/solr'
13
14
 
14
15
  # parse the command line
15
16
  #
16
17
  opt = OptionParser.new do |opts|
17
- opts.banner = %q{Usage: osf_to_rof --projectfile file --packagedir DIR --outputdir DIR
18
+ opts.banner = %q{Usage: osf_to_rof --solr_url --projectfile file --packagedir DIR --outputdir DIR
18
19
  }
19
20
 
20
21
  opts.on("", "--project_file project_file", "osf_projects file provided by requestor (required)") do |project_file|
@@ -26,6 +27,9 @@ opt = OptionParser.new do |opts|
26
27
  opts.on("", "--output_dir output_dir", "Directory to save ROF to (defaults to .)") do |output_dir|
27
28
  config['output_dir'] = output_dir
28
29
  end
30
+ opts.on("", "--solr_url solr_url", "URL of SOLR to use (defaults to http://localhost:8080/solr)") do |solr_url|
31
+ config['solr_url'] = solr_url
32
+ end
29
33
  end
30
34
 
31
35
  opt.parse!
@@ -37,4 +41,4 @@ if !FileTest.exists?(config['project_file']) then
37
41
  end
38
42
 
39
43
  # perform conversion
40
- ROF::CLI.osf_to_rof(config)
44
+ ROF::CLI.osf_to_rof(config['project_file'], config)
data/bin/rof CHANGED
@@ -47,30 +47,16 @@ fedora_info = nil if fedora_info.empty?
47
47
 
48
48
  case ARGV[0]
49
49
  when "compare"
50
- error_count = ROF::CLI.compare_files(ARGV[1], ARGV[2], STDOUT, fedora_info, bendo_info)
50
+ error_count = ROF::CLI.compare_files(ARGV[1], ARGV[2], STDOUT)
51
51
  exit 1 if error_count > 0
52
52
  when "ingest", "validate"
53
53
  error_count = ROF::CLI.ingest_file(ARGV[1], search_path, STDOUT, fedora_info, bendo_info)
54
54
  exit 1 if error_count > 0
55
55
  when "filter"
56
- filter = case ARGV[1]
57
- when "bendo"
58
- ROF::Filters::Bendo.new(bendo_info)
59
- when "collections"
60
- ROF::Filters::Collections.new
61
- when "datestamp"
62
- ROF::Filters::DateStamp.new
63
- when "file-to-url"
64
- ROF::Filters::FileToUrl.new
65
- when "label"
66
- ROF::Filters::Label.new(prefix, noids)
67
- when "work"
68
- ROF::Filters::Work.new
69
- else
70
- STDERR.puts "Unknown filter #{ARGV[1]}"
71
- exit 3
72
- end
73
- ROF::CLI.filter_file(filter, ARGV[2], STDOUT)
56
+ filter_name = ARGV[1]
57
+ file_name = ARGV[2]
58
+ filter = ROF::Filters.for(filter_name, file_name: file_name, bendo_info: bendo_info, prefix: prefix, noids: noids)
59
+ ROF::CLI.filter_file(filter, file_name, STDOUT)
74
60
  else
75
61
  STDERR.puts "Unknown command #{ARGV[0]}"
76
62
  STDERR.puts opt.help
data/lib/rof.rb CHANGED
@@ -5,12 +5,8 @@ require "rof/access"
5
5
  require "rof/collection"
6
6
  require "rof/utility"
7
7
  require "rof/rdf_context"
8
- require "rof/translate_csv"
9
- require "rof/filters/date_stamp"
10
- require "rof/filters/file_to_url"
11
- require "rof/filters/label"
12
- require "rof/filters/work"
13
- require "rof/filters/bendo"
8
+ require "rof/translators"
9
+ require "rof/filters"
14
10
 
15
11
  module ROF
16
12
  end
@@ -1,6 +1,6 @@
1
1
  module ROF
2
2
  # provide translation between access strings and the ROF access hash
3
- # e.g. ("public", owner=dbrower) --> {read-groups: "public", edit: "dbrower"}
3
+ # e.g. ("public", owner=dbrower) --> Hash.new(read-groups: "public", edit: "dbrower")
4
4
  class Access
5
5
  class DecodeError < RuntimeError
6
6
  end
@@ -4,8 +4,8 @@ require 'json'
4
4
  require 'rubydora'
5
5
  require 'rof/ingest'
6
6
  require 'rof/collection'
7
- require 'rof/get_from_fedora'
8
- require 'rof/osf_to_rof'
7
+ require 'rof/translators'
8
+ require 'rof/utility'
9
9
  module ROF
10
10
  module CLI
11
11
  # Ingest the file `fname` that is a level 0 rof file. It may contain any
@@ -19,104 +19,141 @@ module ROF
19
19
  #
20
20
  # Returns the number of errors.
21
21
  def self.ingest_file(fname, search_paths = [], outfile = STDOUT, fedora = nil, bendo = nil)
22
- items = load_items_from_file(fname, outfile)
22
+ items = ROF::Utility.load_items_from_json_file(fname, outfile)
23
23
  ingest_array(items, search_paths, outfile, fedora, bendo)
24
24
  end
25
25
 
26
+ # @param [NilClass, String, #write] outfile - where should we write things
27
+ # @see .with_outfile_handling for details on outfile
26
28
  def self.ingest_array(items, search_paths = [], outfile = STDOUT, fedora = nil, bendo = nil)
27
- need_close = false
28
- if outfile.nil?
29
- outfile = File.open('/dev/null', 'w')
30
- need_close = true
31
- end
32
29
  fedora = Rubydora.connect(fedora) if fedora
33
30
  item_count = 1
34
31
  error_count = 0
35
32
  verb = fedora.nil? ? 'Verifying' : 'Ingesting'
36
- overall_benchmark = Benchmark.measure do
37
- items.each do |item|
38
- begin
39
- outfile.write("#{item_count}. #{verb} #{item['pid']} ...")
40
- item_count += 1
41
- individual_benchmark = Benchmark.measure do
42
- ROF.Ingest(item, fedora, search_paths, bendo)
43
- end
44
- outfile.write("ok. %0.3fs\n" % individual_benchmark.real)
45
- rescue Exception => e
46
- error_count += 1
47
- outfile.write("error. #{e}\n")
48
- # TODO(dbrower): add option to toggle displaying backtraces
49
- if e.backtrace
50
- outfile.write(e.backtrace.join("\n\t"))
51
- outfile.write("\n")
33
+ with_outfile_handling(outfile) do |writer|
34
+ overall_benchmark = Benchmark.measure do
35
+ items.each do |item|
36
+ begin
37
+ writer.write("#{item_count}. #{verb} #{item['pid']} ...")
38
+ item_count += 1
39
+ individual_benchmark = Benchmark.measure do
40
+ ROF.Ingest(item, fedora, search_paths, bendo)
41
+ end
42
+ writer.write("ok. %0.3fs\n" % individual_benchmark.real)
43
+ rescue Exception => e
44
+ error_count += 1
45
+ writer.write("error. #{e}\n")
46
+ # TODO(dbrower): add option to toggle displaying backtraces
47
+ if e.backtrace
48
+ writer.write(e.backtrace.join("\n\t"))
49
+ writer.write("\n")
50
+ end
52
51
  end
53
52
  end
54
53
  end
54
+ writer.write("Total time %0.3fs\n" % overall_benchmark.real)
55
+ writer.write("#{error_count} errors\n")
55
56
  end
56
- outfile.write("Total time %0.3fs\n" % overall_benchmark.real)
57
- outfile.write("#{error_count} errors\n")
58
57
  error_count
59
- ensure
60
- outfile.close if outfile && need_close
61
58
  end
62
59
 
60
+ # Responsible for loading the given :fname into an array of items, the processing
61
+ # those items via the :filter, and finally writing results to the :output
62
+ #
63
+ # @param [#process] filter - the object that processes the items loaded from the fname
64
+ # @param [String] fname - the filename from which to load items
65
+ # @param [NilClass, String, #write] outfile - where should we write things
66
+ # @see .with_outfile_handling for details on outfile
67
+ # @return void
63
68
  def self.filter_file(filter, fname, outfile = STDOUT)
64
- items = load_items_from_file(fname, STDERR)
65
- filter_array(filter, items, fname, outfile)
69
+ items = ROF::Utility.load_items_from_json_file(fname, STDERR)
70
+ result = filter.process(items)
71
+ with_outfile_handling(outfile) do |writer|
72
+ writer.write(JSON.pretty_generate(result))
73
+ end
66
74
  end
67
75
 
68
- def self.filter_array(filter, items, fname, outfile = STDOUT)
69
- # filter will transform the items array in place
70
- result = filter.process(items, fname)
71
- outfile.write(JSON.pretty_generate(result))
76
+ # convert OSF archive tar.gz to rof file
77
+ # @param [String] project_file - The path to the OSF Project file
78
+ # @param [Hash] config
79
+ # @param [NilClass, String, #write] outfile - where should we write things
80
+ # @see .with_outfile_handling for details on outfile
81
+ def self.osf_to_rof(project_file, config = {}, outfile = STDOUT)
82
+ osf_projects = ROF::Utility.load_items_from_json_file(project_file, outfile)
83
+ result = ROF::Translators::OsfToRof.call(osf_projects[0], config)
84
+ with_outfile_handling(outfile) do |writer|
85
+ writer.write(JSON.pretty_generate(result))
86
+ end
72
87
  end
73
88
 
74
- # retrieve fedora object and convert to ROF
75
- def self.convert_to_rof(pids, fedora = nil, outfile = STDOUT, config = {})
76
- need_close = false
77
- # use outfile is_a String
78
- if outfile.is_a?(String)
79
- outfile = File.open(outfile, 'w')
80
- need_close = true
89
+ # Convert the given fedora PIDs to ROF JSON document
90
+ # @param [Array] pids - The path to the OSF Project file
91
+ # @param [Hash] config
92
+ # @param [NilClass, String, #write] outfile - where should we write things
93
+ # @see .with_outfile_handling for details on outfile
94
+ def self.fedora_to_rof(pids, config = {}, outfile = STDOUT)
95
+ result = ROF::Translators::FedoraToRof.call(pids, config)
96
+ with_outfile_handling(outfile) do |writer|
97
+ writer.write(JSON.pretty_generate(result))
81
98
  end
99
+ end
82
100
 
83
- # wrap the objects inside a JSON list
84
- result = []
85
- pids.each do |pid|
86
- result << ROF::FedoraToRof.GetFromFedora(pid, fedora, config)
101
+ # Convert the given CSV to ROF JSON document
102
+ # @param [String] csv - The contents of a CSV file
103
+ # @param [Hash] config
104
+ # @param [NilClass, String, #write] outfile - where should we write things
105
+ # @see .with_outfile_handling for details on outfile
106
+ # @see ROF::Translators::CsvToRof.call
107
+ def self.csv_to_rof(csv, config = {}, outfile = STDOUT)
108
+ result = ROF::Translators::CsvToRof.call(csv, config)
109
+ with_outfile_handling(outfile) do |writer|
110
+ writer.write(JSON.pretty_generate(result))
87
111
  end
88
- outfile.write(JSON.pretty_generate(result))
89
- ensure
90
- outfile.close if outfile && need_close
91
112
  end
92
113
 
93
- # convert OSF archive tar.gz to rof file
94
- def self.osf_to_rof(config, outfile = STDOUT)
95
- osf_projects = load_items_from_file(config['project_file'], outfile) if config.key?('project_file')
96
- rof_data = ROF::OsfToRof.osf_to_rof(config, osf_projects[0])
97
- outfile.write(JSON.pretty_generate(rof_data))
114
+ # Convert the given JSON-LD to ROF JSON document
115
+ # @param [Hash] jsonld - contents of a CSV file
116
+ # @param [Hash] config
117
+ # @param [NilClass, String, #write] outfile - where should we write things
118
+ # @see .with_outfile_handling for details on outfile
119
+ # @see ROF::Translators::JsonldToRof.call
120
+ def self.jsonld_to_rof(jsonld, config = {}, outfile = STDOUT)
121
+ result = ROF::Translators::JsonldToRof.call(jsonld, config)
122
+ with_outfile_handling(outfile) do |writer|
123
+ writer.write(JSON.pretty_generate(result))
124
+ end
98
125
  end
99
126
 
100
127
  # compare two rofs
101
- def self.compare_files(file1, file2, outfile = STDOUT, _fedora, _bendo)
102
- fedora_rof = load_items_from_file(file1, outfile)
103
- bendo_rof = load_items_from_file(file2, outfile)
128
+ # @param [String] file1 - path to "left" file in the comparison
129
+ # @param [String] file2 - path to "right" file in the comparison
130
+ # @param [#write] outfile - where to write any errors (default STDOUT)
131
+ # @return [Integer] number of comparisons that failed. If 0, then the two given files are logically equal
132
+ # @todo Should the outfile default to STDERR
133
+ def self.compare_files(file1, file2, outfile = STDOUT)
134
+ fedora_rof = ROF::Utility.load_items_from_json_file(file1, outfile)
135
+ bendo_rof = ROF::Utility.load_items_from_json_file(file2, outfile)
104
136
 
105
137
  ROF::CompareRof.fedora_vs_bendo(fedora_rof, bendo_rof, outfile)
106
138
  end
107
139
 
108
- protected
109
-
110
- def self.load_items_from_file(fname, outfile)
111
- items = nil
112
- File.open(fname, 'r:UTF-8') do |f|
113
- items = JSON.parse(f.read)
140
+ # Provides a normalized handling of outfiles:
141
+ #
142
+ # @param [NilClass, String, #write] outfile - The IO point that we will write to
143
+ # @yieldparam [#write] writer - An object that can be written to
144
+ def self.with_outfile_handling(outfile)
145
+ need_close = false
146
+ # use outfile is_a String
147
+ if outfile.is_a?(String)
148
+ outfile = File.open(outfile, 'w')
149
+ need_close = true
150
+ elsif outfile.nil?
151
+ outfile = File.open('/dev/null', 'w')
152
+ need_close = true
114
153
  end
115
- items = [items] unless items.is_a? Array
116
- items
117
- rescue JSON::ParserError => e
118
- outfile.puts("Error reading #{fname}:#{e}")
119
- exit!(1)
154
+ yield(outfile)
155
+ ensure
156
+ outfile.close if outfile && (need_close || outfile.respond_to?(:close))
120
157
  end
121
158
  end
122
159
  end