active-fedora 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CONSOLE_GETTING_STARTED.textile +92 -59
 - data/Gemfile.lock +1 -2
 - data/README.textile +2 -2
 - data/config/fedora.yml +1 -1
 - data/config/predicate_mappings.yml +17 -20
 - data/lib/active_fedora.rb +2 -5
 - data/lib/active_fedora/samples/hydra-mods_article_datastream.rb +3 -3
 - data/lib/active_fedora/samples/sample_af_obj_relationship_query_param.rb +11 -0
 - data/lib/active_fedora/samples/special_thing.rb +4 -2
 - data/lib/active_fedora/semantic_node.rb +254 -15
 - data/lib/active_fedora/version.rb +1 -1
 - data/spec/fixtures/rails_root/config/fedora.yml +4 -4
 - data/spec/integration/nokogiri_datastream_spec.rb +2 -1
 - data/spec/integration/semantic_node_spec.rb +259 -2
 - data/spec/unit/active_fedora_spec.rb +2 -2
 - data/spec/unit/semantic_node_spec.rb +13 -6
 - metadata +8 -6
 
| 
         @@ -1,25 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The concepts covered in this tutorial can be applied in any application with the active-fedora gem installed. (Don't forget to "require 'active-fedora'").
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            h2. Dependencies
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
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.
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            h2. Get a Copy of the Code
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 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.
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            First, clone the git repository and cd into the root
         
     | 
| 
      
 11 
     | 
    
         
            +
            First, clone the git repository and cd into the root:
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
            <pre>
         
     | 
| 
       12 
14 
     | 
    
         
             
            git clone git@github.com:mediashelf/active_fedora.git
         
     | 
| 
       13 
15 
     | 
    
         
             
            cd active_fedora
         
     | 
| 
       14 
16 
     | 
    
         
             
            </pre>
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
            If you don't have bundler installed yet, install it
         
     | 
| 
      
 18 
     | 
    
         
            +
            If you don't have bundler installed yet, install it:
         
     | 
| 
       17 
19 
     | 
    
         | 
| 
       18 
20 
     | 
    
         
             
            <pre>
         
     | 
| 
       19 
21 
     | 
    
         
             
            gem install bundler
         
     | 
| 
       20 
22 
     | 
    
         
             
            </pre>
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            Now let bundler handle installing active-fedora's dependencies
         
     | 
| 
      
 24 
     | 
    
         
            +
            Now let bundler handle installing active-fedora's dependencies:
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
26 
     | 
    
         
             
            <pre>
         
     | 
| 
       25 
27 
     | 
    
         
             
            bundle install
         
     | 
| 
         @@ -39,9 +41,9 @@ java -jar start.jar 
     | 
|
| 
       39 
41 
     | 
    
         | 
| 
       40 
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.
         
     | 
| 
       41 
43 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
            You can also set up your own copies of Fedora and Solr to run against. 
     | 
| 
      
 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
         
     | 
| 
       43 
45 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
            h2. Open up the Console
         
     | 
| 
      
 46 
     | 
    
         
            +
            h2. Open up the (Rails) Console (or, use irb)
         
     | 
| 
       45 
47 
     | 
    
         | 
| 
       46 
48 
     | 
    
         
             
            <pre>
         
     | 
| 
       47 
49 
     | 
    
         
             
            script/console
         
     | 
| 
         @@ -55,7 +57,7 @@ require "active_fedora/samples" # these are the sample models and datastreams th 
     | 
|
| 
       55 
57 
     | 
    
         | 
| 
       56 
58 
     | 
    
         
             
            h2. Initialize ActiveFedora
         
     | 
| 
       57 
59 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
            In order to function, ActiveFedora needs to know where Fedora and Solr are running.  It gets this information from a YAML file.  
         
     | 
| 
      
 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
         
     | 
| 
       59 
61 
     | 
    
         | 
| 
       60 
62 
     | 
    
         
             
            <pre>
         
     | 
| 
       61 
63 
     | 
    
         
             
            ActiveFedora.init
         
     | 
| 
         @@ -71,19 +73,19 @@ I, [...]  INFO -- : FEDORA: initialized Fedora as: #<Fedora::Repository:0x102123 
     | 
|
| 
       71 
73 
     | 
    
         | 
| 
       72 
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.
         
     | 
| 
       73 
75 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
            If you want to use a different  
     | 
| 
      
 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:
         
     | 
| 
       75 
77 
     | 
    
         | 
| 
       76 
78 
     | 
    
         
             
            <pre>ActiveFedora.init("path/to/fedora.yml")</pre>
         
     | 
| 
       77 
79 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
            h4. ActiveFedora within Rails
         
     | 
| 
       79 
81 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
            If you are running a rails app, ActiveFedora.init will automatically look for  
     | 
| 
      
 82 
     | 
    
         
            +
            If you are running a rails app, ActiveFedora.init will automatically look for config/fedora.yml
         
     | 
| 
       81 
83 
     | 
    
         | 
| 
       82 
84 
     | 
    
         
             
            Also, within a rails app, you should create a file in config/initializers (ie. fedora_config.rb) that calls ActiveFedora.init
         
     | 
| 
       83 
85 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
            h2. Load a  
     | 
| 
      
 86 
     | 
    
         
            +
            h2. Load a Fixture Object To Play With
         
     | 
| 
       85 
87 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
            The ActiveFedora code includes  
     | 
| 
      
 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:
         
     | 
| 
       87 
89 
     | 
    
         | 
| 
       88 
90 
     | 
    
         
             
            <pre>
         
     | 
| 
       89 
91 
     | 
    
         
             
            filename = File.join(File.dirname(__FILE__),"spec","fixtures", "hydrangea_fixture_mods_article1.foxml.xml")
         
     | 
| 
         @@ -104,83 +106,106 @@ The easiest way to delete an object from Fedora is to use the following line.  N 
     | 
|
| 
       104 
106 
     | 
    
         
             
            </pre>
         
     | 
| 
       105 
107 
     | 
    
         | 
| 
       106 
108 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
            To see a more complete implementation of importing and deleting Fedora objects, see the code in  
     | 
| 
      
 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
         
     | 
| 
       108 
110 
     | 
    
         | 
| 
       109 
111 
     | 
    
         | 
| 
       110 
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.*
         
     | 
| 
       111 
113 
     | 
    
         | 
| 
       112 
114 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
            Look at the SpecialThing model defined in lib/active_fedora/samples/special_thing.rb to see how you declare an ActiveFedora model
         
     | 
| 
      
 115 
     | 
    
         
            +
            h3. Define a Model for Your (Active)Fedora Objects
         
     | 
| 
       116 
116 
     | 
    
         | 
| 
      
 117 
     | 
    
         
            +
            Look at the SpecialThing model defined in lib/active_fedora/samples/special_thing.rb to see how you declare an ActiveFedora model.
         
     | 
| 
       117 
118 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
            Create an instance of the SpecialThing class
         
     | 
| 
      
 119 
     | 
    
         
            +
            Create an instance of the SpecialThing class:
         
     | 
| 
       119 
120 
     | 
    
         | 
| 
       120 
121 
     | 
    
         
             
            <pre>
         
     | 
| 
       121 
122 
     | 
    
         
             
            newthing = SpecialThing.new
         
     | 
| 
       122 
123 
     | 
    
         
             
            </pre>
         
     | 
| 
       123 
124 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
            Get the pid of your new object
         
     | 
| 
      
 125 
     | 
    
         
            +
            Get the pid of your new object:
         
     | 
| 
       125 
126 
     | 
    
         | 
| 
       126 
127 
     | 
    
         
             
            <pre>
         
     | 
| 
       127 
128 
     | 
    
         
             
            newthing.pid
         
     | 
| 
       128 
129 
     | 
    
         
             
            => "changeme:30"
         
     | 
| 
       129 
130 
     | 
    
         
             
            </pre>
         
     | 
| 
       130 
131 
     | 
    
         | 
| 
       131 
     | 
    
         
            -
            This pid was retrieved from Fedora's getNextPid method.   
     | 
| 
      
 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.
         
     | 
| 
       132 
135 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
            h3. RELATIONSHIPS
         
     | 
| 
      
 136 
     | 
    
         
            +
            h3. Fedora RELATIONSHIPS in ActiveFedora
         
     | 
| 
       134 
137 
     | 
    
         | 
| 
       135 
     | 
    
         
            -
            ActiveFedora provides convenience methods for creating and editing RELS-EXT relationships.  It also auto-generates methods for  
     | 
| 
      
 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)
         
     | 
