active_fedora-crosswalks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Yjc3NDMwOTAwOWQyMmM2YTg0NGU5Y2QzOTk3M2I2YmZmMmU5YzQ5Ng==
5
+ data.tar.gz: !binary |-
6
+ ODdhODBjZTFhY2I4YWFlNjRlNmJkMTcyZGFjMjIxM2U2ZWEyM2YzOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDY5M2FjNDQxOGI3ZTA1MDE1OTgyMjA2Yjk4NzdiZWI3ZTI4YmJlMDE4NjNi
10
+ YmM4MWZjNTk3NmExNzBiZTczYzJhNDI4M2NmZTU1YjAyYzM3NmJkZWQ0ZmM5
11
+ OTI2YTM2OWNlMzk1ZGFiZjA1M2FmZTM1YWQ2ZDBhNGVjZjgwZWQ=
12
+ data.tar.gz: !binary |-
13
+ NzkzYWU0Y2UyMmI1OTJkOWJlNGQ4YmIxZDdlYzliMjRlZTJkZjM4NmJiMzcy
14
+ NDcxMTA3MTVmYTQ0YTZhOGU2M2NlMzVjYWNkNTcxNDk5NzliOGQ3MzhkZmYz
15
+ YWU4YjE2MjYzYWM1NzIzZjgyNzk5NmZiYzBiOWY5MDZiNmE2NDA=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ jetty
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_fedora-crosswalks.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :cli => '--color --drb --format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb"] }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,191 @@
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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright 2013 Oregon State University Libraries & Press
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # ActiveFedora::Crosswalks
2
+
3
+ Enables metadata crosswalking between ActiveFedora datastreams.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'active_fedora-crosswalks'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install active_fedora-crosswalks
18
+
19
+ ## Usage
20
+
21
+ In the datastreams you'd like to enable for crosswalking include ActiveFedora::Crosswalks::Crosswalkable
22
+ Example:
23
+ ```ruby
24
+ class ExampleRdfDatastream < ActiveFedora::NtriplesRDFDatastream
25
+ include ActiveFedora::Crosswalks::Crosswalkable
26
+ end
27
+ ```
28
+
29
+ ### Example - Crosswalking between RDF Datastreams
30
+ ```ruby
31
+ class Asset < ActiveFedora::Base
32
+ has_metadata :name => 'descMetadata', :type => ExampleRdfDatastream
33
+ has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
34
+ ds.crosswalk :field => :title, :to => :other_title, :in => :descMetadata
35
+ end
36
+ end
37
+ ```
38
+
39
+ ### Example - Crosswalking from Rels-EXT to RDF Datastreams
40
+ ```ruby
41
+ class Asset < ActiveFedora::Base
42
+ has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
43
+ ds.crosswalk :field => :set, :to => :is_member_of_collection, :in => "RELS-EXT"
44
+ end
45
+ end
46
+ ```
47
+
48
+ ### Example - Deep crosswalking from OM Datastreams to RDF
49
+ ```ruby
50
+ class Asset < ActiveFedora::Base
51
+ has_metadata :name => 'descMetadata', :type => DummyOmDatastream
52
+ has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
53
+ ds.crosswalk :field => :name, :to => [:name, :family_name], :in => :descMetadata
54
+ end
55
+ end
56
+ ```
57
+
58
+ **NOTE**: Currently there is no support for defining datastreams other than RDF datastreams as crosswalk destinations.
59
+ Pull Requests Accepted.
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ Dir.glob('tasks/*.rake').each { |r| import r }
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_fedora/crosswalks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_fedora-crosswalks"
8
+ spec.version = ActiveFedora::Crosswalks::VERSION
9
+ spec.authors = ["Trey Terrell"]
10
+ spec.email = ["trey.terrell@oregonstate.edu"]
11
+ spec.description = %q{Enables metadata crosswalking between ActiveFedora datastreams.}
12
+ spec.summary = %q{Enables metadata crosswalking between ActiveFedora datastreams.}
13
+ spec.homepage = "https://github.com/osulp/active_fedora-crosswalks"
14
+ spec.license = "Apache v2"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency 'jettywrapper'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'shoulda-matchers'
29
+
30
+ spec.add_dependency 'active-fedora'
31
+ spec.add_dependency 'activesupport', '>= 3.2.0', '< 5.0'
32
+ spec.add_dependency 'bagit'
33
+ spec.add_dependency 'mime-types'
34
+ end
@@ -0,0 +1,13 @@
1
+ class FieldProxy
2
+ attr_accessor :array, :accessor, :field
3
+ delegate *(Array.public_instance_methods - [:__send__, :__id__, :class, :object_id] + [:as_json]), :to => :array
4
+ def initialize(array, accessor, field)
5
+ self.array = array
6
+ self.accessor = accessor
7
+ self.field = field
8
+ end
9
+ def << (value)
10
+ array << value
11
+ accessor.set_value(field, array)
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ module Accessors
4
+ class GenericAccessor
5
+ attr_accessor :datastream, :field
6
+ def self.new(datastream, field)
7
+ if self.to_s.include?("GenericAccessor")
8
+ if datastream.kind_of?(ActiveFedora::RelsExtDatastream)
9
+ return RelsExtAccessor.new(datastream, field)
10
+ end
11
+ if datastream.kind_of?(ActiveFedora::OmDatastream)
12
+ return OmAccessor.new(datastream, field)
13
+ end
14
+ end
15
+ super
16
+ end
17
+ def initialize(datastream, field)
18
+ @datastream = datastream
19
+ @field = field
20
+ end
21
+ def get_reader
22
+ return datastream, field, nil
23
+ end
24
+ def get_writer
25
+ return datastream, "#{self.field}=", nil
26
+ end
27
+ def get_value
28
+ FieldProxy.new(Array.wrap(datastream.send(field.to_s)), self, field)
29
+ end
30
+ def set_value(*args)
31
+ value = args.last
32
+ datastream.send("#{field.to_s}=",value)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ module Accessors
4
+ class OmAccessor < GenericAccessor
5
+ def get_reader
6
+ raise "Crosswalking from OM not supported"
7
+ end
8
+ def get_writer
9
+ raise "Crosswalking from OM not supported."
10
+ end
11
+ def get_value
12
+ FieldProxy.new(datastream.send(:term_values, *field), self, field)
13
+ end
14
+ def set_value(*args)
15
+ value = Array.wrap(args.last)
16
+ datastream.send(:update_indexed_attributes, {field => value})
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ module Accessors
4
+ class RelsExtAccessor < GenericAccessor
5
+ def get_reader
6
+ raise "Crosswalking from Rels-Ext not supported"
7
+ end
8
+ def get_writer
9
+ raise "Crosswalking from Rels-Ext not supported."
10
+ end
11
+ def get_value
12
+ FieldProxy.new(Array.wrap(datastream.model.relationships(field.to_sym)), self, field)
13
+ end
14
+ def set_value(*args)
15
+ datastream.model.clear_relationship(field.to_sym)
16
+ value = Array.wrap(args.last)
17
+ value.each do |v|
18
+ datastream.model.add_relationship(field.to_sym, v)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ module Crosswalkable
4
+ # Override content so when it's called it performs crosswalks first.
5
+ def content
6
+ crosswalkers.each do |crosswalker|
7
+ crosswalker.source_accessor.get_value
8
+ end
9
+ super
10
+ end
11
+ def crosswalk_fields
12
+ @crosswalk_fields ||= []
13
+ end
14
+ def crosswalkers
15
+ @crosswalkers ||= []
16
+ end
17
+ def crosswalk(*args)
18
+ args = args.first if args.respond_to? :first
19
+ raise "Hash of options not given" unless args.kind_of?(Hash)
20
+ args[:datastream] = self
21
+ crosswalker = Crosswalker.new(args)
22
+ crosswalker.validate!
23
+ crosswalker.perform_crosswalk!
24
+ self.crosswalkers << crosswalker
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,72 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ class Crosswalker
4
+ include ActiveModel::Validations
5
+ validates :parent, :field, :to, :presence => true
6
+ validate :parent_has_datastream
7
+ attr_accessor :parent, :datastream, :target_datastream, :field, :to
8
+ def initialize(args)
9
+ @datastream = args.delete(:datastream)
10
+ @parent = @datastream.digital_object if @datastream
11
+ @field = args.delete(:field)
12
+ @to = args.delete(:to)
13
+ @target_datastream_key = args.delete(:in).to_s
14
+ @target_datastream = parent.datastreams[@target_datastream_key] if parent.datastreams.has_key?(@target_datastream_key)
15
+ end
16
+
17
+ def validate!
18
+ unless self.valid?
19
+ errors.full_messages.each do |error|
20
+ raise error
21
+ end
22
+ end
23
+ end
24
+
25
+ def perform_crosswalk!
26
+ datastream.crosswalk_fields << field
27
+ create_reader
28
+ create_writer
29
+ end
30
+
31
+ def source_accessor
32
+ @source_accessor ||= Accessors::GenericAccessor.new(datastream, field)
33
+ end
34
+
35
+ def target_accessor
36
+ @target_accessor ||= Accessors::GenericAccessor.new(target_datastream, to)
37
+ end
38
+
39
+ protected
40
+
41
+ def create_reader
42
+ object, method, expected_args = source_accessor.get_reader
43
+ crosswalker = self
44
+ object.define_singleton_method(method) do |*args|
45
+ puts "Expected Arguments in Reader: #{expected_args}"
46
+ if !expected_args || args[0..-2] == expected_args || (args.last.kind_of?(Hash) && args.last.has_key?(expected_args))
47
+ crosswalker.source_accessor.set_value(crosswalker.target_accessor.get_value)
48
+ end
49
+ crosswalker.target_accessor.get_value
50
+ end
51
+ end
52
+
53
+ def create_writer
54
+ object, method, expected_args = source_accessor.get_writer
55
+ crosswalker = self
56
+ object.define_singleton_method(method) do |*args|
57
+ puts "Expected Arguments in Writer: #{expected_args}"
58
+ if !expected_args || args[0..-2] == expected_args || (args.last.kind_of?(Hash) && args.last.has_key?(expected_args))
59
+ result = super(args.last)
60
+ crosswalker.target_accessor.set_value(result)
61
+ return result
62
+ end
63
+ end
64
+ end
65
+
66
+ def parent_has_datastream
67
+ errors.add(:parent, "does not have a datastream #{@target_datastream_key}") unless target_datastream
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveFedora
2
+ module Crosswalks
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require "active_fedora/crosswalks/version"
2
+ require 'active_fedora/crosswalks/crosswalkable'
3
+ require 'active_fedora/crosswalks/crosswalker'
4
+ require 'active_fedora/crosswalks/accessors/generic_accessor'
5
+ require 'active_fedora/crosswalks/accessors/rels_ext_accessor'
6
+ require 'active_fedora/crosswalks/accessors/om_accessor'
7
+ require 'active_fedora/crosswalks/accessors/field_proxy'
8
+
9
+ module ActiveFedora
10
+ module Crosswalks
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'active-fedora'
2
+ class DummyOmDatastream < ActiveFedora::OmDatastream
3
+ include ActiveFedora::Crosswalks::Crosswalkable
4
+ set_terminology do |t|
5
+ t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3")
6
+ t.title
7
+
8
+ # The underscore is purely to avoid namespace conflicts.
9
+ t.name_ {
10
+ t.namePart
11
+ t.family_name(:path=>"namePart", :attributes=>{:type=>"family"})
12
+ t.given_name(:path=>"namePart", :attributes=>{:type=>"given"})
13
+ t.role {
14
+ t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
15
+ t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
16
+ }
17
+ }
18
+ end
19
+ def self.xml_template
20
+ Nokogiri::XML.parse('<mods xmlns="http://www.loc.gov/mods/v3"/>')
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ class ExampleRdfDatastream < ActiveFedora::NtriplesRDFDatastream
2
+ include ActiveFedora::Crosswalks::Crosswalkable
3
+ map_predicates do |map|
4
+ map.title(:in => RDF::DC)
5
+ map.other_title(:to => 'title', :in => RDF::DC)
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ <mods xmlns="http://www.loc.gov/mods/v3">
2
+ <name>
3
+ <namePart type="given">Zoia</namePart>
4
+ <namePart type="family">Horn</namePart>
5
+ <role>
6
+ <roleTerm type="text">author</roleTerm>
7
+ <roleTerm type="code">AUT</roleTerm>
8
+ </role>
9
+ </name>
10
+ <name>
11
+ <namePart type="family">Caesar</namePart>
12
+ <namePart type="given">Julius</namePart>
13
+ <role>
14
+ <roleTerm type="text">Contributor</roleTerm>
15
+ <roleTerm type="code">CON</roleTerm>
16
+ </role>
17
+ </name>
18
+ </mods>
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Crosswalks::Crosswalkable do
4
+ let(:asset) {CrosswalkAsset.new}
5
+ before(:each) do
6
+ Object.send(:remove_const, :CrosswalkAsset) if Object.const_defined?(:CrosswalkAsset)
7
+ class CrosswalkAsset < ActiveFedora::Base; end
8
+ end
9
+ after(:each) do
10
+ Object.send(:remove_const, :CrosswalkAsset)
11
+ end
12
+ context "crosswalking RDF to RDF" do
13
+ before(:each) do
14
+ CrosswalkAsset.has_metadata :name => 'descMetadata', :type => ExampleRdfDatastream
15
+ CrosswalkAsset.has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
16
+ ds.crosswalk :field => :title, :to => :other_title, :in => :descMetadata
17
+ end
18
+ end
19
+ context "when a field is set" do
20
+ context "on the source datastream" do
21
+ before(:each) do
22
+ asset.descMetadata.other_title = "Test"
23
+ end
24
+ it "should set the crosswalked field" do
25
+ expect(asset.xwalkMetadata.title).to eq ["Test"]
26
+ end
27
+ it "should serialize the data" do
28
+ expect(asset.xwalkMetadata.content).to include "Test"
29
+ end
30
+ end
31
+ context "on the crosswalked datastream" do
32
+ before(:each) do
33
+ asset.xwalkMetadata.title = "Test"
34
+ end
35
+ it "should set the source field" do
36
+ expect(asset.descMetadata.other_title).to eq ["Test"]
37
+ end
38
+ it "should serialize the data" do
39
+ expect(asset.descMetadata.content).to include "Test"
40
+ end
41
+ end
42
+ end
43
+ context "when a field is appended to" do
44
+ before(:each) do
45
+ asset.descMetadata.other_title = "Testing"
46
+ asset.xwalkMetadata.title = "Testing"
47
+ end
48
+ context "on the source datastream" do
49
+ before(:each) do
50
+ asset.descMetadata.other_title << "Test2"
51
+ end
52
+ it "should append to the crosswalked field" do
53
+ expect(asset.xwalkMetadata.title).to eq ["Testing", "Test2"]
54
+ end
55
+ it "should serialize the data" do
56
+ expect(asset.xwalkMetadata.content).to include "Testing"
57
+ expect(asset.xwalkMetadata.content).to include "Test2"
58
+ end
59
+ end
60
+ context "on the crosswalked datastream" do
61
+ before(:each) do
62
+ asset.xwalkMetadata.title << "Test2"
63
+ end
64
+ it "should append to the source field" do
65
+ expect(asset.descMetadata.other_title).to eq ["Testing", "Test2"]
66
+ end
67
+ it "should serialize the data" do
68
+ expect(asset.descMetadata.content).to include "Testing"
69
+ expect(asset.descMetadata.content).to include "Test2"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ context "crosswalking RDF to RELS-EXT" do
75
+ before(:each) do
76
+ CrosswalkAsset.has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
77
+ ds.crosswalk :field => :title, :to => :is_member_of_collection, :in => "RELS-EXT"
78
+ end
79
+ end
80
+ context "when a field is set" do
81
+ context "on the source datastream" do
82
+ before(:each) do
83
+ asset.add_relationship(:is_member_of_collection, "info:fedora/test:test")
84
+ end
85
+ it "should set the crosswalked field" do
86
+ expect(asset.xwalkMetadata.title).to eq ["info:fedora/test:test"]
87
+ end
88
+ it "should serialize the data" do
89
+ expect(asset.xwalkMetadata.content).to include "info:fedora/test:test"
90
+ end
91
+ end
92
+ context "on the crosswalked datastream" do
93
+ before(:each) do
94
+ asset.xwalkMetadata.title = "info:fedora/test:testing"
95
+ end
96
+ it "should set the source field" do
97
+ expect(asset.relationships(:is_member_of_collection)).to eq ["info:fedora/test:testing"]
98
+ end
99
+ it "should serialize the data" do
100
+ expect(asset.datastreams["RELS-EXT"].to_rels_ext).to include "info:fedora/test:testing"
101
+ end
102
+ end
103
+ end
104
+ context "when a field is appended to" do
105
+ context "on the source datastream" do
106
+ before(:each) do
107
+ asset.add_relationship(:is_member_of_collection, "info:fedora/test:testing")
108
+ asset.add_relationship(:is_member_of_collection, "info:fedora/test:test2")
109
+ end
110
+ it "should set the crosswalked field" do
111
+ expect(asset.xwalkMetadata.title).to eq ["info:fedora/test:testing", "info:fedora/test:test2"]
112
+ end
113
+ end
114
+ context "on the crosswalked datastream" do
115
+ before(:each) do
116
+ asset.xwalkMetadata.title = "info:fedora/test:testing"
117
+ asset.xwalkMetadata.title << "info:fedora/test:test2"
118
+ end
119
+ it "should set the source field" do
120
+ expect(asset.relationships(:is_member_of_collection)).to eq ["info:fedora/test:testing", "info:fedora/test:test2"]
121
+ end
122
+ end
123
+ end
124
+ end
125
+ context "crosswalking RDF to OM" do
126
+ before(:each) do
127
+ CrosswalkAsset.has_metadata :name => 'descMetadata', :type => DummyOmDatastream
128
+ CrosswalkAsset.has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream do |ds|
129
+ ds.crosswalk :field => :title, :to => [:name, :family_name], :in => :descMetadata
130
+ end
131
+ end
132
+ context "when data is set" do
133
+ context "on the source datastream" do
134
+ before(:each) do
135
+ asset.descMetadata.content = File.read(File.join(FIXTURE_PATH, 'fixture_xml.xml'))
136
+ expect(asset.descMetadata.name(0).family_name).to eq ["Horn"]
137
+ end
138
+ it "should set the crosswalked field" do
139
+ expect(asset.xwalkMetadata.title).to eq ["Horn", "Caesar"]
140
+ end
141
+ it "should serialize the crosswalk" do
142
+ expect(asset.xwalkMetadata.content).to include("Horn")
143
+ expect(asset.xwalkMetadata.content).to include("Caesar")
144
+ end
145
+ end
146
+ context "on the crosswalked datastream" do
147
+ before(:each) do
148
+ asset.xwalkMetadata.title = "test"
149
+ end
150
+ it "should set the source field" do
151
+ expect(asset.descMetadata.name.family_name).to eq ["test"]
152
+ end
153
+ it "should serialize the source" do
154
+ expect(asset.descMetadata.content).to include("test")
155
+ end
156
+ end
157
+ end
158
+ context "when data is appended" do
159
+ context "on the crosswalk datastream" do
160
+ before(:each) do
161
+ asset.descMetadata.content = File.read(File.join(FIXTURE_PATH, 'fixture_xml.xml'))
162
+ asset.xwalkMetadata.title << "test"
163
+ end
164
+ it "should add the metadata to the source field" do
165
+ expect(asset.descMetadata.name.family_name).to eq ["Horn", "test", "Caesar"]
166
+ end
167
+ end
168
+ end
169
+ end
170
+ context "crosswalking OM to RDF" do
171
+ before(:each) do
172
+ CrosswalkAsset.has_metadata :name => 'descMetadata', :type => ExampleRdfDatastream
173
+ CrosswalkAsset.has_metadata :name => 'xwalkMetadata', :type => DummyOmDatastream do |ds|
174
+ ds.crosswalk :field => [:name, :family_name], :to => :title, :in => :descMetadata
175
+ end
176
+ end
177
+ context "when data is set" do
178
+ context "on the crosswalk datastream" do
179
+ before(:each) do
180
+ asset.xwalkMetadata.content = File.read(File.join(FIXTURE_PATH, 'fixture_xml.xml'))
181
+ expect(asset.xwalkMetadata.name(0).family_name).to eq ["Horn"]
182
+ end
183
+ xit "should set the crosswalked field" do
184
+ expect(asset.descMetadata.title).to eq ["Horn", "Caesar"]
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+
4
+
5
+ describe ActiveFedora::Crosswalks::Crosswalker do
6
+ let(:proper_arguments) {{:datastream => asset.xwalkMetadata, :field => :title, :to => :other_title, :in => :descMetadata}}
7
+ let(:arguments) {proper_arguments}
8
+ let(:asset) {CrosswalkAsset.new}
9
+ subject (:crosswalker) {ActiveFedora::Crosswalks::Crosswalker.new(arguments)}
10
+ before(:each) do
11
+ class CrosswalkAsset < ActiveFedora::Base
12
+ has_metadata :name => 'descMetadata', :type => ExampleRdfDatastream
13
+ has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream
14
+ end
15
+ class CrosswalkAssetNoDatastream < ActiveFedora::Base
16
+ has_metadata :name => 'xwalkMetadata', :type => ExampleRdfDatastream
17
+ end
18
+ end
19
+ after(:each) do
20
+ Object.send(:remove_const, :CrosswalkAsset)
21
+ end
22
+ describe ".validate!" do
23
+ context "when the asset has valid datastreams" do
24
+ it "should be valid by default" do
25
+ expect{subject.validate!}.not_to raise_error
26
+ end
27
+ %w{field to in datastream}.each do |value|
28
+ context "when #{value} isn't given" do
29
+ let(:arguments) {proper_arguments.except(value.to_sym)}
30
+ it "should be invalid" do
31
+ expect {subject.validate!}.to raise_error
32
+ end
33
+ end
34
+ end
35
+ end
36
+ context "when the asset doesn't have a datastream by the given name" do
37
+ let(:asset) {CrosswalkAssetNoDatastream}
38
+ it "should be invalid" do
39
+ expect {subject.validate!}.to raise_error
40
+ end
41
+ end
42
+ end
43
+ describe ".perform_crosswalk!" do
44
+ before(:each) do
45
+ asset.descMetadata.other_title = "bla"
46
+ subject.perform_crosswalk!
47
+ end
48
+ it "should populate the datastream's crosswalk_fields" do
49
+ expect(asset.xwalkMetadata.crosswalk_fields).to eq [:title]
50
+ end
51
+ it "should build the crosswalk" do
52
+ expect(asset.xwalkMetadata.title).to eq ["bla"]
53
+ end
54
+ it "should build the crosswalk writer" do
55
+ asset.xwalkMetadata.title = "bla2"
56
+ expect(asset.descMetadata.other_title).to eq ["bla2"]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec/autorun'
2
+ ENV['environment'] ||= 'test'
3
+ # - RSpec adds ./lib to the $LOAD_PATH
4
+ require 'active_fedora'
5
+ require 'active_fedora/crosswalks'
6
+ #Resque.inline = Rails.env.test?
7
+ ROOT_PATH = File.dirname(__FILE__)
8
+ DUMMY_PATH = File.join(ROOT_PATH,"dummies")
9
+ FIXTURE_PATH = File.join(ROOT_PATH, "fixtures")
10
+
11
+ # Support
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
13
+ # Dummies
14
+ Dir["#{File.dirname(__FILE__)}/dummies/**/*.rb"].each { |f| require f }
15
+
16
+ RSpec.configure do |config|
17
+ end
data/tasks/jetty.rake ADDED
@@ -0,0 +1,6 @@
1
+ JETTY_CONFIG = {
2
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty"),
3
+ :jetty_port => "8983", :java_opts=>["-Xmx512m"],
4
+ :startup_wait => 45
5
+ }
6
+ require 'jettywrapper'
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_fedora-crosswalks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Trey Terrell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jettywrapper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: shoulda-matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: active-fedora
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.2.0
146
+ - - <
147
+ - !ruby/object:Gem::Version
148
+ version: '5.0'
149
+ type: :runtime
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: 3.2.0
156
+ - - <
157
+ - !ruby/object:Gem::Version
158
+ version: '5.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: bagit
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: mime-types
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :runtime
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: Enables metadata crosswalking between ActiveFedora datastreams.
188
+ email:
189
+ - trey.terrell@oregonstate.edu
190
+ executables: []
191
+ extensions: []
192
+ extra_rdoc_files: []
193
+ files:
194
+ - .gitignore
195
+ - Gemfile
196
+ - Guardfile
197
+ - LICENSE.txt
198
+ - README.md
199
+ - Rakefile
200
+ - active_fedora-crosswalks.gemspec
201
+ - lib/active_fedora/crosswalks.rb
202
+ - lib/active_fedora/crosswalks/accessors/field_proxy.rb
203
+ - lib/active_fedora/crosswalks/accessors/generic_accessor.rb
204
+ - lib/active_fedora/crosswalks/accessors/om_accessor.rb
205
+ - lib/active_fedora/crosswalks/accessors/rels_ext_accessor.rb
206
+ - lib/active_fedora/crosswalks/crosswalkable.rb
207
+ - lib/active_fedora/crosswalks/crosswalker.rb
208
+ - lib/active_fedora/crosswalks/version.rb
209
+ - spec/dummies/dummy_om_datastream.rb
210
+ - spec/dummies/example_rdf_datastream.rb
211
+ - spec/fixtures/fixture_xml.xml
212
+ - spec/lib/active_fedora/crosswalks/crosswalkable_spec.rb
213
+ - spec/lib/active_fedora/crosswalks/crosswalker_spec.rb
214
+ - spec/spec_helper.rb
215
+ - tasks/jetty.rake
216
+ homepage: https://github.com/osulp/active_fedora-crosswalks
217
+ licenses:
218
+ - Apache v2
219
+ metadata: {}
220
+ post_install_message:
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ! '>='
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ! '>='
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project:
236
+ rubygems_version: 2.0.3
237
+ signing_key:
238
+ specification_version: 4
239
+ summary: Enables metadata crosswalking between ActiveFedora datastreams.
240
+ test_files:
241
+ - spec/dummies/dummy_om_datastream.rb
242
+ - spec/dummies/example_rdf_datastream.rb
243
+ - spec/fixtures/fixture_xml.xml
244
+ - spec/lib/active_fedora/crosswalks/crosswalkable_spec.rb
245
+ - spec/lib/active_fedora/crosswalks/crosswalker_spec.rb
246
+ - spec/spec_helper.rb