active-fedora 4.0.0.rc15 → 4.0.0.rc16
Sign up to get free protection for your applications and to get access to all the features.
- data/CONSOLE_GETTING_STARTED.textile +1 -383
- data/Gemfile.lock +3 -3
- data/History.txt +4 -1
- data/active-fedora.gemspec +1 -1
- data/config/predicate_mappings.yml +3 -1
- data/lib/active_fedora.rb +1 -0
- data/lib/active_fedora/associations/association_collection.rb +1 -1
- data/lib/active_fedora/base.rb +10 -3
- data/lib/active_fedora/model.rb +13 -14
- data/lib/active_fedora/rdf_datastream.rb +35 -13
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +17 -0
- data/lib/active_fedora/relationship_graph.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +1 -0
- data/spec/integration/base_spec.rb +2 -2
- data/spec/integration/model_spec.rb +6 -2
- data/spec/samples/samples.rb +1 -0
- data/spec/samples/special_thing.rb +1 -4
- data/spec/unit/base_spec.rb +12 -0
- data/spec/unit/model_spec.rb +32 -17
- data/spec/unit/ntriples_datastream_spec.rb +32 -0
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +23 -0
- data/spec/unit/relationships_spec.rb +1 -1
- metadata +14 -9
@@ -1,383 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
h2. Dependencies
|
4
|
-
|
5
|
-
You will need Ruby 1.8.7+ to go through this tutorial. If you don't have Ruby 1.8.7 installed, "RVM":https://rvm.beginrescueend.com/ is the best way to install it.
|
6
|
-
|
7
|
-
h2. Get a Copy of the Code
|
8
|
-
|
9
|
-
It is probably easiest to Because this tutorial uses the sample files included For this tutorial, you're cloning a full copy of the active-fedora code so you have access to the sample files that are stored there.
|
10
|
-
|
11
|
-
First, clone the git repository and cd into the root:
|
12
|
-
|
13
|
-
<pre>
|
14
|
-
git clone git@github.com:mediashelf/active_fedora.git
|
15
|
-
cd active_fedora
|
16
|
-
</pre>
|
17
|
-
|
18
|
-
If you don't have bundler installed yet, install it:
|
19
|
-
|
20
|
-
<pre>
|
21
|
-
gem install bundler
|
22
|
-
</pre>
|
23
|
-
|
24
|
-
Now let bundler handle installing active-fedora's dependencies:
|
25
|
-
|
26
|
-
<pre>
|
27
|
-
bundle install
|
28
|
-
</pre>
|
29
|
-
|
30
|
-
h2. Run Solr & Fedora
|
31
|
-
|
32
|
-
h3. Get a copy of hydra-jetty and start it (easiest)
|
33
|
-
|
34
|
-
"hydra-jetty":http://github.com/projecthydra/hydra-jetty is a copy of a Jetty server with Fedora and Solr installed and ready to use with ActiveFedora. Grab a copy and start it up.
|
35
|
-
|
36
|
-
<pre>
|
37
|
-
git clone git://github.com/projecthydra/hydra-jetty.git
|
38
|
-
cd hydra-jetty
|
39
|
-
java -jar start.jar
|
40
|
-
</pre>
|
41
|
-
|
42
|
-
This will start Jetty and spit a bunch of info out onto the console. Leave that terminal window open and open a new one to play around with ActiveFedora.
|
43
|
-
|
44
|
-
You can also set up your own copies of Fedora and Solr to run against. For info on that, see "Setting up Fedora and Solr for use with ActiveFedora":http://projects.mediashelf.us/projects/active-fedora/wiki/Setting_up_Fedora_and_Solr_for_use_with_ActiveFedora
|
45
|
-
|
46
|
-
h2. Open up the (Rails) Console (or, use irb)
|
47
|
-
|
48
|
-
<pre>
|
49
|
-
script/console
|
50
|
-
</pre>
|
51
|
-
|
52
|
-
<pre>
|
53
|
-
require "rubygems"
|
54
|
-
require "active-fedora"
|
55
|
-
require "active_fedora/samples" # these are the sample models and datastreams that come with ActiveFedora
|
56
|
-
</pre>
|
57
|
-
|
58
|
-
h2. Initialize ActiveFedora
|
59
|
-
|
60
|
-
In order to function, ActiveFedora needs to know where Fedora and Solr are running. It gets this information from a YAML file. You can see a sample fedora.yml in the ActiveFedora code on GitHub: "http://github.com/mediashelf/active_fedora/blob/master/config/fedora.yml":http://github.com/mediashelf/active_fedora/blob/master/config/fedora.yml
|
61
|
-
|
62
|
-
<pre>
|
63
|
-
ActiveFedora.init
|
64
|
-
I, [...] INFO -- : Using the default fedora.yml that comes with active-fedora.
|
65
|
-
If you want to override this, pass the path to fedora.yml as an argument to ActiveFedora.init or set RAILS_ROOT and put fedora.yml into #{RAILS_ROOT}/config.
|
66
|
-
I, [...] INFO -- : FEDORA: loading ActiveFedora config from /opt/local/lib/ruby/gems/1.8/gems/active-fedora-1.1.3/config/fedora.yml
|
67
|
-
I, [...] INFO -- : FEDORA: initializing ActiveFedora::SolrService with solr_config: {:url=>"http://127.0.0.1:8983/solr/development"}
|
68
|
-
I, [...8] INFO -- : FEDORA: initialized Solr with ActiveFedora.solr_config: #<ActiveFedora::SolrService:0x1021245f0 @conn=#<Solr::Connection:... >>>
|
69
|
-
I, [...] INFO -- : FEDORA: initializing Fedora with fedora_config: {:url=>"http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora"}
|
70
|
-
I, [...] INFO -- : FEDORA: initialized Fedora as: #<Fedora::Repository:0x102123b78 ....>
|
71
|
-
=> true
|
72
|
-
</pre>
|
73
|
-
|
74
|
-
As you can see, ActiveFedora.init defaults to using the fedora.yml included in the gem, which points to a local instance of jetty running on port 8983 with fedora and solr installed.
|
75
|
-
|
76
|
-
If you want to use a different yml file, put your info (pointing ActiveFedora to specific Fedora & Solr URLs) into the file and pass its path to ActiveFedora.init:
|
77
|
-
|
78
|
-
<pre>ActiveFedora.init(:fedora_config_path=>"path/to/fedora.yml")</pre>
|
79
|
-
|
80
|
-
h4. ActiveFedora within Rails
|
81
|
-
|
82
|
-
If you are running a rails app, ActiveFedora.init will automatically look for config/fedora.yml
|
83
|
-
|
84
|
-
Also, within a rails app, you should create a file in config/initializers (ie. fedora_config.rb) that calls ActiveFedora.init
|
85
|
-
|
86
|
-
h2. Load a Fixture Object To Play With
|
87
|
-
|
88
|
-
The ActiveFedora code includes sample Fedora objects (as foxml files) that you can load into a Fedora repository and play around with. Here we will load the one called hydrangea_fixture_mods_article1.foxml.xml:
|
89
|
-
|
90
|
-
<pre>
|
91
|
-
filename = File.join(File.dirname(__FILE__),"spec","fixtures", "hydrangea_fixture_mods_article1.foxml.xml")
|
92
|
-
file = File.new(filename, "r")
|
93
|
-
result = foxml = Fedora::Repository.instance.ingest(file.read)
|
94
|
-
</pre>
|
95
|
-
|
96
|
-
If you get an error that starts with the lines below, this means that you already have a copy of that object in fedora.
|
97
|
-
|
98
|
-
<pre>
|
99
|
-
Fedora::ServerError: Failed with 500 Error from Fedora: javax.ws.rs.WebApplicationException: org.fcrepo.server.errors.ObjectExistsException: The PID 'hydrangea:fixture_mods_article1' already exists in the registry; the object can't be re-created.
|
100
|
-
</pre>
|
101
|
-
|
102
|
-
The easiest way to delete an object from Fedora is to use the following line. Note that this will raise an error if the object didn't exist in the first place.
|
103
|
-
|
104
|
-
<pre>
|
105
|
-
ActiveFedora::Base.load_instance("hydrangea:fixture_mods_article1").delete
|
106
|
-
</pre>
|
107
|
-
|
108
|
-
|
109
|
-
To see a more complete implementation of importing and deleting Fedora objects, see the code in this gem's fedora rake tasks "https://github.com/mediashelf/active_fedora/blob/master/lib/tasks/fedora.rake":https://github.com/mediashelf/active_fedora/blob/master/lib/tasks/fedora.rake
|
110
|
-
|
111
|
-
|
112
|
-
*When you're done playing around with importing and deleting, make sure that you leave a copy of hydrangea:fixture_mods_article1 in fedora so we can play with it.*
|
113
|
-
|
114
|
-
|
115
|
-
h2. Define a Model for Your (Active)Fedora Objects
|
116
|
-
|
117
|
-
Look at the SpecialThing model defined in spec/samples/special_thing.rb to see how you declare an ActiveFedora model.
|
118
|
-
|
119
|
-
Create an instance of the SpecialThing class:
|
120
|
-
|
121
|
-
<pre>
|
122
|
-
newthing = SpecialThing.new
|
123
|
-
</pre>
|
124
|
-
|
125
|
-
Get the pid of your new object:
|
126
|
-
|
127
|
-
<pre>
|
128
|
-
newthing.pid
|
129
|
-
=> "changeme:30"
|
130
|
-
</pre>
|
131
|
-
|
132
|
-
This pid was retrieved from Fedora's getNextPid method.
|
133
|
-
|
134
|
-
Your object will not show up in the actual Fedora repository until you save it using newthing.save, but let's hold off on saving it for now.
|
135
|
-
|
136
|
-
h2. Fedora RELATIONSHIPS in ActiveFedora
|
137
|
-
|
138
|
-
ActiveFedora provides convenience methods for creating and editing Fedora RELS-EXT relationships. It also auto-generates methods for searching these relationships with Solr. (see https://github.com/projecthydra/solrizer and https://github.com/projecthydra/solrizer-fedora)
|
139
|
-
|
140
|
-
Use the relationships method to list the object's relationships:
|
141
|
-
|
142
|
-
<pre>
|
143
|
-
newthing.relationships
|
144
|
-
=> #<RDF::Graph:0x83a53088(<>)>
|
145
|
-
|
146
|
-
newthing.relationships.statements.map(&:inspect)
|
147
|
-
=> ["#<RDF::Statement:0x8371a858(<info:fedora/changeme:30> <info:fedora/fedora-system:def/model#hasModel> <info:fedora/hydra-cModel:DisplaySet> .)>",
|
148
|
-
"#<RDF::Statement:0x8371a6f0(<info:fedora/changeme:30> <info:fedora/fedora-system:def/model#hasModel> <info:fedora/hydra-cModel:CommonMetadata> .)>",
|
149
|
-
"#<RDF::Statement:0x8371a3e4(<info:fedora/changeme:30> <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/changeme:parentSet> .)>"]
|
150
|
-
|
151
|
-
newthing.relationships(:is_member_of)
|
152
|
-
=> ["info:fedora/changeme:parentSet"]
|
153
|
-
</pre>
|
154
|
-
|
155
|
-
The SpecialThing class definition contains these lines:
|
156
|
-
|
157
|
-
<pre>
|
158
|
-
#
|
159
|
-
# RELATIONSHIPS
|
160
|
-
#
|
161
|
-
|
162
|
-
# This is an example of how you can add a custom relationship to a model
|
163
|
-
# This will allow you to call .derivations on instances of the model to get a list of all of the _outbound_ "hasDerivation" relationships in the RELS-EXT datastream
|
164
|
-
has_relationship "derivations", :has_derivation
|
165
|
-
|
166
|
-
# This will allow you to call .inspirations on instances of the model to get a list of all of the objects that assert "hasDerivation" relationships pointing at this object
|
167
|
-
has_relationship "inspirations", :has_derivation, :inbound => true
|
168
|
-
</pre>
|
169
|
-
|
170
|
-
ActiveFedora creates methods for the SpecialThing object based on has_relationship lines. So we can call the "inspirations" method that is automatically created by ActiveFedora:
|
171
|
-
|
172
|
-
<pre>
|
173
|
-
newthing.inspirations
|
174
|
-
=> []
|
175
|
-
</pre>
|
176
|
-
|
177
|
-
This method is actually making a search request to Solr -- it is looking in Solr to see if the "newthing" object has any "inspirations" relationships.
|
178
|
-
|
179
|
-
Now we'll create another Fedora object (using the default ActiveFedora object model) and we'll use ActiveFedora's add_relationship method to relate our new object to the SpecialThing object. We'll also save our new object in our Fedora repository.
|
180
|
-
|
181
|
-
<pre>
|
182
|
-
newobj = ActiveFedora::Base.new
|
183
|
-
newobj.add_relationship(:has_derivation, newthing)
|
184
|
-
=> true
|
185
|
-
|
186
|
-
newobj.relationships
|
187
|
-
=> #<RDF::Graph:0x83a53088(<>)>
|
188
|
-
|
189
|
-
newobj.relationships.statements.map(&:inspect)
|
190
|
-
=> ["#<RDF::Statement:0x8371a3e4(<info:fedora/changeme:30> <info:fedora/fedora-system:def/relations-external#hasDerivation> <info:fedora/changeme:30> .)>"]
|
191
|
-
|
192
|
-
newobj.relationships(:has_derivation)
|
193
|
-
=> ["info:fedora/changeme:30"]
|
194
|
-
|
195
|
-
|
196
|
-
newobj.save
|
197
|
-
=> ...
|
198
|
-
newobj.pid
|
199
|
-
=> "changeme:164" # this is the pid you want to put in the following URLs as a replacement for (PID)
|
200
|
-
</pre>
|
201
|
-
|
202
|
-
You can see objects in Fedora by going to http://localhost:8983/fedora/objects/(PID) and you can see the relationships for an object by looking at the RELS-EXT datastream content: http://localhost: 8983/fedora/objects/(PID)/datastreams/RELS-EXT/content
|
203
|
-
|
204
|
-
Now let's see if the "newthing" object has an "inspiration" relationship with our "newobj"
|
205
|
-
|
206
|
-
<pre>
|
207
|
-
newthing.inspirations
|
208
|
-
=> ... (FIXME: put expected output here)
|
209
|
-
newthing.inspirations.each {|pt| puts pt.pid }
|
210
|
-
=> ... (FIXME: put expected output here)
|
211
|
-
newthing.inspirations(:response_format=>:id_array)
|
212
|
-
=> ... (FIXME: put expected output here)
|
213
|
-
</pre>
|
214
|
-
|
215
|
-
Note that you didn't have to save the "newthing" object in order for this relationship to show up in Solr because it is an inbound relationship.
|
216
|
-
|
217
|
-
Only the ActiveFedora object making the assertion needs to be saved in order for the search to work. In our example above, new_obj asserts :has_derivation (rather than the derivative asserting :is_derivation_of), so only new_obj had to be saved.
|
218
|
-
|
219
|
-
|
220
|
-
h2. Fedora DATASTREAMS & METADATA in ActiveFedora
|
221
|
-
|
222
|
-
h3. Blobs (a.k.a. File Datastreams, a.k.a Managed Content Datastreams)
|
223
|
-
|
224
|
-
Here we create a simple Datastream (using the default Datastream model).
|
225
|
-
|
226
|
-
<pre>
|
227
|
-
file = File.new('spec/fixtures/minivan.jpg')
|
228
|
-
=> #<File:spec/fixtures/minivan.jpg>
|
229
|
-
file_ds = ActiveFedora::Datastream.new(:dsID => "minivan", :dsLabel => 'hello', :controlGroup => 'M', :blob => file)
|
230
|
-
=> ...
|
231
|
-
newthing.add_datastream(file_ds)
|
232
|
-
=> "minivan"
|
233
|
-
newthing.save
|
234
|
-
=> true
|
235
|
-
</pre>
|
236
|
-
|
237
|
-
Now use your browser to find the file datastreams in Fedora ...
|
238
|
-
|
239
|
-
|
240
|
-
h3. On auto-generating datastream ids
|
241
|
-
|
242
|
-
If you don't specify a dsid, ActiveFedora will generate one for you. In the example below, "DS1" is the dsID assigned to the new datastream
|
243
|
-
|
244
|
-
<pre>
|
245
|
-
file_ds2 = ActiveFedora::Datastream.new(:dsLabel => 'Minivan Plays', :altIDs => 'default', :controlGroup => 'M', :blob => file)
|
246
|
-
newthing.add_datastream(file_ds2)
|
247
|
-
=> "DS1"
|
248
|
-
newthing.datastreams.keys
|
249
|
-
=> ["DS1", "descMetadata", "minivan", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun"]
|
250
|
-
newthing.datastreams_in_memory["DS1"] == file_ds2
|
251
|
-
=> true
|
252
|
-
</pre>
|
253
|
-
|
254
|
-
You can choose a different prefix for the dsid by passing a :prefix value to add_datastream (be careful to ensure that the resulting dsid is a valid XMLString, or fedora will reject it!)
|
255
|
-
|
256
|
-
<pre>
|
257
|
-
file_ds3 = ActiveFedora::Datastream.new(:dsLabel => 'Minivan Plays', :altIDs => 'default', :controlGroup => 'M', :blob => file)
|
258
|
-
newthing.add_datastream(file_ds3, :prefix=>"Foo")
|
259
|
-
=> "Foo1"
|
260
|
-
newthing.datastreams.keys
|
261
|
-
newthing.save
|
262
|
-
</pre>
|
263
|
-
|
264
|
-
h2. Retrieving Existing Fedora Repository Objects
|
265
|
-
|
266
|
-
When you want your code to interact with existing digital objects in a Fedora repository, use the ActiveFedora load_instance method.
|
267
|
-
|
268
|
-
You can use the load_instance class method on any kind of ActiveFedora::Base class to load objects from Fedora. In the example below, the ActiveFedora object model for "copy_as_base" is ActiveFedora::Base.
|
269
|
-
|
270
|
-
<pre>
|
271
|
-
newthing.pid
|
272
|
-
=> "changeme:30"
|
273
|
-
copy_as_base = ActiveFedora::Base.load_instance("changeme:30")
|
274
|
-
copy_as_base.pid
|
275
|
-
=> "changeme:30"
|
276
|
-
newthing.datastreams.keys
|
277
|
-
=> ["DS1", "descMetadata", "Foo1", "minivan", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun"]
|
278
|
-
copy_as_base.datastreams.keys
|
279
|
-
=> ["DS1", "descMetadata", "Foo1", "minivan", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun"]
|
280
|
-
</pre>
|
281
|
-
|
282
|
-
As you can see, ActiveFedora::Base will load the object, its datastreams, its generic Fedora Object information, and even its RELS-EXT relationships. It will _not_, however, know how to deserialize any model-specific metadata datastreams. In other words, *ActiveFedora::Base treats all datastreams as generic Fedora datastreams*.
|
283
|
-
|
284
|
-
<pre>
|
285
|
-
copy_as_base.datastreams["extraMetadataForFun"].class
|
286
|
-
=> ActiveFedora::Datastream
|
287
|
-
</pre>
|
288
|
-
|
289
|
-
If you want the model-specific metadata to be deserialized, you must call load_instance on the appropriate ActiveFedora model class. This will load all of the same info as ActiveFedora::Base, but it will also attempt to deserialize the xml from any metadata datastreams that were declared by the has_metadata method in the model.
|
290
|
-
|
291
|
-
<pre>
|
292
|
-
copy_as_specialthing = SpecialThing.load_instance(newthing.pid)
|
293
|
-
copy_as_specialthing.datastreams["descMetadata"].class
|
294
|
-
=> Hydra::ModsArticleDatastream
|
295
|
-
copy_as_specialthing.datastreams["extraMetadataForFun"].class
|
296
|
-
=> ActiveFedora::Marpa::DcDatastream
|
297
|
-
</pre>
|
298
|
-
|
299
|
-
|
300
|
-
You can use "find" instead of "load_instance". In practice, we tend to use load_instance though -- it's more direct.
|
301
|
-
|
302
|
-
<pre>
|
303
|
-
Base.find("changeme:30")
|
304
|
-
SpecialThing.find("changeme:30")
|
305
|
-
</pre>
|
306
|
-
|
307
|
-
|
308
|
-
h3. Finding Fedora Repository Objects of the Same Class
|
309
|
-
|
310
|
-
All descendants of the ActiveFedora::Base class inherit the "find" method which searches Solr for Fedora repository objects of the given class. The method is somewhat incomplete at the moment, but is functional. We are actively working on making it better.
|
311
|
-
|
312
|
-
h3. Finding Instances of the Class
|
313
|
-
|
314
|
-
Imitating ActiveRecord, the find(:all) method (inherited from the ActiveFedora::Base class) searches for instances of the calling class. In current versions of the gem, this method searches solr using the active_fedora_model_field. In future versions it will not hit solr at all, instead relying on Fedora's Resource Index and searching for anything that asserts "conformsTo" or "hasModel" relationships pointing at the given model.
|
315
|
-
|
316
|
-
<pre>
|
317
|
-
ActiveFedora::Base.find(:all)
|
318
|
-
SpecialThing.find(:all)
|
319
|
-
</pre>
|
320
|
-
|
321
|
-
You can also query solr directly like so:
|
322
|
-
|
323
|
-
<pre>
|
324
|
-
solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_s:info\:fedora/afmodel\:SpecialThing')
|
325
|
-
</pre>
|
326
|
-
|
327
|
-
This query will return a Solr::Result containing all of the objects that have conformsTo relationships pointing at info:fedora/afmodel:SpecialThing in their RELS-EXT. This relationship gets added to the RELS-EXT whenever you save an object as a given ActiveFedora model and it does not get erased if you later save it as a different model.
|
328
|
-
|
329
|
-
|
330
|
-
h2. More About ActiveFedora Models
|
331
|
-
|
332
|
-
ActiveFedora Models for Fedora objects don't actually do much. They mainly keep a list of datastream ids and associate them with classes that help you use the content from those datastreams.
|
333
|
-
|
334
|
-
Let's load an instance of the SpecialThing model and take a look at its datastreams.
|
335
|
-
|
336
|
-
<pre>
|
337
|
-
st = SpecialThing.load_instance("hydrangea:fixture_mods_article1")
|
338
|
-
st.datastreams
|
339
|
-
... woah. that's a lot of stuff. how about just the datastream ids
|
340
|
-
st.datastreams.keys
|
341
|
-
=> ["descMetadata", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun", "properties"]
|
342
|
-
</pre>
|
343
|
-
|
344
|
-
We see the three datastreams that are declared by the SpecialThing Model, but where did the other datastreams come from?
|
345
|
-
|
346
|
-
h3. Default Fedora Datastreams
|
347
|
-
|
348
|
-
The RELS-EXT is where Fedora objects store their relationships, so SpecialThing uses that datastream when it uses the methods created by has_relationship.
|
349
|
-
|
350
|
-
The other two datastreams, DC and properties, were already there in the object we imported. Our model doesn't define anything about those datastreams, so they are loaded as mere ActiveFedora::Datastreams. When a datastream is loaded in this way, you can still see it and access/update its content as a blob, but your model doesn't know anything special about its contents. This behavior is what allows us to have multiple interfaces for the same content. One model might care only about the descMetadata and the properties while another model only cares about the descMetadata and rightsMetadata. The two models only need to be consistent with each other when they are both operating on the same datastream in the same object.
|
351
|
-
|
352
|
-
Let's see what classes the datastreams have been bound to
|
353
|
-
|
354
|
-
<pre>
|
355
|
-
st.datastreams.keys.each do |dsid|
|
356
|
-
puts "#{dsid}:"
|
357
|
-
puts " #{st.datastreams[dsid].class}"
|
358
|
-
end
|
359
|
-
</pre>
|
360
|
-
|
361
|
-
This will output
|
362
|
-
|
363
|
-
<pre>
|
364
|
-
descMetadata:
|
365
|
-
Hydra::ModsArticleDatastream
|
366
|
-
RELS-EXT:
|
367
|
-
ActiveFedora::RelsExtDatastream
|
368
|
-
rightsMetadata:
|
369
|
-
Hydra::RightsMetadataDatastream
|
370
|
-
DC:
|
371
|
-
ActiveFedora::Datastream
|
372
|
-
extraMetadataForFun:
|
373
|
-
Marpa::DcDatastream
|
374
|
-
properties:
|
375
|
-
ActiveFedora::Datastream
|
376
|
-
</pre>
|
377
|
-
|
378
|
-
Notice that properties and DC have been loaded as ActiveFedora::Datastream, RELS-EXT has been loaded as ActiveFedora::RelsExtDatastream, and the other three have been loaded as the classes specified in the Model.
|
379
|
-
|
380
|
-
h2. Where to Find More Information
|
381
|
-
|
382
|
-
You can examine the files in lib/active_fedora/samples to learn more about how to define ActiveFedora models and OM-based datastreams. We also suggest you read about "OM-based NokogiriDatastreams":http://hudson.projecthydra.org/job/active_fedora/Documentation/file.NOKOGIRI_DATASTREAMS.html to learn about manipulating XML contained in datastreams.
|
383
|
-
|
1
|
+
Moved to "https://github.com/mediashelf/active_fedora/wiki/Getting-Started:---Console-Tour":https://github.com/mediashelf/active_fedora/wiki/Getting-Started:---Console-Tour
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (4.0.0.
|
4
|
+
active-fedora (4.0.0.rc16)
|
5
5
|
activeresource (>= 3.0.0)
|
6
6
|
activesupport (>= 3.0.0)
|
7
7
|
equivalent-xml
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
mime-types (>= 1.16)
|
10
10
|
multipart-post (= 1.1.2)
|
11
11
|
nokogiri
|
12
|
-
om (
|
12
|
+
om (~> 1.6.0.rc1)
|
13
13
|
rdf
|
14
14
|
rdf-rdfxml (= 0.3.5)
|
15
15
|
rsolr
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
multipart-post (1.1.2)
|
64
64
|
nokogiri (1.5.2)
|
65
65
|
nori (1.1.0)
|
66
|
-
om (1.
|
66
|
+
om (1.6.0.rc1)
|
67
67
|
mediashelf-loggable
|
68
68
|
nokogiri (>= 1.4.2)
|
69
69
|
rack (1.4.1)
|
data/History.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
4.0.0.
|
1
|
+
4.0.0.rc16
|
2
2
|
Removed deprecations
|
3
3
|
* allowing :fedora level in fedora.yml
|
4
4
|
* automatic includes of Relationships and FileMethods is removed
|
@@ -21,6 +21,9 @@ Fixes for Ruby 1.9 compatibility
|
|
21
21
|
HYDRA-741 Use fixture loader in repo:* rake tasks. Parameters changed to foxml and dir.
|
22
22
|
rubydora to 0.5.7
|
23
23
|
Lazily load solr config
|
24
|
+
HYDRA-766 Model#classname_from_uri singularizes terms, but it shouldn't change them.
|
25
|
+
HYDRA-767 Remove Model::DEFAULT_NS
|
26
|
+
Upgrade Om to 1.6.0
|
24
27
|
|
25
28
|
3.3.2
|
26
29
|
HYDRA-745 No need to require :url be present on external datastreams
|
data/active-fedora.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency('mime-types', '>= 1.16')
|
21
21
|
s.add_dependency('multipart-post', "= 1.1.2")
|
22
22
|
s.add_dependency('nokogiri')
|
23
|
-
s.add_dependency('om', '
|
23
|
+
s.add_dependency('om', '~> 1.6.0.rc1')
|
24
24
|
s.add_dependency('solrizer', '~>1.2.0')
|
25
25
|
s.add_dependency("activeresource", '>= 3.0.0')
|
26
26
|
s.add_dependency("activesupport", '>= 3.0.0')
|
@@ -40,7 +40,9 @@
|
|
40
40
|
:is_subset_of: isSubsetOf
|
41
41
|
:is_topic_of: isTopicOf
|
42
42
|
info:fedora/fedora-system:def/model#:
|
43
|
-
:
|
43
|
+
:is_contractor_of: isContractorOf
|
44
|
+
:is_deployment_of: isDeploymentOf
|
44
45
|
:has_service: hasService
|
46
|
+
:has_model: hasModel
|
45
47
|
http://www.openarchives.org/OAI/2.0/:
|
46
48
|
:oai_item_id: itemID
|
data/lib/active_fedora.rb
CHANGED
data/lib/active_fedora/base.rb
CHANGED
@@ -252,7 +252,8 @@ module ActiveFedora
|
|
252
252
|
# end
|
253
253
|
|
254
254
|
datastreams.each_value do |ds|
|
255
|
-
ds.to_xml(fields_xml) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper)
|
255
|
+
ds.to_xml(fields_xml) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper)
|
256
|
+
ds.to_rels_ext if ds.kind_of?(ActiveFedora::RelsExtDatastream)
|
256
257
|
end
|
257
258
|
return xml.to_s
|
258
259
|
end
|
@@ -324,6 +325,12 @@ module ActiveFedora
|
|
324
325
|
end
|
325
326
|
klass.allocate.init_with(inner_object)
|
326
327
|
end
|
328
|
+
|
329
|
+
# Examine the :has_model assertions in the RELS-EXT. Adapt this class to the first first known model
|
330
|
+
def adapt_to_cmodel
|
331
|
+
the_model = ActiveFedora::ContentModel.known_models_for( self ).first
|
332
|
+
self.class != the_model ? self.adapt_to(the_model) : self
|
333
|
+
end
|
327
334
|
|
328
335
|
# ** EXPERIMENTAL **
|
329
336
|
# This method returns a new object of the same class, with the internal SolrDigitalObject
|
@@ -359,10 +366,10 @@ module ActiveFedora
|
|
359
366
|
def self.load_instance_from_solr(pid,solr_doc=nil)
|
360
367
|
if solr_doc.nil?
|
361
368
|
result = find_by_solr(pid)
|
362
|
-
raise "Object #{pid} not found in solr" if result.nil?
|
369
|
+
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} not found in solr" if result.nil?
|
363
370
|
solr_doc = result.first
|
364
371
|
#double check pid and id in record match
|
365
|
-
raise "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
|
372
|
+
raise ActiveFedora::ObjectNotFoundError, "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
|
366
373
|
else
|
367
374
|
raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
|
368
375
|
end
|
data/lib/active_fedora/model.rb
CHANGED
@@ -5,8 +5,6 @@ module ActiveFedora
|
|
5
5
|
# This module mixes various methods into the including class,
|
6
6
|
# much in the way ActiveRecord does.
|
7
7
|
module Model
|
8
|
-
DEFAULT_NS = 'afmodel'
|
9
|
-
|
10
8
|
def self.included(klass) # :nodoc:
|
11
9
|
klass.extend(ClassMethods)
|
12
10
|
end
|
@@ -15,7 +13,7 @@ module ActiveFedora
|
|
15
13
|
def self.classname_from_uri(uri)
|
16
14
|
local_path = uri.split('/')[1]
|
17
15
|
parts = local_path.split(':')
|
18
|
-
return parts[-1].split(/_/).map(&:
|
16
|
+
return parts[-1].split(/_/).map(&:camelize).join('::'), parts[0]
|
19
17
|
end
|
20
18
|
|
21
19
|
# Takes a Fedora URI for a cModel, and returns a
|
@@ -36,7 +34,7 @@ module ActiveFedora
|
|
36
34
|
result = Kernel.const_get(model_value)
|
37
35
|
end
|
38
36
|
unless result.nil?
|
39
|
-
model_ns = (result.respond_to? :pid_namespace) ? result.pid_namespace :
|
37
|
+
model_ns = (result.respond_to? :pid_namespace) ? result.pid_namespace : ContentModel::CMODEL_NAMESPACE
|
40
38
|
if model_ns != pid_ns
|
41
39
|
logger.warn "Model class namespace '#{model_ns}' does not match uri: '#{uri}'"
|
42
40
|
end
|
@@ -96,9 +94,13 @@ module ActiveFedora
|
|
96
94
|
"info:fedora/#{namespace}:#{ContentModel.sanitized_class_name(self)}#{pid_suffix}"
|
97
95
|
end
|
98
96
|
|
99
|
-
# Takes :all or a pid as arguments
|
100
97
|
# Returns an Array of objects of the Class that +find+ is being
|
101
98
|
# called on
|
99
|
+
#
|
100
|
+
# @param[String,Symbol] either a pid or :all
|
101
|
+
# @param [Hash] opts the options to create a message with.
|
102
|
+
# @option opts [Integer] :rows when :all is passed, the maximum number of rows to load from solr
|
103
|
+
# @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
102
104
|
def find(args, opts={})
|
103
105
|
opts = {:rows=>25}.merge(opts)
|
104
106
|
if args == :all
|
@@ -107,10 +109,10 @@ module ActiveFedora
|
|
107
109
|
hits = SolrService.query(q, :rows=>opts[:rows])
|
108
110
|
return hits.map do |hit|
|
109
111
|
pid = hit[SOLR_DOCUMENT_ID]
|
110
|
-
find_one(pid)
|
112
|
+
find_one(pid, opts[:cast])
|
111
113
|
end
|
112
114
|
elsif args.class == String
|
113
|
-
return find_one(args)
|
115
|
+
return find_one(args, opts[:cast])
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
@@ -272,18 +274,15 @@ module ActiveFedora
|
|
272
274
|
# using #{ActiveFedora::ContentModel.known_models_for} and cast to that class.
|
273
275
|
# Raises a ObjectNotFoundError if the object is not found.
|
274
276
|
# @param [String] pid of the object to load
|
277
|
+
# @param [Boolean] cast when true, cast the found object to the class of the first known model defined in it's RELS-EXT
|
275
278
|
#
|
276
279
|
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel info:fedora/afmodel:Dataset), return a Dataset object (not a Book).
|
277
280
|
# Book.find_one("hydra:dataset1")
|
278
|
-
def find_one(pid)
|
281
|
+
def find_one(pid, cast=false)
|
279
282
|
inner = DigitalObject.find(self, pid)
|
280
|
-
raise ActiveFedora::ObjectNotFoundError if inner.new?
|
283
|
+
raise ActiveFedora::ObjectNotFoundError, "Unable to find '#{pid}' in fedora" if inner.new?
|
281
284
|
af_base = self.allocate.init_with(inner)
|
282
|
-
|
283
|
-
if af_base.class != the_model
|
284
|
-
return af_base.adapt_to(the_model)
|
285
|
-
end
|
286
|
-
af_base
|
285
|
+
cast ? af_base.adapt_to_cmodel : af_base
|
287
286
|
end
|
288
287
|
|
289
288
|
end
|
@@ -32,10 +32,23 @@ module ActiveFedora
|
|
32
32
|
pre = self.to_s.sub(/RDFDatastream$/, '').underscore
|
33
33
|
return "#{pre}__#{name}".to_sym
|
34
34
|
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Register a ruby block that evaluates to the subject of the graph
|
38
|
+
# By default, the block returns the current object's pid
|
39
|
+
# @yield [ds] 'ds' is the datastream instance
|
40
|
+
def rdf_subject &block
|
41
|
+
if block_given?
|
42
|
+
return @subject_block = block
|
43
|
+
end
|
44
|
+
|
45
|
+
@subject_block ||= lambda { |ds| "info:fedora/#{ds.pid}" }
|
46
|
+
end
|
47
|
+
|
35
48
|
def register_vocabularies(*vocabs)
|
36
49
|
@vocabularies = {}
|
37
50
|
vocabs.each do |v|
|
38
|
-
if v.respond_to? :property and v.respond_to? :to_uri
|
51
|
+
if v.is_a?(RDF::Vocabulary) or (v.respond_to? :property and v.respond_to? :to_uri)
|
39
52
|
@vocabularies[v.to_uri] = v
|
40
53
|
else
|
41
54
|
raise "not an RDF vocabulary: #{v}"
|
@@ -150,23 +163,26 @@ module ActiveFedora
|
|
150
163
|
|
151
164
|
# returns a Hash, e.g.: {field => {:values => [], :type => :something, :behaviors => []}, ...}
|
152
165
|
def fields
|
166
|
+
ensure_loaded
|
153
167
|
field_map = {}
|
154
168
|
graph.relationships.each do |predicate, values|
|
155
169
|
vocab_sym, name = predicate.qname
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
170
|
+
uri, vocab = self.class.vocabularies.select { |ns, v| v.__prefix__ == vocab_sym }.first
|
171
|
+
next unless vocab
|
172
|
+
|
173
|
+
config = self.class.config[:predicate_mapping][vocab.to_s]
|
174
|
+
|
175
|
+
name, indexed_as = config.select { |k, v| name.to_s == v.to_s && k.to_s.split("__")[0] == self.class.prefix(name).to_s.split("__")[0]}.first
|
176
|
+
next unless name and config.has_key?("#{name}type".to_sym) and config.has_key?("#{name}behaviors".to_sym)
|
177
|
+
type = config["#{name}type".to_sym]
|
178
|
+
behaviors = config["#{name}behaviors".to_sym]
|
164
179
|
field_map[name.to_sym] = {:values => values.map {|v| v.to_s}, :type => type, :behaviors => behaviors}
|
165
180
|
end
|
166
181
|
field_map
|
167
182
|
end
|
168
183
|
|
169
184
|
def to_solr(solr_doc = Hash.new) # :nodoc:
|
185
|
+
ensure_loaded
|
170
186
|
fields.each do |field_key, field_info|
|
171
187
|
values = field_info.fetch(:values, false)
|
172
188
|
if values
|
@@ -201,7 +217,7 @@ module ActiveFedora
|
|
201
217
|
return if results.nil?
|
202
218
|
values = []
|
203
219
|
results.each do |object|
|
204
|
-
values << (object.kind_of?(RDF::Literal) ? object.value : object.
|
220
|
+
values << (object.kind_of?(RDF::Literal) ? object.value : object.to_s)
|
205
221
|
end
|
206
222
|
TermProxy.new(graph, predicate, values)
|
207
223
|
end
|
@@ -243,6 +259,12 @@ module ActiveFedora
|
|
243
259
|
super
|
244
260
|
end
|
245
261
|
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# Get the subject for this rdf/xml datastream
|
265
|
+
def rdf_subject
|
266
|
+
@subject ||= self.class.rdf_subject.call(self)
|
267
|
+
end
|
246
268
|
|
247
269
|
# Populate a RDFDatastream object based on the "datastream" content
|
248
270
|
# Assumes that the datastream contains RDF XML from a Fedora RELS-EXT datastream
|
@@ -251,9 +273,9 @@ module ActiveFedora
|
|
251
273
|
unless data.nil?
|
252
274
|
RDF::Reader.for(serialization_format).new(data) do |reader|
|
253
275
|
reader.each_statement do |statement|
|
254
|
-
next unless statement.subject ==
|
276
|
+
next unless statement.subject == rdf_subject
|
255
277
|
literal = statement.object.kind_of?(RDF::Literal)
|
256
|
-
object = literal ? statement.object.value : statement.object.
|
278
|
+
object = literal ? statement.object.value : statement.object.to_s
|
257
279
|
graph.add(statement.predicate, object, literal)
|
258
280
|
end
|
259
281
|
end
|
@@ -265,7 +287,7 @@ module ActiveFedora
|
|
265
287
|
# Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array
|
266
288
|
def serialize
|
267
289
|
out = RDF::Writer.for(serialization_format).buffer do |writer|
|
268
|
-
graph.to_graph(
|
290
|
+
graph.to_graph(rdf_subject).each_statement do |statement|
|
269
291
|
writer << statement
|
270
292
|
end
|
271
293
|
end
|
@@ -3,4 +3,5 @@
|
|
3
3
|
<info:fedora/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
|
4
4
|
<info:fedora/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
|
5
5
|
<info:fedora/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
|
6
|
+
<info:fedora/test:1/content> <http://purl.org/dc/terms/title> "Title of datastream" .
|
6
7
|
|
@@ -41,7 +41,7 @@ describe "has_metadata" do
|
|
41
41
|
@obj.save
|
42
42
|
end
|
43
43
|
it "should save the datastream." do
|
44
|
-
ActiveFedora::Base.find(@obj.pid).foo.person.should == ['bob']
|
44
|
+
ActiveFedora::Base.find(@obj.pid, :cast=>true).foo.person.should == ['bob']
|
45
45
|
ActiveFedora::SolrService.query("id:#{@obj.pid.gsub(":", "\\:")}", :fl=>'id person_t').first.should == {"id"=>@obj.pid, 'person_t'=>['bob']}
|
46
46
|
end
|
47
47
|
end
|
@@ -56,7 +56,7 @@ describe "has_metadata" do
|
|
56
56
|
@obj.save
|
57
57
|
end
|
58
58
|
it "should save the datastream." do
|
59
|
-
ActiveFedora::Base.find(@obj.pid).foo.person.should == ['frank']
|
59
|
+
ActiveFedora::Base.find(@obj.pid, :cast=>true).foo.person.should == ['frank']
|
60
60
|
ActiveFedora::SolrService.query("id:#{@obj.pid.gsub(":", "\\:")}", :fl=>'id person_t').first.should == {"id"=>@obj.pid, 'person_t'=>['frank']}
|
61
61
|
end
|
62
62
|
end
|
@@ -42,10 +42,14 @@ describe ActiveFedora::Model do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
describe "#find with a valid pid" do
|
46
|
-
subject { ActiveFedora::Base.find('hydrangea:fixture_mods_article1') }
|
45
|
+
describe "#find with a valid pid with cast" do
|
46
|
+
subject { ActiveFedora::Base.find('hydrangea:fixture_mods_article1', :cast=>true) }
|
47
47
|
it { should be_instance_of HydrangeaArticle}
|
48
48
|
end
|
49
|
+
describe "#find with a valid pid without cast" do
|
50
|
+
subject { ActiveFedora::Base.find('hydrangea:fixture_mods_article1') }
|
51
|
+
it { should be_instance_of ActiveFedora::Base}
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
|
data/spec/samples/samples.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
# require "active_fedora/samples/hydra-mods_article_datastream.rb"
|
3
|
-
# require "active_fedora/samples/hydra-rights_metadata_datastream.rb"
|
4
|
-
# require "active_fedora/samples/marpa-dc_datastream.rb"
|
1
|
+
require "spec/samples/marpa-dc_datastream.rb"
|
5
2
|
|
6
3
|
# This is an example of an ActiveFedora Model
|
7
4
|
#
|
data/spec/unit/base_spec.rb
CHANGED
@@ -505,6 +505,18 @@ describe ActiveFedora::Base do
|
|
505
505
|
end
|
506
506
|
end
|
507
507
|
|
508
|
+
describe ".adapt_to_cmodel" do
|
509
|
+
subject { FooHistory.new }
|
510
|
+
it "should cast when a cmodel is found" do
|
511
|
+
ActiveFedora::ContentModel.expects(:known_models_for).with( subject).returns([FooAdaptation])
|
512
|
+
subject.adapt_to_cmodel.should be_kind_of FooAdaptation
|
513
|
+
end
|
514
|
+
it "should not cast when a cmodel is same as the class" do
|
515
|
+
ActiveFedora::ContentModel.expects(:known_models_for).with( subject).returns([FooHistory])
|
516
|
+
subject.adapt_to_cmodel.should === subject
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
508
520
|
describe ".to_xml" do
|
509
521
|
it "should provide .to_xml" do
|
510
522
|
@test_object.should respond_to(:to_xml)
|
data/spec/unit/model_spec.rb
CHANGED
@@ -69,21 +69,29 @@ describe ActiveFedora::Model do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe '#find' do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
72
|
+
describe "without :cast" do
|
73
|
+
it "(:all) should query solr for all objects with :active_fedora_model_s of self.class" do
|
74
|
+
ActiveFedora::SolrService.expects(:query).with('has_model_s:info\\:fedora/afmodel\\:SpecModel_Basic', :rows=>1001).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
|
75
|
+
SpecModel::Basic.expects(:find_one).with("changeme:30", nil).returns("Fake Object1")
|
76
|
+
SpecModel::Basic.expects(:find_one).with("changeme:22", nil).returns("Fake Object2")
|
77
|
+
SpecModel::Basic.find(:all, :rows=>1001).should == ["Fake Object1", "Fake Object2"]
|
78
|
+
end
|
79
|
+
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
80
|
+
SpecModel::Basic.any_instance.expects(:init_with).returns(SpecModel::Basic.new)
|
81
|
+
ActiveFedora::DigitalObject.expects(:find).returns(stub("inner obj", :'new?'=>false))
|
82
|
+
SpecModel::Basic.find("_PID_").should be_a SpecModel::Basic
|
83
|
+
end
|
84
|
+
it "should raise an exception if it is not found" do
|
85
|
+
SpecModel::Basic.expects(:connection_for_pid).with("_PID_")
|
86
|
+
lambda {SpecModel::Basic.find("_PID_")}.should raise_error ActiveFedora::ObjectNotFoundError
|
87
|
+
end
|
83
88
|
end
|
84
|
-
|
85
|
-
SpecModel::Basic.
|
86
|
-
|
89
|
+
describe "with :cast" do
|
90
|
+
it "should use SpecModel::Basic.allocate.init_with to instantiate an object" do
|
91
|
+
SpecModel::Basic.any_instance.expects(:init_with).returns(mock("Model", :adapt_to_cmodel=>SpecModel::Basic.new ))
|
92
|
+
ActiveFedora::DigitalObject.expects(:find).returns(stub("inner obj", :'new?'=>false))
|
93
|
+
SpecModel::Basic.find("_PID_", :cast=>true)
|
94
|
+
end
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
@@ -154,9 +162,16 @@ describe ActiveFedora::Model do
|
|
154
162
|
its(:to_class_uri) {should == 'info:fedora/afmodel:SpecModel_CamelCased-TEST-SUFFIX' }
|
155
163
|
end
|
156
164
|
|
157
|
-
|
158
|
-
|
159
|
-
|
165
|
+
describe ".classname_from_uri" do
|
166
|
+
it "should turn an afmodel URI into a Model class name" do
|
167
|
+
ActiveFedora::Model.classname_from_uri('info:fedora/afmodel:SpecModel_CamelCased').should == ['SpecModel::CamelCased', 'afmodel']
|
168
|
+
end
|
169
|
+
it "should not change plurality" do
|
170
|
+
ActiveFedora::Model.classname_from_uri('info:fedora/afmodel:MyMetadata').should == ['MyMetadata', 'afmodel']
|
171
|
+
end
|
172
|
+
it "should capitalize the first letter" do
|
173
|
+
ActiveFedora::Model.classname_from_uri('info:fedora/afmodel:image').should == ['Image', 'afmodel']
|
174
|
+
end
|
160
175
|
end
|
161
176
|
end
|
162
177
|
|
@@ -18,6 +18,10 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
18
18
|
@subject.stubs(:pid => 'test:1')
|
19
19
|
@subject.stubs(:new? => false)
|
20
20
|
end
|
21
|
+
|
22
|
+
it "should have a subject" do
|
23
|
+
@subject.rdf_subject.should == "info:fedora/test:1"
|
24
|
+
end
|
21
25
|
it "should have controlGroup" do
|
22
26
|
@subject.controlGroup.should == 'M'
|
23
27
|
end
|
@@ -55,6 +59,34 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
62
|
+
describe "an instance with a custom subject" do
|
63
|
+
before do
|
64
|
+
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
65
|
+
register_vocabularies RDF::DC, RDF::FOAF, RDF::RDFS
|
66
|
+
rdf_subject { |ds| "info:fedora/#{ds.pid}/content" }
|
67
|
+
map_predicates do |map|
|
68
|
+
map.created(:in => RDF::DC)
|
69
|
+
map.title(:in => RDF::DC)
|
70
|
+
map.publisher(:in => RDF::DC)
|
71
|
+
map.based_near(:in => RDF::FOAF)
|
72
|
+
map.related_url(:to => "seeAlso", :in => RDF::RDFS)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
@subject = MyDatastream.new(@inner_object, 'mixed_rdf')
|
76
|
+
@subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
|
77
|
+
@subject.stubs(:pid => 'test:1')
|
78
|
+
@subject.stubs(:new? => false)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have fields" do
|
82
|
+
@subject.title.should == ["Title of datastream"]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should have a custom subject" do
|
86
|
+
@subject.rdf_subject.should == 'info:fedora/test:1/content'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
58
90
|
describe "a new instance" do
|
59
91
|
before(:each) do
|
60
92
|
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::RdfxmlRDFDatastream do
|
4
|
+
describe "a new instance" do
|
5
|
+
before(:each) do
|
6
|
+
class MyRdfxmlDatastream < ActiveFedora::RdfxmlRDFDatastream
|
7
|
+
register_vocabularies RDF::DC
|
8
|
+
map_predicates do |map|
|
9
|
+
map.publisher(:in => RDF::DC)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
@subject = MyRdfxmlDatastream.new(@inner_object, 'mixed_rdf')
|
13
|
+
@subject.stubs(:pid => 'test:1')
|
14
|
+
end
|
15
|
+
after(:each) do
|
16
|
+
Object.send(:remove_const, :MyRdfxmlDatastream)
|
17
|
+
end
|
18
|
+
it "should save and reload" do
|
19
|
+
@subject.publisher = ["St. Martin's Press"]
|
20
|
+
@subject.serialize.should =~ /<rdf:RDF/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -236,7 +236,7 @@ describe ActiveFedora::Relationships do
|
|
236
236
|
local_node = SpecNode.new
|
237
237
|
local_node.expects(:ids_for_outbound).with(:is_member_of).returns(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
|
238
238
|
|
239
|
-
ActiveFedora::ContentModel.expects(:known_models_for).returns([SpecNode]).times(3)
|
239
|
+
#ActiveFedora::ContentModel.expects(:known_models_for).returns([SpecNode]).times(3)
|
240
240
|
ActiveFedora::SolrService.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns([{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
|
241
241
|
{"id"=> "my:_PID2_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
|
242
242
|
{"id"=> "my:_PID3_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]}])
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424181
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 4
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 4.0.0.
|
11
|
+
- 16
|
12
|
+
version: 4.0.0.rc16
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Matt Zumwalt
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2012-03-
|
22
|
+
date: 2012-03-26 00:00:00 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
prerelease: false
|
@@ -101,14 +101,16 @@ dependencies:
|
|
101
101
|
requirement: &id006 !ruby/object:Gem::Requirement
|
102
102
|
none: false
|
103
103
|
requirements:
|
104
|
-
- -
|
104
|
+
- - ~>
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
hash:
|
106
|
+
hash: 15424087
|
107
107
|
segments:
|
108
108
|
- 1
|
109
|
-
-
|
110
|
-
-
|
111
|
-
|
109
|
+
- 6
|
110
|
+
- 0
|
111
|
+
- rc
|
112
|
+
- 1
|
113
|
+
version: 1.6.0.rc1
|
112
114
|
version_requirements: *id006
|
113
115
|
name: om
|
114
116
|
type: :runtime
|
@@ -397,6 +399,7 @@ files:
|
|
397
399
|
- lib/active_fedora/qualified_dublin_core_datastream.rb
|
398
400
|
- lib/active_fedora/rdf_datastream.rb
|
399
401
|
- lib/active_fedora/rdf_xml_writer.rb
|
402
|
+
- lib/active_fedora/rdfxml_rdf_datastream.rb
|
400
403
|
- lib/active_fedora/reflection.rb
|
401
404
|
- lib/active_fedora/relationship_graph.rb
|
402
405
|
- lib/active_fedora/relationships.rb
|
@@ -533,6 +536,7 @@ files:
|
|
533
536
|
- spec/unit/property_spec.rb
|
534
537
|
- spec/unit/qualified_dublin_core_datastream_spec.rb
|
535
538
|
- spec/unit/rdf_xml_writer_spec.rb
|
539
|
+
- spec/unit/rdfxml_rdf_datastream_spec.rb
|
536
540
|
- spec/unit/relationship_graph_spec.rb
|
537
541
|
- spec/unit/relationships_spec.rb
|
538
542
|
- spec/unit/rels_ext_datastream_spec.rb
|
@@ -693,6 +697,7 @@ test_files:
|
|
693
697
|
- spec/unit/property_spec.rb
|
694
698
|
- spec/unit/qualified_dublin_core_datastream_spec.rb
|
695
699
|
- spec/unit/rdf_xml_writer_spec.rb
|
700
|
+
- spec/unit/rdfxml_rdf_datastream_spec.rb
|
696
701
|
- spec/unit/relationship_graph_spec.rb
|
697
702
|
- spec/unit/relationships_spec.rb
|
698
703
|
- spec/unit/rels_ext_datastream_spec.rb
|