hydra-tutorial 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "" do
4
+ it "should" do
5
+ true.should be_true
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Record < ActiveFedora::Base
2
+
3
+ has_metadata :name => "descMetadata", :type => ActiveFedora::NokogiriDatastream
4
+
5
+ end
@@ -0,0 +1,13 @@
1
+ class Record < ActiveFedora::Base
2
+
3
+ has_metadata :name => "descMetadata", :type => ModsDescMetadata
4
+
5
+ delegate :title, :to=>'descMetadata', :at => [:mods, :titleInfo, :title], :unique=>true
6
+ delegate :abstract, :to => "descMetadata"
7
+ delegate :preferred_citation, :to => "descMetadata", :unique=>true
8
+ delegate :author, :to=>'descMetadata', :at => [:name, :namePart], :unique=>true
9
+ delegate :url, :to=>'descMetadata', :at => [:relatedItem, :location, :url], :unique=>true
10
+ delegate :description, :to=>'descMetadata', :at => [:abstract], :unique=>true
11
+
12
+ end
13
+
@@ -0,0 +1,28 @@
1
+ class Record < ActiveFedora::Base
2
+
3
+ class DatastreamMetadata < ActiveFedora::NokogiriDatastream
4
+
5
+ ##
6
+ # Here's the important part. We're mapping XML into Ruby.
7
+ set_terminology do |t|
8
+ t.root :path => 'root', :xmlns => nil
9
+ t.title
10
+ t.author
11
+ t.url
12
+ t.description
13
+ end
14
+
15
+ def self.xml_template
16
+ Nokogiri::XML::Builder.new do |xml|
17
+ xml.root do
18
+ xml.title
19
+ xml.author
20
+ xml.url
21
+ xml.description
22
+ end
23
+ end.doc
24
+ end
25
+ end
26
+
27
+ has_metadata :name => "descMetadata", :type => DatastreamMetadata
28
+ end
@@ -0,0 +1,135 @@
1
+ class ModsDescMetadata < ActiveFedora::NokogiriDatastream
2
+ # MODS XML constants.
3
+
4
+ MODS_NS = 'http://www.loc.gov/mods/v3'
5
+ MODS_SCHEMA = 'http://www.loc.gov/standards/mods/v3/mods-3-3.xsd'
6
+ MODS_PARAMS = {
7
+ "version" => "3.3",
8
+ "xmlns:xlink" => "http://www.w3.org/1999/xlink",
9
+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
10
+ "xmlns" => MODS_NS,
11
+ "xsi:schemaLocation" => "#{MODS_NS} #{MODS_SCHEMA}",
12
+ }
13
+
14
+ # OM terminology.
15
+
16
+ set_terminology do |t|
17
+ t.root :path => 'mods', :xmlns => MODS_NS
18
+ t.originInfo do
19
+ t.dateOther
20
+ end
21
+ t.abstract
22
+ t.titleInfo do
23
+ t.title
24
+ end
25
+
26
+ t.title :ref => [:mods, :titleInfo, :title]
27
+ t.name do
28
+ t.namePart
29
+ t.role do
30
+ t.roleTerm
31
+ end
32
+ end
33
+
34
+ t.relatedItem do
35
+ t.titleInfo do
36
+ t.title
37
+ end
38
+ t.location do
39
+ t.url
40
+ end
41
+ end
42
+
43
+ t.subject do
44
+ t.topic
45
+ end
46
+
47
+ t.preferred_citation :path => 'note', :attributes => { :type => "preferred citation" }
48
+ t.related_citation :path => 'note', :attributes => { :type => "citation/reference" }
49
+
50
+ end
51
+
52
+ # Blocks to pass into Nokogiri::XML::Builder.new()
53
+
54
+ define_template :name do |xml|
55
+ xml.name {
56
+ xml.namePart
57
+ xml.role {
58
+ xml.roleTerm(:authority => "marcrelator", :type => "text")
59
+ }
60
+ }
61
+ end
62
+
63
+ define_template :relatedItem do |xml|
64
+ xml.relatedItem {
65
+ xml.titleInfo {
66
+ xml.title
67
+ }
68
+ xml.location {
69
+ xml.url
70
+ }
71
+ }
72
+ end
73
+
74
+ define_template :related_citation do |xml|
75
+ xml.note(:type => "citation/reference")
76
+ end
77
+
78
+ def self.xml_template
79
+ Nokogiri::XML::Builder.new do |xml|
80
+ xml.mods(MODS_PARAMS) {
81
+ xml.originInfo {
82
+ xml.dateOther
83
+ }
84
+ xml.abstract
85
+ xml.titleInfo {
86
+ xml.title
87
+ }
88
+ xml.name {
89
+ xml.namePart
90
+ xml.role {
91
+ xml.roleTerm
92
+ }
93
+ }
94
+ xml.relatedItem {
95
+ xml.titleInfo {
96
+ xml.title
97
+ }
98
+ xml.location {
99
+ xml.url
100
+ }
101
+ }
102
+ xml.subject {
103
+ xml.topic
104
+ }
105
+ xml.note(:type => "preferred citation")
106
+ xml.note(:type => "citation/reference")
107
+ }
108
+ end.doc
109
+ end
110
+
111
+ def insert_person
112
+ insert_new_node(:name)
113
+ end
114
+
115
+ def insert_related_item
116
+ insert_new_node(:relatedItem)
117
+ end
118
+
119
+ def insert_related_citation
120
+ insert_new_node(:related_citation)
121
+ end
122
+
123
+ def insert_new_node(term)
124
+ add_child_node(ng_xml.root, term)
125
+ end
126
+
127
+ def remove_node(term, index)
128
+ node = self.find_by_terms(term.to_sym => index.to_i).first
129
+ unless node.nil?
130
+ node.remove
131
+ self.dirty = true
132
+ end
133
+ end
134
+
135
+ end
@@ -0,0 +1,14 @@
1
+ development:
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora
5
+ test: &TEST
6
+ user: fedoraAdmin
7
+ password: fedoraAdmin
8
+ url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/fedora-test" %>
9
+ production:
10
+ user: fedoraAdmin
11
+ password: fedoraAdmin
12
+ url: http://your.production.server:8080/fedora
13
+ cucumber:
14
+ <<: *TEST
@@ -0,0 +1,10 @@
1
+ # This is a sample config file that does not have multiple solr instances. You will also need to be sure to
2
+ # edit the fedora.yml file to match the solr URL for active-fedora.
3
+ development:
4
+ url: http://localhost:8983/solr/development
5
+ test: &TEST
6
+ url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/test" %>
7
+ cucumber:
8
+ <<: *TEST
9
+ production:
10
+ url: http://your.production.server:8080/bl_solr/core0
@@ -0,0 +1,83 @@
1
+ class RecordsController < ApplicationController
2
+ # GET /records
3
+ # GET /records.json
4
+ def index
5
+ @records = Record.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @records }
10
+ end
11
+ end
12
+
13
+ # GET /records/1
14
+ # GET /records/1.json
15
+ def show
16
+ @record = Record.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @record }
21
+ end
22
+ end
23
+
24
+ # GET /records/new
25
+ # GET /records/new.json
26
+ def new
27
+ @record = Record.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @record }
32
+ end
33
+ end
34
+
35
+ # GET /records/1/edit
36
+ def edit
37
+ @record = Record.find(params[:id])
38
+ end
39
+
40
+ # POST /records
41
+ # POST /records.json
42
+ def create
43
+ @record = Record.new(params[:record])
44
+
45
+ respond_to do |format|
46
+ if @record.save
47
+ format.html { redirect_to @record, notice: 'Record was successfully created.' }
48
+ format.json { render json: @record, status: :created, location: @record }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @record.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /records/1
57
+ # PUT /records/1.json
58
+ def update
59
+ @record = Record.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @record.update_attributes(params[:record])
63
+ format.html { redirect_to @record, notice: 'Record was successfully updated.' }
64
+ format.json { head :no_content }
65
+ else
66
+ format.html { render action: "edit" }
67
+ format.json { render json: @record.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /records/1
73
+ # DELETE /records/1.json
74
+ def destroy
75
+ @record = Record.find(params[:id])
76
+ @record.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to records_url }
80
+ format.json { head :no_content }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,31 @@
1
+ <%= form_for(@record) do |f| -%>
2
+ <h2>Title</h2>
3
+ <div class="row">
4
+ <%= f.label :title, "Title" %>
5
+ <%= f.text_area :title, :value=>@record.title, :required => true %>
6
+ </div>
7
+
8
+ <h2>Abstract and keywords</h2>
9
+
10
+ <div class="row">
11
+ <%= f.label :abstract %>
12
+ <%= f.text_area :abstract, :value=>@record.abstract.first, :required=>true %>
13
+ </div>
14
+
15
+ <div class="row">
16
+ <%= label_tag("hydrus_item_keywords", "Keywords") %>
17
+ <%= text_field_tag("hydrus_item_keywords", @record.descMetadata.subject.topic.join(", ")) -%>
18
+ <div class="help">separate keywords with commas</div>
19
+ </div>
20
+
21
+ <h2>Citations</h2>
22
+ <div class="row">
23
+ <%= f.label :preferred_citation, "Preferred citation for this object", :class => "hidden-tablet" %>
24
+ <%= f.text_area :preferred_citation, :value=>@record.preferred_citation %>
25
+ </div>
26
+
27
+ <input type="submit" class="btn btn-small save-edits" name="save" id="save" />
28
+
29
+ <% end %>
30
+
31
+
@@ -0,0 +1,7 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1><%= @record.title %></h1>
4
+
5
+ <%= link_to 'Edit', edit_record_path(@record) %> |
6
+ <%= link_to 'Back', records_path %>
7
+
@@ -0,0 +1,13 @@
1
+ class Dataset < ActiveFedora::Base
2
+
3
+ include Hydra::ModelMixins::CommonMetadata
4
+ include Hydra::ModelMethods
5
+
6
+ has_metadata :name => "descMetadata", :type => ModsDescMetadata
7
+
8
+ delegate :title, :to=>'descMetadata', :at => [:mods, :titleInfo, :title], :unique=>true
9
+ delegate :author, :to=>'descMetadata', :at => [:name, :namePart], :unique=>true
10
+ delegate :url, :to=>'descMetadata', :at => [:relatedItem, :location, :url], :unique=>true
11
+ delegate :description, :to=>'descMetadata', :at => [:abstract], :unique=>true
12
+
13
+ end
@@ -0,0 +1,37 @@
1
+ class Dataset < ActiveFedora::Base
2
+
3
+ class DatastreamMetadata < ActiveFedora::NokogiriDatastream
4
+
5
+ ##
6
+ # Here's the important part. We're mapping XML into Ruby.
7
+ set_terminology do |t|
8
+ t.root :path => 'root', :xmlns => nil
9
+ t.title
10
+ t.author
11
+ t.url
12
+ t.description
13
+ end
14
+
15
+ def self.xml_template
16
+ Nokogiri::XML::Builder.new do |xml|
17
+ xml.root do
18
+ xml.title
19
+ xml.author
20
+ xml.url
21
+ xml.description
22
+ end
23
+ end.doc
24
+ end
25
+ end
26
+
27
+ include Hydra::ModelMixins::CommonMetadata
28
+ include Hydra::ModelMethods
29
+
30
+ has_metadata :name => "descMetadata", :type => DatastreamMetadata
31
+
32
+ delegate :title, :to=>'descMetadata', :unique=>true
33
+ delegate :author, :to=>'descMetadata', :unique=>true
34
+ delegate :url, :to=>'descMetadata', :unique=>true
35
+ delegate :description, :to=>'descMetadata', :unique=>true
36
+
37
+ end
@@ -0,0 +1,82 @@
1
+ class DatasetsController < ApplicationController
2
+ # GET /datasets
3
+ # GET /datasets.json
4
+ def index
5
+ @datasets = Dataset.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @datasets }
10
+ end
11
+ end
12
+
13
+ # GET /datasets/1
14
+ # GET /datasets/1.json
15
+ def show
16
+ @dataset = Dataset.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @dataset }
21
+ end
22
+ end
23
+
24
+ # GET /datasets/new
25
+ # GET /datasets/new.json
26
+ def new
27
+ @dataset = Dataset.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @dataset }
32
+ end
33
+ end
34
+
35
+ # GET /datasets/1/edit
36
+ def edit
37
+ @dataset = Dataset.find(params[:id])
38
+ end
39
+
40
+ # POST /datasets
41
+ # POST /datasets.json
42
+ def create
43
+ @dataset = Dataset.new(params[:dataset])
44
+ respond_to do |format|
45
+ if @dataset.save
46
+ format.html { redirect_to @dataset, notice: 'Dataset was successfully created.' }
47
+ format.json { render json: @dataset, status: :created, location: @dataset }
48
+ else
49
+ format.html { render action: "new" }
50
+ format.json { render json: @dataset.errors, status: :unprocessable_entity }
51
+ end
52
+ end
53
+ end
54
+
55
+ # PUT /datasets/1
56
+ # PUT /datasets/1.json
57
+ def update
58
+ @dataset = Dataset.find(params[:id])
59
+
60
+ respond_to do |format|
61
+ if @dataset.update_attributes(params[:dataset])
62
+ format.html { redirect_to @dataset, notice: 'Dataset was successfully updated.' }
63
+ format.json { head :no_content }
64
+ else
65
+ format.html { render action: "edit" }
66
+ format.json { render json: @dataset.errors, status: :unprocessable_entity }
67
+ end
68
+ end
69
+ end
70
+
71
+ # DELETE /datasets/1
72
+ # DELETE /datasets/1.json
73
+ def destroy
74
+ @dataset = Dataset.find(params[:id])
75
+ @dataset.destroy
76
+
77
+ respond_to do |format|
78
+ format.html { redirect_to datasets_url }
79
+ format.json { head :no_content }
80
+ end
81
+ end
82
+ end