active_fedora_relsint 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,11 @@
1
1
  module ActiveFedora
2
2
  module RelsInt
3
3
  class Datastream < ActiveFedora::Datastream
4
+ class_attribute :profile_solr_name
4
5
  attr_accessor :relationships_loaded
6
+
7
+ self.profile_solr_name = ActiveFedora::SolrService.solr_name("rels_int_profile", :string, :displayable)
8
+
5
9
  def serialize!
6
10
  self.content = to_rels_int() if changed_attributes.include? 'relationships'
7
11
  changed_attributes.delete 'relationships'
@@ -111,6 +115,30 @@ module ActiveFedora
111
115
  def self.xml_template
112
116
  "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"></rdf:RDF>"
113
117
  end
118
+
119
+ def to_solr(solr_doc=Hash.new)
120
+ result = super(solr_doc)
121
+ result = solrize_relationships(result)
122
+ result
123
+ end
124
+
125
+ def from_solr(solr_doc)
126
+ @solr_hash = JSON.parse(solr_doc[self.class.profile_solr_name][0])
127
+ end
128
+
129
+ def solrize_relationships(solr_doc=Hash.new)
130
+ rel_hash = {} # the rels_int_profile is a hash of hashes in json
131
+ graph.each_statement do |statement|
132
+ predicate = ActiveFedora::RelsExtDatastream.short_predicate(statement.predicate)
133
+ literal = statement.object.kind_of?(RDF::Literal)
134
+ val = literal ? statement.object.value : statement.object.to_str
135
+ rel_hash[statement.subject] ||= {}
136
+ rel_hash[statement.subject][predicate] ||= []
137
+ rel_hash[statement.subject][predicate] << val
138
+ end
139
+ solr_doc[self.class.profile_solr_name] = rel_hash.to_json unless rel_hash.blank?
140
+ solr_doc
141
+ end
114
142
  end
115
143
  end
116
144
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveFedora
2
2
  module RelsInt
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,46 @@
1
+ APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
2
+
3
+ namespace :active_fedora_relsint do
4
+ require 'active-fedora'
5
+
6
+ # Use yard to build docs
7
+ begin
8
+ require 'yard'
9
+ require 'yard/rake/yardoc_task'
10
+ project_root = APP_ROOT
11
+ doc_destination = File.join(project_root, 'doc')
12
+
13
+ YARD::Rake::YardocTask.new(:doc) do |yt|
14
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
15
+ [ File.join(project_root, 'README.textile')]
16
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
17
+ end
18
+ rescue LoadError
19
+ desc "Generate YARD Documentation"
20
+ task :doc do
21
+ abort "Please install the YARD gem to generate rdoc."
22
+ end
23
+ end
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:rspec) do |spec|
27
+ spec.pattern = FileList['spec/**/*_spec.rb']
28
+ spec.pattern += FileList['spec/*_spec.rb']
29
+ end
30
+
31
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ spec.pattern += FileList['spec/*_spec.rb']
34
+ spec.rcov = true
35
+ end
36
+
37
+ desc "Execute specs with coverage"
38
+ task :coverage do
39
+ # Put spec opts in a file named .rspec in root
40
+ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
41
+ ENV['COVERAGE'] = 'true' unless ruby_engine == 'jruby'
42
+
43
+ Rake::Task["active_fedora_relsint:rspec"].invoke
44
+ end
45
+
46
+ end
@@ -23,66 +23,83 @@ describe ActiveFedora::RelsInt do
23
23
  Foo.ds_specs['RELS-INT'][:type].should == ActiveFedora::RelsInt::Datastream
24
24
  end
25
25
 
26
- it "should serialize to appropriate RDF-XML" do
26
+ it "should serialize to appropriate RDF-XML on a new object" do
27
27
  blank_relsint = fixture('rels_int_blank.xml').read
28
28
  inner = mock("DigitalObject")
29
+ inner.stubs(:new?).returns(true)
29
30
  inner.stubs(:pid).returns("test:relsint")
30
31
  repo = mock("Repository")
