hydra 6.2.0.rc1 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/CONTRIBUTING.md +3 -0
  4. data/RELEASE-POLICY.md +40 -0
  5. data/doc/Configuring-solr-and-fedora.md +16 -0
  6. data/doc/Content-Type-Example:-Journal-Article.textile +735 -0
  7. data/doc/Dive-into-Hydra.md +62 -0
  8. data/doc/Filtering-search-results-with-hydra-access-controls.md +16 -0
  9. data/doc/For-Developers.md +47 -0
  10. data/doc/Home.md +33 -0
  11. data/doc/Lesson:-Define-Relationships-Between-Objects.md +127 -0
  12. data/doc/Lesson:-Generate-Rails-Scaffolding-for-Creating-and-Editing-Books.md +167 -0
  13. data/doc/Lesson:-Reading-Hydra-rightsMetadata-XML.md +87 -0
  14. data/doc/Lesson:-Use-Hydra-Access-Controls-to-Control-Access-to-Blacklight-show-Pages.md +37 -0
  15. data/doc/Lesson:-Using-Hydra-Access-Controls-and-CanCan-to-conditionally-render-part-of-a-page.md +29 -0
  16. data/doc/Lesson:-add-the-Hydra-dependencies.md +28 -0
  17. data/doc/Lesson:-adding-content-datastreams.md +60 -0
  18. data/doc/Lesson:-build-a-book-model.md +262 -0
  19. data/doc/Lesson:-create-a-git-repository.md +35 -0
  20. data/doc/Lesson:-generate-a-rails-application.md +53 -0
  21. data/doc/Lesson:-install-hydra-jetty.md +57 -0
  22. data/doc/Lesson:-make-blacklight-return-search-results.md +47 -0
  23. data/doc/Lesson:-run-the-Hydra-generator.md +39 -0
  24. data/doc/Lesson:-set-up-your-Rails-Application-to-use-rspec.md +41 -0
  25. data/doc/Lesson:-start-jetty.md +85 -0
  26. data/doc/Lesson:-start-the-application-&-search-for-results.md +43 -0
  27. data/doc/Lesson:-turn-off-access-controls.md +37 -0
  28. data/doc/Migrating-to-Hydra-6.2.md +12 -0
  29. data/doc/Migration-Notes.md +2 -0
  30. data/doc/Models---Defining-a-Custom-Hydra-Model.textile +198 -0
  31. data/doc/Rake-Tasks-in-Hydra-Head.textile +40 -0
  32. data/doc/Reference.textile +19 -0
  33. data/doc/Solr-Schema.rdoc +44 -0
  34. data/doc/Tools-for-Developing-and-Testing-your-Application.textile +69 -0
  35. data/doc/YOUR-Hydra-Application---Initial-Modifications.textile +357 -0
  36. data/lib/hydra/version.rb +1 -1
  37. metadata +35 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f0fcaaabe73a7f2626f1cb5be5f6d28705a72c5
4
- data.tar.gz: 728c7ef646a4e1cdcb346c1339c6d812b28ccee2
3
+ metadata.gz: dca5799096f3b249d3855d97f983d82d3682f000
4
+ data.tar.gz: e0679fded2bc13b82b274bc955ec42c6529f95c6
5
5
  SHA512:
6
- metadata.gz: 4b1ab43c089521e0798d93693060ff8104f2d2c1863cb4e378c2978146a95b799f6e53c7ce8af0567af8a2ecf5ca88e3ac361c9c045b18b17826a4b33333f32a
7
- data.tar.gz: 02404e6f4d9cf0f2bb96b32429a7c420e4560613a34503d48e9cac769f5fa5f80352de64328e80faf3faccdbb39a79750f4034e14c96da16cc6042ba0ffee621
6
+ metadata.gz: 99e85a8b24e88e1e5d4c5862d09bdea440e642d333b55178919591fb019ea050032a93b5a201f801db386064fef28c0ee04998fd15e6e221d3b277a14c183135
7
+ data.tar.gz: a2355c729901bd625b5f477d9fc61ddd19e1fa7464d908ddc7b6b37dbe9bc3bc60b4d5acd5285438f1069553f64b5436ae5cdae815b2f5c1e6735ecb2005b5c8
data/.gitignore CHANGED
@@ -7,7 +7,6 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
- doc/
11
10
  lib/bundler/man
12
11
  pkg
13
12
  rdoc
@@ -105,6 +105,9 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
105
105
  * If you are uncertain, bring other contributors into the conversation by creating a comment that includes their @username.
106
106
  * If you like the pull request, but want others to chime in, create a +1 comment and tag a user.
107
107
 
108
+ ## New Developers
109
+ A great way to get new developers involved and to learn the process is to have them go through the Hierarchy of Promises and create a pull request to improve it.
110
+
108
111
  # Additional Resources
109
112
 