| 
       136 
139 
     | 
    
         | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
      
 140 
     | 
    
         
            +
            Use the relationships method to list the object's relationships:
         
     | 
| 
       138 
141 
     | 
    
         | 
| 
       139 
142 
     | 
    
         
             
            <pre>
         
     | 
| 
       140 
143 
     | 
    
         
             
            newthing.relationships
         
     | 
| 
       141 
144 
     | 
    
         
             
            => {:self=>{}}
         
     | 
| 
       142 
145 
     | 
    
         
             
            </pre>
         
     | 
| 
       143 
146 
     | 
    
         | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
      
 147 
     | 
    
         
            +
            The SpecialThing class definition contains these lines:
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
            <pre>
         
     | 
| 
      
 150 
     | 
    
         
            +
              #
         
     | 
| 
      
 151 
     | 
    
         
            +
              # RELATIONSHIPS
         
     | 
| 
      
 152 
     | 
    
         
            +
              #
         
     | 
| 
      
 153 
     | 
    
         
            +
              
         
     | 
| 
      
 154 
     | 
    
         
            +
              # This is an example of how you can add a custom relationship to a model
         
     | 
| 
      
 155 
     | 
    
         
            +
              # 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
         
     | 
| 
      
 156 
     | 
    
         
            +
              has_relationship "derivations", :has_derivation
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
              # 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
         
     | 