31
- #repo.expects(:datastream_dissemination).with(:dsid=>"RELS-INT", :pid=>"test:relsint").returns("")
32
- #inner.stubs(:repository).returns(repo)
32
+ inner.stubs(:repository).returns(repo)
33
33
  test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
34
34
  Nokogiri::XML.parse(test_obj.content).should be_equivalent_to Nokogiri::XML.parse(blank_relsint)
35
35
  end
36
36
 
37
+ it "should serialize to appropriate RDF-XML when added to an existing obect" do
38
+ blank_relsint = fixture('rels_int_blank.xml').read
39
+ inner = mock("DigitalObject")
40
+ inner.stubs(:new?).returns(false)
41
+ inner.stubs(:pid).returns("test:relsint")
42
+ repo = mock("Repository")
43
+ # new datastream, no profile
44
+ repo.expects(:datastream).with(:pid=>inner.pid,:dsid=>"RELS-INT").returns(nil)
45
+ repo.expects(:config).returns({})
46
+ inner.stubs(:repository).returns(repo)
47
+ test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
48
+ Nokogiri::XML.parse(test_obj.content).should be_equivalent_to Nokogiri::XML.parse(blank_relsint)
49
+ end
50
+
37
51
  describe ActiveFedora::RelsInt::Datastream do
38
- it "should load relationships from foxml into the appropriate graphs" do
39
- test_relsint = fixture('rels_int_test.xml').read
40
- inner = mock("DigitalObject")
41
- inner.stubs(:pid).returns("test:relsint")
42
- inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
52
+ before :each do
53
+ @test_relsint = fixture('rels_int_test.xml').read
54
+ @inner = mock("DigitalObject")
55
+ @inner.stubs(:new?).returns(false)
56
+ @inner.stubs(:pid).returns("test:relsint")
57
+ @inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
43
58
  repo = mock("Repository")
44
59
  profile_xml = fixture('rels_int_profile.xml').read
45
- repo.expects(:datastream).with(:pid=>inner.pid,:dsid=>"RELS-INT").returns(profile_xml)
46
- repo.expects(:datastream_dissemination).with(:pid=>inner.pid,:dsid=>"RELS-INT").returns(test_relsint)
60
+ repo.expects(:datastream).with(:pid=>@inner.pid,:dsid=>"RELS-INT").returns(profile_xml)
61
+ repo.stubs(:datastream_dissemination).with(:pid=>@inner.pid,:dsid=>"RELS-INT").returns(@test_relsint)
47
62
  repo.stubs(:config).returns({})
48
- inner.stubs(:repository).returns(repo)
49
- test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
63
+ @inner.stubs(:repository).returns(repo)
64
+ end
65
+ it "should load relationships from foxml into the appropriate graphs" do
66
+ test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
50
67
  test_obj.changed?.should be_false
51
- dc = ActiveFedora::Datastream.new(inner,"DC")
68
+ dc = ActiveFedora::Datastream.new(@inner,"DC")
52
69
  triples = test_obj.relationships(dc,:is_metadata_for)
53
70
  e = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-INT'].
54
71
  map {|x| RDF::URI.new(x)}
55
72
  triples.should == [RDF::Statement.new(*e)]
56
73
  end
57
74
  it "should load relationships into appropriate graphs when assigned content" do
58
- test_relsint = fixture('rels_int_test.xml').read
59
- inner = mock("DigitalObject")
60
- inner.stubs(:pid).returns("test:relsint")
61
- inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
62
- test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
63
- test_obj.content=test_relsint
75
+ #test_relsint = fixture('rels_int_test.xml').read
76
+ #inner = mock("DigitalObject")
77
+ #inner.stubs(:pid).returns("test:relsint")
78
+ #inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
79
+ test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
80
+ test_obj.content=@test_relsint
64
81
  test_obj.changed?.should be_true
65
- dc = ActiveFedora::Datastream.new(inner,"DC")
82
+ dc = ActiveFedora::Datastream.new(@inner,"DC")
66
83
  triples = test_obj.relationships(dc,:is_metadata_for)
67
84
  e = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-INT'].
68
85
  map {|x| RDF::URI.new(x)}
69
86
  triples.should == [RDF::Statement.new(*e)]
70
87
  end