110
113
  * [General GitHub documentation](http://help.github.com/)
@@ -22,3 +22,43 @@ deprecations when the Hydra gem is updated.
22
22
 
23
23
  The `./script/query-for-deprecation.rb` is a tool to help report what methods
24
24
  have had a change in deprecation status.
25
+
26
+ ## Documentation for releases
27
+
28
+ Our primary location for documentation is the Github wiki associated with this
29
+ project. All pages from the Github wiki should be copied to `doc/` as part of
30
+ a release.
31
+
32
+ **Steps:**
33
+
34
+ 1. Get the latest version of the wiki. Note that Github wikis are git
35
+ repositories, so you can treat them like any other.
36
+
37
+ ```
38
+ # if you haven't yet done so, clone the wiki repo...
39
+ git clone git@github.com:projecthydra/hydra.wiki.git path/to/hydra.wiki
40
+
41
+ # or, if you have already cloned, then get the latest changes...
42
+ cd path/to/hydra.wiki
43
+ git pull
44
+ ```
45
+
46
+ 1. Copy the wiki pages to `docs/` directory of `hydra` project.
47
+
48
+ ```
49
+ cp -a path/to/hydra.wiki/* path/to/hydra/docs/
50
+ ```
51
+
52
+ 1. Commit the changes.
53
+
54
+ ```
55
+ cd path/to/hydra
56
+ git add docs/.
57
+ git commit -m "Updates the wiki docs"
58
+ ```
59
+
60
+ This commit should then be included as part of the pull request for the new
61
+ release. See ["Making Changes"](/CONTRIBUTING.md#making-changes) and
62
+ ["Submitting Changes"](/CONTRIBUTING.md#submitting-changes) on the preferred
63
+ way to submit pull requests.
64
+ properly.
@@ -0,0 +1,16 @@
1
+ When you run the hydra generator (e.g. rails generatate hydra:head) the following files will be generated into your project:
2
+ ```
3
+ create fedora_conf
4
+ create fedora_conf/conf/development/fedora.fcfg
5
+ create fedora_conf/conf/test/fedora.fcfg
6
+ create solr_conf
7
+ create solr_conf/conf/schema.xml
8
+ create solr_conf/conf/solrconfig.xml
9
+ create solr_conf/solr.xml
10
+ ```
11
+
12
+ These files are configuration for the 4.0 version of solr and the 3.6.1 version of fedora. You should check these into your SCM. If you need to change the configuration you should edit them in this directory and then copy them into your solr/fedora deployment. If you are using hydra-jetty you can just call `rake jetty:config` to copy them into place.
13
+
14
+ If you need a configuration suitable for a 3.6.0 version of solr, try these:
15
+ * [[https://github.com/projecthydra/hydra-head/blob/4.1.x/solr_conf/conf/schema.xml]]
16
+ * [[https://github.com/projecthydra/hydra-head/blob/4.1.x/solr_conf/conf/solrconfig.xml]]
@@ -0,0 +1,735 @@
1
+ *This tutorial is only known to work with Hydra-Head 4. If you want to take over maintenance of this page, please do so.*
2
+
3
+ h1. Adding a Content Type to Your Hydra Application: Journal Article Example
4
+
5
+ h2. Before You Begin
6
+
7
+ This document assumes you have read "How to Get Started":https://github.com/projecthydra/hydra-head/wiki/How-to-Get-Started
8
+
9
+ This document is a work in progress. We are actively seeking feedback. If you run into anything that is incorrect or confusing, please email the "hydra-tech":http://groups.google.com/group/hydra-tech mailing list and let us know.
10
+
11
+ h3. What you will learn from this document
12
+
13
+ # Understand how Hydra fits into and uses Rails MVC (Model, View, Controller) structures
14
+ # Define an ActiveFedora Model for JournalArticles
15
+ # Define Controller & Views for Creating, Editing, Viewing and Deleting Journal Articles
16
+ # Customize how JournalArticles appear in Blacklight search results
17
+
18
+ h3. If you get stuck
19
+
20
+ We maintain a reference copy of the Hydra Head that is described in this Tutorial. It contains working versions of all the Models, Controllers, Views, and tests that you will be creating. If you get stuck, take a look at those files for ideas. We also maintain a Hudson build for this reference copy in order to ensure that all of the tests pass.
21
+
22
+ The code: http://github.com/projecthydra/hydra-tutorial-application
23
+ The Hudson Build: http://hudson.projecthydra.org/job/hydra-tutorial-app/
24
+
25
+
26
+ h2. Hydra and Rails MVC (Model, View, Controller)
27
+
28
+ In an MVC framework, the Model defines the attributes and behaviors of your various objects, allowing you to persist those objects and retrieve them. By default, Rails Models uses ActiveRecord to persist & retrieve objects using SQL databases. With Hydra, we use ActiveFedora to connect with Fedora and Solr instead of a SQL database.
29
+
30
+ Controllers handle requests from clients (ie. HTTP requests from a web browser), loading the necessary information and rendering the appropriate responses (ie. HTML pages returned to the browser). They use your Models to load the information and they use your Views to render the response. In this way, Controllers are like connectors or coordinators -- they coordinate the flow of activity in your application when it receives requests.
31
+
32
+ h2. The new Content Type: JournalArticle
33
+
34
+ In this tutorial, we are creating a new JournalArticle content type. This will allow us to create Journal Articles in a Fedora Repository, collect custom metadata for them, index them in solr, and display that custom metadata in the user interface.
35
+
36
+ In order to describe our Fedora objects, we can use whatever metadata schemas suit our needs. Some metadata schemas currently being used in Hydra Heads include MODS, Dublin Core, EAD, PBcore, EAC-CPF and VRE. This list continues to grow as people set up Hydra Heads to deal with their own specialized content.
37
+
38
+ The JournalArticle content type will use MODS (handily available in hydra-head) to track descriptive metadata about Articles. Some of the metadata is common to many types of content:
39
+
40
+ * title
41
+ * author (first name, last name, role)
42
+ * abstract
43
+
44
+ Other metadata fields are more specifically relevant to journal articles, but they still fit into the MODS schema:
45
+
46
+ * journal title
47
+ * publication date
48
+ * journal volume
49
+ * journal issue
50
+ * start page
51
+ * end page
52
+
53
+ In addition to the MODS metadata, JournalArticle objects will use Hydra Rights Metadata to track information about licenses, rights, and which people/groups should be able to discover, view, and/or edit each Journal Article.
54
+
55
+ h2. Define the ActiveFedora Model for JournalArticles
56
+
57
+ The first thing to do when adding a new content type is to create the ActiveFedora Model. This model is a Ruby class that uses ActiveFedora to tell the application the structure of your content and its metadata.
58
+
59
+ The model we create can be used in any application with ActiveFedora and OM (Opinionated Metadata), not just in a Hydra Head. For example, ActiveFedora models can be used in batch scripts, command line utilities, and robots that perform automated actions on your fedora objects based on information and behaviors stored in their ActiveFedora models.
60
+
61
+ h3. Where to find the full tutorial on defining ActiveFedora Models
62
+
63
+ This tutorial will only cover the very basics of defining an ActiveFedora Model and defining OM terminologies for its XML datastreams. For a complete introduction to those topics, see the "ActiveFedora Console Tour":http://hudson.projecthydra.org/job/active_fedora/Documentation/file.CONSOLE_GETTING_STARTED.html and the tutorials included in the "OM documentation":http://hudson.projecthydra.org/job/om/Documentation/.
64
+
65
+ h3. Tests to Define Expected Behaviors
66
+
67
+ These tests describe how our JournalArticle objects will behave once the Model is fully defined. We will have to do a few things before these tests pass, but it's important to define your goals before you start coding.
68
+
69
+ <pre>
70
+ # spec/modules/journal_article_spec.rb
71
+ require 'spec_helper'
72
+
73
+ describe JournalArticle do
74
+
75
+ before(:each) do
76
+ # This gives you a test article object that can be used in any of the tests
77
+ @article = JournalArticle.new
78
+ end
79
+
80
+ it "should have the specified datastreams" do
81
+ # Check for descMetadata datastream with MODS in it
82
+ @article.datastreams.keys.should include("descMetadata")
83
+ @article.descMetadata.should be_kind_of JournalArticleModsDatastream
84
+ # Check for rightsMetadata datastream
85
+ @article.datastreams.keys.should include("rightsMetadata")
86
+ @article.rightsMetadata.should be_kind_of Hydra::RightsMetadata
87
+ end
88
+
89
+ it "should have the attributes of a journal article and support update_attributes" do
90
+ attributes_hash = {
91
+ "title" => "All the Awesome you can Handle",
92
+ "abstract" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
93
+ "journal_title" => "The Journal of Cool",
94
+ "publication_date" => "1967-11-01",
95
+ "journal_volume" => "3",
96
+ "journal_issue" => "2",
97
+ "start_page" => "25",
98
+ "end_page" => "30",
99
+ }
100
+
101
+ @article.update_attributes( attributes_hash )
102
+
103
+ # These attributes have been marked "unique" in the call to delegate, which causes the results to be singular
104
+ @article.title.should == attributes_hash["title"]
105
+ @article.abstract.should == attributes_hash["abstract"]
106
+
107
+ # These attributes have not been marked "unique" in the call to the delegate, which causes the results to be arrays
108
+ @article.journal_title.should == [attributes_hash["journal_title"]]
109
+ @article.publication_date.should == [attributes_hash["publication_date"]]
110
+ @article.journal_volume.should == [attributes_hash["journal_volume"]]
111
+ @article.journal_issue.should == [attributes_hash["journal_issue"]]
112
+ @article.start_page.should == [attributes_hash["start_page"]]
113
+ @article.end_page.should == [attributes_hash["end_page"]]
114
+ end
115
+
116
+ end
117
+
118
+ </pre>
119
+
120
+ h4. Run the tests
121
+
122
+ The test code should execute but the tests should fail because we haven't written the code yet.
123
+
124
+ On the command line, run <pre>rake spec</pre>
125
+
126
+ You should get an error complaining that
127
+ <pre>spec/models/journal_article_spec.rb:3: uninitialized constant JournalArticle (NameError) </pre>
128
+
129
+ This is because we haven't defined the Model yet. Now let's define the JournalArticle Model, but first we have to define the datastream that will contain its MODS XML descriptive metadata.
130
+
131
+ If you get an error complaining that <pre>journal_article_spec.rb:2:in `require': no such file to load -- .../spec/spec_helper (LoadError)</pre> that means you need to run.
132
+
133
+ <pre>
134
+ rails g rspec:install
135
+ </pre>
136
+
137
+ h3. Defining the Datastreams
138
+
139
+ A Fedora object is made up of any number of _datastreams_. Datastreams can have content of any type and each datastream is identified by a _datastream id_ or _dsid_. The ActiveFedora model tells us which datastreams to expect or create in an object and tells us what kind of content is expected inside each datastream.
140
+
141
+ For our JournalArticle model, we're particularly interested datastreams with XML content because a JournalArticle object is basically a container for XML metadata. The actual content of the Article (PDF,text,whatever.) will be stored in a separate Fedora object, a _primitive_, with the RDF isPartOf relationship connecting the JournalArticle (primarily metadata) to its content (any number of primitives with files in them). For more information about datastreams, primitives, and where the actual content of an object lives, see the Reference links at the end of this tutorial.
142
+
143
+ h4. descMetadata -- the Descriptive Metadata Datastream
144
+
145
+ Our MODS xml will go into a datastream with the datastream id of _descMetadata_. Technically, we could give it any name we want but the Hydra community has come up with some conventions to make things simpler. One of these conventions is to always put descriptive metadata in a datastream called descMetadata.
146
+
147
+ As we said above, we want to create MODS metadata that keeps track of title, author (first name/last name/role), publication date, abstract, journal title, journal volume, journal issue, start page and end page. In order to do this we will use ActiveFedora to define a special type of Ruby object that uses OM to read and modify XML.
148
+
149
+ Example of the MODS XML we will be creating:
150
+
151
+ <pre>
152
+ <mods xmlns="http://www.loc.gov/mods/v3" version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3
153
+ http://www.loc.gov/standards/mods/v3/mods-3-0.xsd">
154
+ <titleInfo>
155
+ <title>ARTICLE TITLE</title> <!-- title -->
156
+ </titleInfo>
157
+ <name type="personal">
158
+ <namePart type="family">FAMILY NAME</namePart> <!-- author last name -->
159
+ <namePart type="given">GIVEN NAMES</namePart> <!-- author first name -->
160
+ <role>
161
+ <roleTerm authority="marcrelator" type="text">Creator</roleTerm> <!-- author role -->
162
+ </role>
163
+ </name>
164
+ <abstract>ABSTRACT</abstract> <!-- abstract -->
165
+ <relatedItem type="host">
166
+ <titleInfo>
167
+ <title>TITLE OF HOST JOURNAL</title> <!-- journal title -->
168
+ </titleInfo>
169
+ <part>
170
+ <detail type="volume">
171
+ <number>2</number> <!-- journal volume -->
172
+ </detail>
173
+ <detail type="level">
174
+ <number>2</number> <!-- journal issue -->
175
+ </detail>
176
+ <extent unit="pages">
177
+ <start>195</start> <!-- start page -->
178
+ <end>230</end> <!-- end page -->
179
+ </extent>
180
+ <date>FEB. 2007</date> <!-- publication date -->
181
+ </part>
182
+ </relatedItem>
183
+ </mods>
184
+ </pre>
185
+
186
+ The constraints of a metadata schema sometimes force us to put information into structures that don't map directly to the vocabulary that we use when talking about that information. The "title" has ended up in a spot that you might call the "mods titleInfo title" and the "start page" has ended up in a spot that you might call the <pre>"mods host-relatedItem part pages-extent start"</pre> or <pre>"//mods/relatedItem[@type=host]/part/extent[@unit='pages']/start"</pre> ... quite the mouthful, isn't it? This is where OM comes in. OM lets us define a Terminology that will allow us to access values in the xml based on our natural vocabulary (title, start page, etc.) while also allowing us to access those same values using the more cumbersome XML-speak when necessary.
187
+
188
+ h5. Unit tests for the expected behaviors of a JournalArticleModsDatastream
189
+
190
+ This test is a bit more fine-grained than you really need, but it lets you see how you can access the information in an XML Datastream with OM.
191
+
192
+ <pre>
193
+ # spec/datastreams/journal_article_mods_datastream_spec.rb
194
+ require 'spec_helper'
195
+
196
+ describe JournalArticleModsDatastream do
197
+ before(:each) do
198
+ @mods = fixture("article_mods_sample.xml")
199
+ @ds = JournalArticleModsDatastream.from_xml(@mods)
200
+ end
201
+ it "should expose bibliographic info for journal articles with explicit terms and simple proxies" do
202
+ @ds.mods.title_info.main_title.should == ["SAMPLE ARTICLE TITLE"]
203
+ @ds.title.should == ["SAMPLE ARTICLE TITLE"]
204
+ @ds.abstract.should == ["THIS IS AN ABSTRACT"]
205
+ @ds.journal.title_info.main_title.should == ["SAMPLE HOST JOURNAL TITLE"]
206
+ @ds.journal_title.should == ["SAMPLE HOST JOURNAL TITLE"]
207
+ @ds.journal.issue.date.should == ["FEB. 2007"]
208
+ @ds.publication_date.should == ["FEB. 2007"]
209
+ @ds.journal.issue.volume.number.should == ["2"]
210
+ @ds.journal_volume.should == ["2"]
211
+ @ds.journal.issue.level.number.should == ["18"]
212
+ @ds.journal_issue.should == ["18"]
213
+ @ds.journal.issue.pages.start.should == ["195"]
214
+ @ds.start_page.should == ["195"]
215
+ @ds.journal.issue.pages.end.should == ["230"]
216
+ @ds.end_page.should == ["230"]
217
+ end
218
+
219
+
220
+ it "should expose nested/hierarchical metadata" do
221
+ @ds.author.first_name.should == ["George","Abraham"]
222
+ @ds.author.last_name.should == ["Washington", "Lincoln"]
223
+ @ds.author.role.text.should == ["Creator", "Contributor"]
224
+ @ds.author(0).first_name.should == ["George"]
225
+ @ds.author(0).last_name.should == ["Washington"]
226
+ @ds.author(0).role.text.should == ["Creator"]
227
+ end
228
+ end
229
+ </pre>
230
+
231
+
232
+ You need to add this simple method to your spec helper so that the tests will be able to load xml files from the spec/fixtures directory.
233
+
234
+ <pre>
235
+ # spec/spec_helper.rb
236
+ ...
237
+ Spec::Runner.configure do |config|
238
+
239
+ ...
240
+
241
+ def fixture(file)
242
+ File.new(File.join(File.dirname(__FILE__), 'fixtures', file))
243
+ end
244
+ end
245
+ </pre>
246
+
247
+ Now download the sample MODS xml from <code>https://raw.github.com/projecthydra/hydra-tutorial-application/master/spec/fixtures/article_mods_sample.xml</code> and save it as <code>spec/fixtures/article_mods_sample.xml</code>
248
+
249
+ Now run the test to see it fail before we write the code to make it pass. We know that the journal_article_spec.rb tests are still failing, so instead of using rake spec to run all the tests, we will just run this one spec file from the command line:
250
+
251
+ <pre>rspec spec/datastreams/journal_article_mods_datastream_spec.rb</pre>
252
+
253
+ You should see an error that includes a message like this:
254
+
255
+ <pre>hydra-tutorial-app/spec/datastreams/journal_article_mods_datastream_spec.rb:3: uninitialized constant JournalArticleModsDatastream (NameError)</pre>
256
+
257
+ Now we will define the JournalArticleModsDatastream class so the test will pass.
258
+
259
+
260
+
261
+ h5. Coding the descMetadata Datastream model
262
+
263
+ Here's how we define the datastream class for the descMetadata. Notice that we use set_terminology which defines its OM Terminology.
264
+
265
+ <b><i>Create a new file in app/models/datastreams called journal_article_mods_datastream.rb</i></b> and put this into it (NOTE: you could also save this file as lib/journal_article_mods_datastream.rb and get the same results):
266
+
267
+ <pre>
268
+ # app/models/datastreams/journal_article_mods_datastream.rb
269
+
270
+ # a Fedora Datastream object containing Mods XML for the descMetadata
271
+ # datastream in the Journal Article hydra content type, defined using
272
+ # ActiveFedora and OM.
273
+
274
+ require 'hydra-mods'
275
+
276
+ class JournalArticleModsDatastream < ActiveFedora::NokogiriDatastream
277
+
278
+ # OM (Opinionated Metadata) terminology mapping for the mods xml
279
+ set_terminology do |t|
280
+ t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
281
+ t.title_info(:path=>"titleInfo") {
282
+ t.main_title(:index_as=>[:facetable],:path=>"title", :label=>"title")
283
+ }
284
+ t.author(:path=>"name", :attributes=>{:type=>"personal"}) {
285
+ t.first_name(:path=>"namePart", :attributes=>{:type=>"given"})
286
+ t.last_name(:path=>"namePart", :attributes=>{:type=>"family"})
287
+ t.role {
288
+ t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
289
+ }
290
+ }
291
+ t.abstract
292
+ t.journal(:path=>'relatedItem', :attributes=>{:type=>"host"}) {
293
+ t.title_info(:ref=>[:title_info])
294
+ t.issue(:path=>"part") {
295
+ t.volume(:path=>"detail", :attributes=>{:type=>"volume"}) {
296
+ t.number
297
+ }
298
+ t.level(:path=>"detail", :attributes=>{:type=>"level"}) {
299
+ t.number
300
+ }
301
+ t.pages(:path=>"extent", :attributes=>{:unit=>"pages"}) {
302
+ t.start
303
+ t.end
304
+ }
305
+ t.date
306
+ }
307
+ }
308
+
309
+ # these proxy declarations allow you to use more familiar term/field names that hide the details of the XML structure
310
+ t.title(:proxy=>[:mods, :title_info, :main_title])
311
+ t.journal_title(:proxy=>[:journal, :title_info, :main_title])
312
+ t.journal_volume(:proxy=>[:journal, :issue, :volume, :number])
313
+ t.journal_issue(:proxy=>[:journal, :issue, :level, :number])
314
+ t.start_page(:proxy=>[:journal, :issue, :pages, :start])
315
+ t.end_page(:proxy=>[:journal, :issue, :pages, :end])
316
+ t.publication_date(:proxy=>[:journal, :issue, :date])
317
+
318
+ end # set_terminology
319
+
320
+ # This defines what the default xml should look like when you create empty MODS datastreams.
321
+ # We are reusing the ModsArticle xml_template that Hydra provides, but you can make this method return any xml you desire.
322
+ # See the API docs for more info. http://rubydoc.info/github/projecthydra/om/OM/XML/Container/ClassMethods#xml_template-instance_method
323
+ def self.xml_template
324
+ return Hydra::ModsArticle.xml_template
325
+ end
326
+ end # class
327
+ </pre>
328
+
329
+ Save that file and run the tests again. They should pass - if not - you need to add a cmd in the config/application.rb to ensure that your new app/model/datastreams/journal_article_mods_datastream.rb is available.
330
+ <pre>
331
+ class Application < Rails::Application
332
+ ...
333
+ config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
334
+ ...
335
+ end
336
+ </pre>
337
+ Good to go. You might get some extra information output onto the console while the tests run.
338
+
339
+ <pre>
340
+ rspec spec/datastreams/journal_article_mods_datastream_spec.rb
341
+ ..
342
+
343
+ Finished in 7.26 seconds
344
+ 2 examples, 0 failures
345
+ </pre>
346
+
347
+ The key here is "2 examples, 0 failures".
348
+
349
+ Try deleting lines from the datastream definition or changing values in the fixture xml then re-run the tests to see what it looks like when the tests fail.
350
+
351
+
352
+ h4. rightsMetadata -- The Hydra Rights Metadata Datastream
353
+
354
+ The hydra-head plugin provides a class definition for the rightsMetadata datastream, so you won't have to define the OM Terminology yourself. The definition is in the hydra-head plugin code in "lib/hydra/rights_metadata.rb":https://github.com/projecthydra/hydra-head/blob/master/lib/hydra/rights_metadata.rb.
355
+
356
+ Here's an example of what rightsMetadata XML looks like:
357
+
358
+ <pre>
359
+ <rightsMetadata xmlns="http://hydra-collab.stanford.edu/schemas/rightsMetadata/v1">
360
+ <copyright>
361
+ <human>(c)2009 The Hydra Project</human>
362
+ <human type="someSpecialisedType">Blah Blah</human>
363
+ <human type="aDifferentType">More blah</human>
364
+ <machine><a rel="license" href="http://creativecommons.org/licenses/publicdomain/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/publicdomain/88x31.png" /></a><br />This work is in the <a rel="license" href="http://creativecommons.org/licenses/publicdomain/">Public Domain</a>.</machine>
365
+ </copyright>
366
+ <access type="discover">
367
+ <human></human>
368
+ <machine>
369
+ <policy>hydra-policy:4502</policy>
370
+ <group>public</group>
371
+ </machine>
372
+ </access>
373
+ <access type="read">
374
+ <human></human>
375
+ <machine>
376
+ <group>public</group>
377
+ </machine>
378
+ </access>
379
+ <access type="edit">
380
+ <human></human>
381
+ <machine>
382
+ <person>researcher1</person>
383
+ <group>archivist</group>
384
+ </machine>
385
+ </access>
386
+ <access type="etc">
387
+ <!-- etc -->
388
+ </access>
389
+ <use>
390
+ <human>You are free to re-distribute this object, but you cannot change it or sell it. </human>
391
+ <machine><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/us/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-nd/3.0/us/88x31.png" /></a><br />This <span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Sound" rel="dc:type">work</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/us/">Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License</a>.</machine>
392
+ </use>
393
+
394
+ </rightsMetadata>
395
+ </pre>
396
+
397
+
398
+ The Hydra::RightsMetadata datastream definition is provided by hydra-head, so we don't need to implement it or write tests for it.
399
+
400
+ h4. RELS-EXT & DC Datastreams (Fedora defaults)
401
+
402
+ There are two special datastreams that Fedora creates for you -- the DC datastream and the RELS-EXT datastream. We don't really use the DC datastream. It contains simple Dublin Core metadata that mainly exists for Fedora's internal use. The RELS-EXT datastream contains RDF representing the relationships between the objects in a Fedora repository. ActiveFedora and Hydra both use these RDF relationships in a number of ways. For more information about how to work with RDF relationships in ActiveFedora, see the ActiveFedora documentation links at the end of this tutorial.
403
+
404
+ h3. Defining the Model and adding the Datastreams to it
405
+
406
+ Now we're ready to assemble the JournalArticle model and make its tests pass. First, rerun the tests to see them pass:
407
+
408
+ <pre>rake spec</pre>
409
+
410
+ <b><i>Create a file in app/models called journal_article.rb</i></b> and put these lines into it:
411
+
412
+ <pre>
413
+ # app/models/journal_article.rb
414
+ # a Fedora object for the Journal Article hydra content type
415
+ class JournalArticle < ActiveFedora::Base
416
+ include Hydra::ModelMethods
417
+
418
+ has_metadata :name => "descMetadata", :type=> JournalArticleModsDatastream
419
+ has_metadata :name => "rightsMetadata", :type => Hydra::RightsMetadata
420
+ end
421
+ </pre>
422
+
423
+ Rerun the tests in journal_article_spec.rb and you will see actual failures (probably in red) instead of the error message about JournalArticle being undefined.
424
+
425
+ <pre>rspec ./spec/models/journal_article_spec.rb</pre>
426
+
427
+ <pre>
428
+ .F
429
+
430
+ Failures:
431
+
432
+ 1) JournalArticle should have the attributes of a journal article and support update_attributes
433
+ Failure/Error: @article.update_attributes( attributes_hash )
434
+ ActiveFedora::UnknownAttributeError:
435
+ unknown attribute: end_page
436
+ # ./spec/models/journal_article_spec.rb:31
437
+
438
+ Finished in 7.51 seconds
439
+ 2 examples, 1 failure
440
+
441
+ Failed examples:
442
+
443
+ rspec ./spec/models/journal_article_spec.rb:19 # JournalArticle should have the attributes of a journal article and support update_attributes
444
+ </pre>
445
+
446
+ "2 examples, 1 failure" means that the first test is now passing. You have defined the datastreams correctly using has_metadata. Now we need to make the JournalArticle model delegate the attributes we want to the descMetadata datastream. To do that, add these lines into the JournalArticle class defnition:
447
+
448
+ <pre>
449
+ # The delegate method allows you to set up attributes on the model that are stored in datastreams
450
+ # When you set :unique=>"true", searches will return a single value instead of an array.
451
+ delegate :title, :to=>"descMetadata", :unique=>"true"
452
+ delegate :abstract, :to=>"descMetadata", :unique=>"true"
453
+
454
+ delegate :start_page, :to=>"descMetadata"
455
+ delegate :end_page, :to=>"descMetadata"
456
+ delegate :publication_date, :to=>"descMetadata"
457
+ delegate :journal_title, :to=>"descMetadata"
458
+ delegate :journal_volume, :to=>"descMetadata"
459
+ delegate :journal_issue, :to=>"descMetadata"
460
+ </pre>
461
+
462
+
463
+ h3. Test Your Work
464
+
465
+ Now rerun the tests. They should all pass.
466
+
467
+ <pre>
468
+ rspec ./spec/models/journal_article_spec.rb
469
+
470
+ ..
471
+
472
+ Finished in 8.09 seconds
473
+ 2 examples, 0 failures
474
+ </pre>
475
+
476
+ <pre>rake spec
477
+ ....*
478
+
479
+ Pending:
480
+ User add some examples to (or delete) /Users/matt/Develop/projects/hydra-tutorial-app/spec/models/user_spec.rb
481
+ # Not Yet Implemented
482
+ # ./spec/models/user_spec.rb:4
483
+
484
+ Finished in 8.12 seconds
485
+ 5 examples, 0 failures, 1 pending
486
+ </pre>
487
+
488
+ The test that's marked "pending" was generated when you ran the blacklight generator. You can either add some assertions to it or delete it in order to make your test suite "green" (everything passing, nothing pending).
489
+
490
+
491
+ h2. Defining Journal Articles Controller and Views
492
+
493
+ Now that you've defined the Model, you need to define the Controller & Views for Creating, Retrieving, Updating and Deleting (CRUD) Journal Articles.
494
+
495
+
496
+ <pre>
497
+ # spec/controllers/journal_articles_controller_spec.rb
498
+ describe JournalArticlesController do
499
+
500
+ describe "creating" do
501
+ it "should render the create page" do
502
+ get :new
503
+ assigns[:journal_article].should be_kind_of JournalArticle
504
+ renders.should == "new"
505
+ end
506
+ end
507
+ end
508
+ </pre>
509
+
510
+ ... no controller ...
511
+
512
+ h3. URL Routing for JournalArticles
513
+
514
+ <pre>
515
+ # config/routes.rb
516
+ ...
517
+ resources :journal_articles
518
+ ...
519
+ </pre>
520
+
521
+ h3. Defining the JournalArticlesController
522
+
523
+ <pre>
524
+ # app/controllers/journal_articles_controller.rb
525
+ class JournalArticlesController < ApplicationController
526
+ def new
527
+ @journal_article = JournalArticle.new
528
+ end
529
+ end
530
+ </pre>
531
+
532
+ h3. The "Create" View
533
+
534
+ h4. Cucumber Test for "Create" View
535
+
536
+ You will need to have run:
537
+
538
+ <pre>
539
+ rails g cucumber:install
540
+ </pre>
541
+
542
+ <pre>
543
+ Given I am logged in as archivist1@example.com
544
+ And I am on the home page
545
+ When I click "Add a Journal Article"
546
+ Then I should see ...
547
+ When I fill in ...
548
+ And I click "Create this Journal Article"
549
+ Then I should see "Journal Article 'My title' created."
550
+ </pre>
551
+
552
+ h4. "Add a Journal Article" button
553
+
554
+ First, we need to add a link to the Hydra Head that lets you create Journal Articles. To do this, you need to override the _add_asset_links view partial. Here's the cucumber test for what you want:
555
+
556
+ hydra-head puts a list of "add asset" links into the user_util_links section of the page. This list is defined in app/views/_add_asset_links.html.erb. By default, this list includes links for adding Images, MODS Assets and Generic Content. We want it to have just one link -- create an Article. To override the list, create a file at app/views/_add_assets_links.html.erb and put this into it:
557
+
558
+ <pre>
559
+ <div id="select-item-box">
560
+ <a class="add-new-asset" href="#">Add a New Asset</a>
561
+ <ul id="select-item-list">
562
+ <li>
563
+ <%= link_to_create_asset 'Add an Article', 'journal_article' %>
564
+ </li>
565
+ </ul>
566
+ </div>
567
+ </pre>
568
+
569
+ h4. Form for Creating Journal Articles
570
+
571
+ h4. Controller "Create" Method
572
+
573
+ <pre>
574
+ # spec/controllers/journal_articles_controller_spec.rb
575
+ describe JournalArticlesController do
576
+
577
+ describe "creating" do
578
+ it "should render the create page" do
579
+ ...
580
+ end
581
+ it "should support create requests" do
582
+ post :create, :journal_article=>{"title"=>"My title"}
583
+ ja = assigns[:journal_article]
584
+ ja.title.should == "My title"
585
+ end
586
+ end
587
+ end
588
+ </pre>
589
+
590
+ Restart the app, load up http://localhost:3000/journal_articles/new and try it out.
591
+
592
+ h3. The "Edit" View
593
+
594
+ h4. The Fixture Object for tests
595
+
596
+ h4. Cucumber Test for "Edit"
597
+
598
+ <pre>
599
+ Given I am on the edit page for "hydra:fixture_journal_article"
600
+ And I fill in "Title" with "The History of Hopscotch"
601
+ When I click "Save"
602
+ Then I should see "The History of Hopscotch has been updated."
603
+ </pre>
604
+
605
+ h4. Controller Edit & Update Methods
606
+
607
+ <pre>
608
+ # spec/controllers/journal_articles_controller_spec.rb
609
+ describe JournalArticlesController do
610
+
611
+ describe "creating" do
612
+ ...
613
+ end
614
+
615
+ describe "editing" do
616
+ it "should support edit requests" do
617
+ get :edit, :id=>"hydra:fixture_journal_article"
618
+ assigns[:journal_article].should be_kind_of JournalArticle
619
+ assigns[:journal_article].pid.should == "hydra:fixture_journal_article"
620
+ end
621
+ it "should support updating objects" do
622
+ put :update, :journal_article=>{"title"=>"My Newest Title"}
623
+ ja = assigns[:journal_article]
624
+ ja.title.should == "My Newest Title"
625
+ end
626
+ end
627
+ end
628
+ </pre>
629
+
630
+ <pre>
631
+ # app/controllers/journal_articles_controller.rb
632
+ class JournalArticlesController < ApplicationController
633
+ def new
634
+ ...
635
+ end
636
+
637
+ def edit
638
+ @journal_article = JournalArticle.find(params[:id])
639
+ end
640
+
641
+ def update
642
+ @journal_article = JournalArticle.find(params[:id])
643
+ @journal_article.update_attributes(params[:journal_article])
644
+ redirect_to :edit
645
+ end
646
+ end
647
+ </pre>
648
+
649
+ h4. Form for Editing Journal Articles
650
+
651
+ <pre>
652
+ # app/views/journal_articles/_edit.html.erb
653
+ <%= form_for @journal_article do |f| %>
654
+ <%= f.label :title %>
655
+ <%= f.text_field :title %>
656
+ <%= f.submit "Save" %>
657
+ <% end %>
658
+ </pre>
659
+
660
+ h3. The Show Page
661
+
662
+ h4. Controller "Show" Method
663
+
664
+ The show method definition is almost identical to the edit method. With time, the two methods will accumulate different logic within your application, but for now they both have one basic role: load the requested object and pass it into the requested view template.
665
+
666
+ <pre>
667
+ # app/controllers/journal_articles_controller.rb
668
+ class JournalArticlesController < ApplicationController
669
+ def new
670
+ ...
671
+ end
672
+
673
+ def show
674
+ @journal_article = JournalArticle.find(params[:id])
675
+ end
676
+
677
+ def edit
678
+ @journal_article = JournalArticle.find(params[:id])
679
+ end
680
+
681
+ def update
682
+ ...
683
+ end
684
+ end
685
+ </pre>
686
+
687
+ h4. View Template for "Show"
688
+
689
+
690
+ <pre>
691
+ # app/views/journal_articles/edit.html.erb
692
+ <h1>&lt;%= @journal_article.title %>&lt;/h1>
693
+ <dl>
694
+ <dt>Title&lt;/dt>
695
+ <dd>
696
+ <%= @journal_article.title %>
697
+ </dd>
698
+ <dt>Journal&lt;/dt>
699
+ <dd>
700
+ <%= @journal_article.journal_title %>
701
+ </dd>
702
+ </dl>
703
+ </pre>
704
+
705
+ h2. Journal Articles in Blacklight Search Results
706
+
707
+ h3. Look at the Solr Document for a Journal Article
708
+
709
+ title_t, journal_title_t
710
+
711
+ active_fedora_model_s and Blacklight.config[:display_type]
712
+
713
+ h3. The _index partial
714
+
715
+ <pre>
716
+ # app/views/journal_articles/_index.html.erb
717
+ <dl>
718
+ <dt>Title&lt;/dt>
719
+ <dd>
720
+ <%= document["title_t"] %>
721
+ </dd>
722
+ <dt>Journal&lt;/dt>
723
+ <dd>
724
+ <%= document["journal_title_t"] %>
725
+ </dd>
726
+ </dl>
727
+ </pre>
728
+
729
+ h2. Hydra Modeling Conventions
730
+
731
+ See "Hydra Modeling Conventions":https://github.com/projecthydra/hydra-head/wiki/Models---Hydra-Conventions
732
+
733
+ h2. For Further Information
734
+
735
+ See "Reference":https://github.com/projecthydra/hydra-head/wiki/Reference for more links.