| 
      
 159 
     | 
    
         
            +
              has_relationship "inspirations", :has_derivation, :inbound => true  
         
     | 
| 
      
 160 
     | 
    
         
            +
            </pre>
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
            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:
         
     | 
| 
       145 
163 
     | 
    
         | 
| 
       146 
164 
     | 
    
         
             
            <pre>
         
     | 
| 
       147 
165 
     | 
    
         
             
            newthing.inspirations
         
     | 
| 
       148 
166 
     | 
    
         
             
            => []
         
     | 
| 
       149 
167 
     | 
    
         
             
            </pre>
         
     | 
| 
       150 
168 
     | 
    
         | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
      
 169 
     | 
    
         
            +
            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.
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
            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 objectl  We'll also save our new object in our Fedora repository.
         
     | 
| 
       152 
172 
     | 
    
         | 
| 
       153 
173 
     | 
    
         
             
            <pre>
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
      
 174 
     | 
    
         
            +
            newobj = ActiveFedora::Base.new
         
     | 
| 
      
 175 
     | 
    
         
            +
            newobj.add_relationship(:has_derivation, newthing)
         
     | 
| 
       156 
176 
     | 
    
         
             
            => true
         
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
      
 177 
     | 
    
         
            +
            newobj.relationships
         
     | 
| 
       158 
178 
     | 
    
         
             
            => {:self=>{:has_derivation=>["info:fedora/changeme:30"]}}
         
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
      
 179 
     | 
    
         
            +
            newobj.save
         
     | 
| 
       160 
180 
     | 
    
         
             
            => ...
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
      
 181 
     | 
    
         
            +
            newobj.pid
         
     | 
| 
       162 
182 
     | 
    
         
             
            => "changeme:164" # this is the pid you want to put in the following URLs as a replacement for {PID}
         
     | 
| 
       163 
183 
     | 
    
         
             
            </pre>
         
     | 
| 
       164 
184 
     | 
    
         | 
| 
       165 
     | 
    
         
            -
            You can  
     | 
| 
      
 185 
     | 
    
         
            +
            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
         
     | 
| 
       166 
186 
     | 
    
         | 
| 
       167 
     | 
    
         
            -
            Now  
     | 
| 
      
 187 
     | 
    
         
            +
            Now let's see if the "newthing" object has an "inspiration" relationship with our "newobj"
         
     | 
| 
       168 
188 
     | 
    
         | 
| 
       169 
189 
     | 
    
         
             
            <pre>
         
     | 
| 
       170 
190 
     | 
    
         
             
            newthing.inspirations
         
     | 
| 
       171 
     | 
    
         
            -
            => ...
         
     | 
| 
      
 191 
     | 
    
         
            +
            => ... (FIXME: put expected output here)
         
     | 
| 
       172 
192 
     | 
    
         
             
            newthing.inspirations.each {|pt| puts pt.pid }
         
     | 
| 
       173 
     | 
    
         
            -
            => ...
         
     | 
| 
      
 193 
     | 
    
         
            +
            => ... (FIXME: put expected output here)
         
     | 
| 
       174 
194 
     | 
    
         
             
            newthing.inspirations(:response_format=>:id_array)
         
     | 
| 
       175 
     | 
    
         
            -
            => ...
         
     | 
| 
      
 195 
     | 
    
         
            +
            => ... (FIXME: put expected output here)
         
     | 
| 
       176 
196 
     | 
    
         
             
            </pre>
         
     | 
| 
       177 
197 
     | 
    
         | 
| 
       178 
     | 
    
         
            -
            Note that you didn't have to save newthing in order for this relationship to show up in  
     | 
| 
      
 198 
     | 
    
         
            +
            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. 
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
            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. 
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
       179 
202 
     | 
    
         | 
| 
       180 
     | 
    
         
            -
            h3. DATASTREAMS & METADATA
         
     | 
| 
      
 203 
     | 
    
         
            +
            h3. Fedora DATASTREAMS & METADATA in ActiveFedora
         
     | 
| 
       181 
204 
     | 
    
         | 
| 
       182 
205 
     | 
    
         
             
            h4. Blobs (a.k.a. File Datastreams, a.k.a Managed Content Datastreams)
         
     | 
| 
       183 
206 
     | 
    
         | 
| 
      
 207 
     | 
    
         
            +
            Here we create a simple Datastream (using the default Datastream model). 
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
       184 
209 
     | 
    
         
             
            <pre>
         
     | 
| 
       185 
210 
     | 
    
         
             
            file = File.new('spec/fixtures/minivan.jpg')
         
     | 
| 
       186 
211 
     | 
    
         
             
            => #<File:spec/fixtures/minivan.jpg>
         
     | 
| 
         @@ -192,12 +217,12 @@ newthing.save 
     | 
|
| 
       192 
217 
     | 
    
         
             
            => true
         
     | 
| 
       193 
218 
     | 
    
         
             
            </pre>
         
     | 
| 
       194 
219 
     | 
    
         | 
| 
       195 
     | 
    
         
            -
            Now  
     | 
| 
      
 220 
     | 
    
         
            +
            Now use your browser to find the file datastreams in Fedora ...
         
     | 
| 
       196 
221 
     | 
    
         | 
| 
       197 
222 
     | 
    
         | 
| 
       198 
     | 
    
         
            -
            h4. On auto-generating  
     | 
| 
      
 223 
     | 
    
         
            +
            h4. On auto-generating datastream ids
         
     | 
| 
       199 
224 
     | 
    
         | 
| 
       200 
     | 
    
         
            -
            If you don't specify a dsid, ActiveFedora will generate one for you.
         
     | 
| 
      
 225 
     | 
    
         
            +
            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
         
     | 
| 
       201 
226 
     | 
    
         | 
| 
       202 
227 
     | 
    
         
             
            <pre>
         
     | 
| 
       203 
228 
     | 
    
         
             
            file_ds2 = ActiveFedora::Datastream.new(:dsLabel => 'Minivan Plays', :altIDs => 'default', :controlGroup => 'M', :blob => file)
         
     | 
| 
         @@ -219,9 +244,11 @@ newthing.datastreams.keys 
     | 
|
| 
       219 
244 
     | 
    
         
             
            newthing.save
         
     | 
| 
       220 
245 
     | 
    
         
             
            </pre>
         
     | 
| 
       221 
246 
     | 
    
         | 
| 
       222 
     | 
    
         
            -
            h2.  
     | 
| 
      
 247 
     | 
    
         
            +
            h2. Getting Existing Fedora Repository Objects 
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
            When you want your code to interact with existing digital objects in a Fedora repository, use the ActiveFedora load_instance method.
         
     | 
| 
       223 
250 
     | 
    
         | 
| 
       224 
     | 
    
         
            -
            You can use the load_instance class method on any kind of ActiveFedora::Base class to load objects from Fedora.
         
     | 
| 
      
 251 
     | 
    
         
            +
            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.
         
     | 
| 
       225 
252 
     | 
    
         | 
| 
       226 
253 
     | 
    
         
             
            <pre>
         
     | 
| 
       227 
254 
     | 
    
         
             
            newthing.pid
         
     | 
| 
         @@ -229,20 +256,24 @@ newthing.pid 
     | 
|
| 
       229 
256 
     | 
    
         
             
            copy_as_base = ActiveFedora::Base.load_instance("changeme:30")
         
     | 
| 
       230 
257 
     | 
    
         
             
            copy_as_base.pid
         
     | 
| 
       231 
258 
     | 
    
         
             
            => "changeme:30"
         
     | 
| 
      
 259 
     | 
    
         
            +
            newthing.relationships
         
     | 
| 
      
 260 
     | 
    
         
            +
            => {:self=>{:has_model=>["info:fedora/afmodel:SpecialThing"]}} 
         
     | 
| 
       232 
261 
     | 
    
         
             
            copy_as_base.relationships
         
     | 
| 
       233 
262 
     | 
    
         
             
            => {:self=>{:has_model=>["info:fedora/afmodel:SpecialThing"]}} 
         
     | 
| 
      
 263 
     | 
    
         
            +
            newthing.datastreams.keys
         
     | 
| 
      
 264 
     | 
    
         
            +
            => ["DS1", "descMetadata", "Foo1", "minivan", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun"] 
         
     | 
| 
       234 
265 
     | 
    
         
             
            copy_as_base.datastreams.keys
         
     | 
| 
       235 
266 
     | 
    
         
             
            => ["DS1", "descMetadata", "Foo1", "minivan", "RELS-EXT", "rightsMetadata", "DC", "extraMetadataForFun"] 
         
     | 
| 
       236 
267 
     | 
    
         
             
            </pre>
         
     | 
| 
       237 
268 
     | 
    
         | 
| 
       238 
     | 
    
         
            -
            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 
     | 
| 
      
 269 
     | 
    
         
            +
            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*.
         
     | 
| 
       239 
270 
     | 
    
         | 
| 
       240 
271 
     | 
    
         
             
            <pre>
         
     | 
| 
       241 
272 
     | 
    
         
             
            copy_as_base.datastreams["extraMetadataForFun"].class
         
     | 
| 
       242 
273 
     | 
    
         
             
            => ActiveFedora::Datastream
         
     | 
| 
       243 
274 
     | 
    
         
             
            </pre>
         
     | 
| 
       244 
275 
     | 
    
         | 
| 
       245 
     | 
    
         
            -
            If you want the model-specific metadata to be deserialized, you must call load_instance on the appropriate 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.
         
     | 
| 
      
 276 
     | 
    
         
            +
            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.
         
     | 
| 
       246 
277 
     | 
    
         | 
| 
       247 
278 
     | 
    
         
             
            <pre>
         
     | 
| 
       248 
279 
     | 
    
         
             
            copy_as_specialthing = SpecialThing.load_instance(newthing.pid)
         
     | 
| 
         @@ -252,13 +283,22 @@ copy_as_specialthing.datastreams["extraMetadataForFun"].class 
     | 
|
| 
       252 
283 
     | 
    
         
             
            => ActiveFedora::Marpa::DcDatastream
         
     | 
| 
       253 
284 
     | 
    
         
             
            </pre>
         
     | 
| 
       254 
285 
     | 
    
         | 
| 
       255 
     | 
    
         
            -
            h2. Finding Objects
         
     | 
| 
       256 
286 
     | 
    
         | 
| 
       257 
     | 
    
         
            -
             
     | 
| 
      
 287 
     | 
    
         
            +
            You can use "find" instead of "load_instance".  In practice, we tend to use load_instance though -- it's more direct.
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
            <pre>
         
     | 
| 
      
 290 
     | 
    
         
            +
            Base.find("changeme:30")
         
     | 
| 
      
 291 
     | 
    
         
            +
            SpecialThing.find("changeme:30")
         
     | 
| 
      
 292 
     | 
    
         
            +
            </pre>
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
             
     | 
| 
      
 295 
     | 
    
         
            +
            h3. Finding Fedora Repository Objects of the Same Class
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
      
 297 
     | 
    
         
            +
            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.
         
     | 
| 
       258 
298 
     | 
    
         | 
| 
       259 
299 
     | 
    
         
             
            h3. Finding Instances of the Class
         
     | 
| 
       260 
300 
     | 
    
         | 
| 
       261 
     | 
    
         
            -
            Imitating ActiveRecord,  
     | 
| 
      
 301 
     | 
    
         
            +
            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.
         
     | 
| 
       262 
302 
     | 
    
         | 
| 
       263 
303 
     | 
    
         
             
            <pre>
         
     | 
| 
       264 
304 
     | 
    
         
             
            ActiveFedora::Base.find(:all)
         
     | 
| 
         @@ -273,21 +313,12 @@ solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_s:info\:f 
     | 
|
| 
       273 
313 
     | 
    
         | 
| 
       274 
314 
     | 
    
         
             
            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.
         
     | 
| 
       275 
315 
     | 
    
         | 
| 
       276 
     | 
    
         
            -
            h3. Finding (Loading) a specific Object
         
     | 
| 
       277 
316 
     | 
    
         | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
            <pre>
         
     | 
| 
       281 
     | 
    
         
            -
            Base.find("changeme:30")
         
     | 
| 
       282 
     | 
    
         
            -
            SpecialThing.find("changeme:30")
         
     | 
| 
       283 
     | 
    
         
            -
            </pre>
         
     | 
| 
       284 
     | 
    
         
            -
             
     | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
            h3. Looking a bit deeper at what Models do
         
     | 
| 
      
 317 
     | 
    
         
            +
            h2. More About ActiveFedora Models
         
     | 
| 
       287 
318 
     | 
    
         | 
| 
       288 
319 
     | 
    
         
             
            ActiveFedora Models 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.
         
     | 
| 
       289 
320 
     | 
    
         | 
| 
       290 
     | 
    
         
            -
            When you're ready to learn more about how to define ActiveFedora models and OM-based datastreams,  
     | 
| 
      
 321 
     | 
    
         
            +
            When you're ready to learn more about how to define ActiveFedora models and OM-based datastreams, examine the files in lib/active_fedora/samples.  Those will give you more background.  Here, we're seeing what happens when you use those Models and datastreams.
         
     | 
| 
       291 
322 
     | 
    
         | 
| 
       292 
323 
     | 
    
         
             
            For now, load an instance of the SpecialThing model and take a look at its datastreams.
         
     | 
| 
       293 
324 
     | 
    
         | 
| 
         @@ -301,10 +332,12 @@ st.datastreams.keys 
     | 
|
| 
       301 
332 
     | 
    
         | 
| 
       302 
333 
     | 
    
         
             
            We see the three datastreams that are declared by the SpecialThing Model, but where did the other datastreams come from?
         
     | 
| 
       303 
334 
     | 
    
         | 
| 
      
 335 
     | 
    
         
            +
            h3. Default Fedora Datastreams
         
     | 
| 
      
 336 
     | 
    
         
            +
             
     | 
| 
       304 
337 
     | 
    
         
             
            The RELS-EXT is where Fedora objects store their relationships, so SpecialThing uses that datastream when it uses the methods created by has_relationship.
         
     | 
| 
       305 
338 
     | 
    
         | 
| 
       306 
     | 
    
         
            -
            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. 
     | 
| 
       307 
     | 
    
         
            -
             
     | 
| 
      
 339 
     | 
    
         
            +
            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.
         
     | 
| 
      
 340 
     | 
    
         
            +
             
     | 
| 
       308 
341 
     | 
    
         
             
            Let's see what classes the datastreams have been bound to
         
     | 
| 
       309 
342 
     | 
    
         | 
| 
       310 
343 
     | 
    
         
             
            <pre>
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.textile
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            h2. Description
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            RubyFedora and ActiveFedora provide a set of Ruby gems for creating and managing objects in the Fedora Repository Architecture ("http://fedora-commons.org":http://fedora-commons.org).
         
     | 
| 
      
 3 
     | 
    
         
            +
            RubyFedora and ActiveFedora provide a set of Ruby gems for creating and managing objects in the Fedora Repository Architecture ("http://fedora-commons.org":http://fedora-commons.org).  ActiveFedora is loosely based on "ActiveRecord" in Rails.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            h2. Getting Help
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -18,7 +18,7 @@ h2. Getting Started 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
            The "ActiveFedora Console Tour":https://github.com/mediashelf/active_fedora/blob/master/CONSOLE_GETTING_STARTED.textile  gives you a brief tour through ActiveFedora's features on the command line.
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
            h2. Testing
         
     | 
| 
      
 21 
     | 
    
         
            +
            h2. Testing (this Gem)
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            In order to run the RSpec tests, you need to have a copy of the ActiveFedora source code, and then run bundle install in the source directory.
         
     | 
| 
       24 
24 
     | 
    
         | 
    
        data/config/fedora.yml
    CHANGED
    
    
| 
         @@ -13,34 +13,31 @@ 
     | 
|
| 
       13 
13 
     | 
    
         
             
            # With the last two lines of this file uncommented, the relationships hash of your object will include:
         
     | 
| 
       14 
14 
     | 
    
         
             
            #   :oai_item_id => ["info:fedora/oai:example.edu:changeme:500"]
         
     | 
| 
       15 
15 
     | 
    
         
             
            #
         
     | 
| 
       16 
     | 
    
         
            -
            # With the last two lines of this file commented out, the relationships hash of your object will include:
         
     | 
| 
       17 
     | 
    
         
            -
            #   "oai_itemID" => ["info:fedora/oai:example.edu:changeme:500"]
         
     | 
| 
       18 
     | 
    
         
            -
            #   
         
     | 
| 
       19 
16 
     | 
    
         
             
            :predicate_mapping:
         
     | 
| 
       20 
17 
     | 
    
         
             
              info:fedora/fedora-system:def/relations-external#: 
         
     | 
| 
       21 
     | 
    
         
            -
                : 
     | 
| 
       22 
     | 
    
         
            -
                :is_metadata_for: isMetadataFor
         
     | 
| 
       23 
     | 
    
         
            -
                :is_member_of_collection: isMemberOfCollection
         
     | 
| 
       24 
     | 
    
         
            -
                :has_derivation: hasDerivation
         
     | 
| 
       25 
     | 
    
         
            -
                :is_annotation_of: isAnnotationOf
         
     | 
| 
       26 
     | 
    
         
            -
                :is_constituent_of: isConstituentOf
         
     | 
| 
       27 
     | 
    
         
            -
                :is_dependent_of: isDependentOf
         
     | 
| 
       28 
     | 
    
         
            -
                :has_collection_member: hasCollectionMember
         
     | 
| 
      
 18 
     | 
    
         
            +
                :conforms_to: conformsTo
         
     | 
| 
       29 
19 
     | 
    
         
             
                :has_annotation: hasAnnotation
         
     | 
| 
      
 20 
     | 
    
         
            +
                :has_collection_member: hasCollectionMember
         
     | 
| 
       30 
21 
     | 
    
         
             
                :has_constituent: hasConstituent
         
     | 
| 
       31 
22 
     | 
    
         
             
                :has_dependent: hasDependent
         
     | 
| 
       32 
     | 
    
         
            -
                : 
     | 
| 
      
 23 
     | 
    
         
            +
                :has_derivation: hasDerivation
         
     | 
| 
      
 24 
     | 
    
         
            +
                :has_description: hasDescription
         
     | 
| 
       33 
25 
     | 
    
         
             
                :has_equivalent: hasEquivalent
         
     | 
| 
       34 
     | 
    
         
            -
                :is_subset_of: isSubsetOf
         
     | 
| 
       35 
     | 
    
         
            -
                :is_description_of: isDescriptionOf
         
     | 
| 
       36 
     | 
    
         
            -
                :is_member_of: isMemberOf
         
     | 
| 
       37 
     | 
    
         
            -
                :has_model: hasModel
         
     | 
| 
       38 
     | 
    
         
            -
                :conforms_to: conformsTo
         
     | 
| 
       39 
26 
     | 
    
         
             
                :has_metadata: hasMetadata
         
     | 
| 
       40 
     | 
    
         
            -
                :has_subset: hasSubset
         
     | 
| 
       41 
     | 
    
         
            -
                :has_description: hasDescription
         
     | 
| 
       42 
     | 
    
         
            -
                :has_part: hasPart
         
     | 
| 
       43 
27 
     | 
    
         
             
                :has_member: hasMember
         
     | 
| 
      
 28 
     | 
    
         
            +
                :has_model: hasModel
         
     | 
| 
      
 29 
     | 
    
         
            +
                :has_part: hasPart
         
     | 
| 
      
 30 
     | 
    
         
            +
                :has_subset: hasSubset
         
     | 
| 
      
 31 
     | 
    
         
            +
                :is_annotation_of: isAnnotationOf
         
     | 
| 
      
 32 
     | 
    
         
            +
                :is_constituent_of: isConstituentOf
         
     | 
| 
      
 33 
     | 
    
         
            +
                :is_dependent_of: isDependentOf
         
     | 
| 
      
 34 
     | 
    
         
            +
                :is_derivation_of: isDerivationOf
         
     | 
| 
      
 35 
     | 
    
         
            +
                :is_description_of: isDescriptionOf
         
     | 
| 
      
 36 
     | 
    
         
            +
                :is_member_of: isMemberOf
         
     | 
| 
      
 37 
     | 
    
         
            +
                :is_member_of_collection: isMemberOfCollection
         
     | 
| 
      
 38 
     | 
    
         
            +
                :is_metadata_for: isMetadataFor
         
     | 
| 
      
 39 
     | 
    
         
            +
                :is_part_of: isPartOf
         
     | 
| 
      
 40 
     | 
    
         
            +
                :is_subset_of: isSubsetOf
         
     | 
| 
       44 
41 
     | 
    
         
             
              info:fedora/fedora-system:def/model#:
         
     | 
| 
       45 
42 
     | 
    
         
             
                :has_model: hasModel
         
     | 
| 
       46 
43 
     | 
    
         
             
            #  http://www.openarchives.org/OAI/2.0/: 
         
     | 
    
        data/lib/active_fedora.rb
    CHANGED
    
    | 
         @@ -3,7 +3,6 @@ gem 'solr-ruby' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require "loggable"
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            $: << 'lib'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'logger'
         
     | 
| 
       7 
6 
     | 
    
         
             
            require 'active_fedora/solr_service.rb'
         
     | 
| 
       8 
7 
     | 
    
         
             
            require "solrizer"
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
         @@ -30,6 +29,8 @@ ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES) 
     | 
|
| 
       30 
29 
     | 
    
         | 
| 
       31 
30 
     | 
    
         
             
            module ActiveFedora #:nodoc:
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
              include Loggable
         
     | 
| 
      
 33 
     | 
    
         
            +
              
         
     | 
| 
       33 
34 
     | 
    
         
             
              class << self
         
     | 
| 
       34 
35 
     | 
    
         
             
                attr_accessor :solr_config, :fedora_config
         
     | 
| 
       35 
36 
     | 
    
         
             
              end
         
     | 
| 
         @@ -90,10 +91,6 @@ module ActiveFedora #:nodoc: 
     | 
|
| 
       90 
91 
     | 
    
         
             
                Fedora::Repository.instance
         
     | 
| 
       91 
92 
     | 
    
         
             
              end
         
     | 
| 
       92 
93 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
              def self.logger      
         
     | 
| 
       94 
     | 
    
         
            -
                @logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT)
         
     | 
| 
       95 
     | 
    
         
            -
              end
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
94 
     | 
    
         
             
              def self.predicate_config
         
     | 
| 
       98 
95 
     | 
    
         
             
                @predicate_config_path ||= build_predicate_config_path
         
     | 
| 
       99 
96 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "active-fedora"
         
     | 
| 
       2 
2 
     | 
    
         
             
            module Hydra
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
              # This is an example of a NokogiriDatastream that defines  
     | 
| 
      
 4 
     | 
    
         
            +
              # This is an example of a NokogiriDatastream that defines an OM terminology for MODS xml
         
     | 
| 
       5 
5 
     | 
    
         
             
              # It focuses on the aspects of MODS that deal with descriptive metadata for published articles
         
     | 
| 
       6 
     | 
    
         
            -
              #  
     | 
| 
      
 6 
     | 
    
         
            +
              # This is not the hydra-head plugin version of this OM Terminology; See https://github.com/projecthydra/hydra-head/blob/master/lib/hydra/mods_article.rb
         
     | 
| 
       7 
7 
     | 
    
         
             
              #
         
     | 
| 
       8 
     | 
    
         
            -
              # Things to note about the Terminology  
     | 
| 
      
 8 
     | 
    
         
            +
              # Things to note about the OM Terminology defined here:
         
     | 
| 
       9 
9 
     | 
    
         
             
              #
         
     | 
| 
       10 
10 
     | 
    
         
             
              # * Uses :ref terms to repeat the structures of a mods:name with a different @type on the mods:name element
         
     | 
| 
       11 
11 
     | 
    
         
             
              # * Defines a term lang_code that maps to "languageTerm[@type=code]"
         
     |