71
88
  it "should propagate relationship changes to the appropriate graph in RELS-INT" do
72
- test_relsint = fixture('rels_int_test.xml').read
73
- inner = mock("DigitalObject")
74
- inner.stubs(:pid).returns("test:relsint")
75
- inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
76
- test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
77
- dc = ActiveFedora::Datastream.new(inner,"DC")
78
- rels_ext = ActiveFedora::Datastream.new(inner,"RELS-EXT")
89
+ #test_relsint = fixture('rels_int_test.xml').read
90
+ #inner = mock("DigitalObject")
91
+ #inner.stubs(:pid).returns("test:relsint")
92
+ #inner.stubs(:internal_uri).returns("info:fedora/test:relsint")
93
+ test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
94
+ dc = ActiveFedora::Datastream.new(@inner,"DC")
95
+ rels_ext = ActiveFedora::Datastream.new(@inner,"RELS-EXT")
79
96
  test_obj.add_relationship(dc,:is_metadata_for, test_obj)
80
97
  test_obj.add_relationship(rels_ext,:asserts, "FOO", true)
81
98
  test_obj.add_relationship(test_obj,:asserts, "BAR", true)
82
99
  test_obj.serialize!
83
100
  test_obj.changed?.should be_true
84
101
  puts test_obj.content
85
- Nokogiri::XML.parse(test_obj.content).should be_equivalent_to Nokogiri::XML.parse(test_relsint)
102
+ Nokogiri::XML.parse(test_obj.content).should be_equivalent_to Nokogiri::XML.parse(@test_relsint)
86
103
  end
87
104
  end
88
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fedora_relsint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active-fedora
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 4.2.0
21
+ version: '5.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 4.2.0
29
+ version: '5.0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.5.11
53
+ version: 1.2.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.11
61
+ version: 1.2.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: yard
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +139,22 @@ dependencies:
139
139
  - - '='
140
140
  - !ruby/object:Gem::Version
141
141
  version: 0.10.5
142
+ - !ruby/object:Gem::Dependency
143
+ name: loggable
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
142
158
  description: ActiveFedora library to allow use of RELS-INT to track RDF assertions
143
159
  about datastreams via a similar api to the ActiveFedora RELS-EXT implementation
144
160
  email:
@@ -153,16 +169,35 @@ files:
153
169
  - Gemfile.lock
154
170
  - LICENSE.txt
155
171
  - README.textile
172
+ - Rakefile
156
173
  - active_fedora_relsint.gemspec
157
174
  - config/fedora.yml
158
175
  - config/predicate_mappings.yml
159
176
  - config/solr.yml
177
+ - doc/ActiveFedora.html
178
+ - doc/ActiveFedora/RelsInt.html
179
+ - doc/ActiveFedora/RelsInt/Datastream.html
180
+ - doc/_index.html
181
+ - doc/class_list.html
182
+ - doc/css/common.css
183
+ - doc/css/full_list.css
184
+ - doc/css/style.css
185
+ - doc/file.README.html
186
+ - doc/file_list.html
187
+ - doc/frames.html
188
+ - doc/index.html
189
+ - doc/js/app.js
190
+ - doc/js/full_list.js
191
+ - doc/js/jquery.js
192
+ - doc/method_list.html
193
+ - doc/top-level-namespace.html
160
194
  - fixtures/rels_int_blank.xml
161
195
  - fixtures/rels_int_profile.xml
162
196
  - fixtures/rels_int_test.xml
163
197
  - lib/active_fedora_relsint.rb
164
198
  - lib/active_fedora_relsint/datastream.rb
165
199
  - lib/active_fedora_relsint/version.rb
200
+ - lib/tasks/active_fedora_relsint_dev.rake
166
201
  - spec/spec_helper.rb
167
202
  - spec/unit/relsint_spec.rb
168
203
  homepage: https://github.com/cul/active_fedora_rels_int
@@ -192,3 +227,4 @@ summary: ActiveFedora library supporting RELS-INT datastreams
192
227
  test_files:
193
228
  - spec/spec_helper.rb
194
229
  - spec/unit/relsint_spec.rb
230
+ has_rdoc: