hydra-collections 0.0.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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.gitmodules +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +16 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +133 -0
  10. data/Rakefile +12 -0
  11. data/app/assets/javascripts/hydra/batch_select.js +41 -0
  12. data/app/assets/javascripts/hydra_collections.js +12 -0
  13. data/app/controllers/collections_controller.rb +18 -0
  14. data/app/helpers/batch_select_helper.rb +25 -0
  15. data/app/helpers/collections_helper.rb +14 -0
  16. data/app/models/collection.rb +16 -0
  17. data/app/views/batch_select/_add_button.html.erb +3 -0
  18. data/app/views/batch_select/_check_all.html.erb +4 -0
  19. data/app/views/batch_select/_tools.html.erb +10 -0
  20. data/app/views/collections/_button_create_collection.html.erb +2 -0
  21. data/app/views/collections/_form.html.erb +36 -0
  22. data/app/views/collections/_form_for_select_collection.html.erb +13 -0
  23. data/app/views/collections/new.html.erb +3 -0
  24. data/app/views/collections/show.html.erb +9 -0
  25. data/config/jetty.yml +6 -0
  26. data/config/routes.rb +3 -0
  27. data/fedora_conf/conf/development/fedora.fcfg +946 -0
  28. data/fedora_conf/conf/test/fedora.fcfg +946 -0
  29. data/hydra-collections.gemspec +27 -0
  30. data/lib/hydra-collections.rb +7 -0
  31. data/lib/hydra/collection.rb +52 -0
  32. data/lib/hydra/collections.rb +12 -0
  33. data/lib/hydra/collections/accepts_batches.rb +55 -0
  34. data/lib/hydra/collections/collectible.rb +24 -0
  35. data/lib/hydra/collections/search_service.rb +58 -0
  36. data/lib/hydra/collections/version.rb +5 -0
  37. data/lib/hydra/collections_controller_behavior.rb +108 -0
  38. data/lib/hydra/datastreams/collection_rdf_datastream.rb +36 -0
  39. data/solr_conf/conf/schema.xml +372 -0
  40. data/solr_conf/conf/solrconfig.xml +163 -0
  41. data/solr_conf/solr.xml +35 -0
  42. data/spec/controllers/accepts_batches_spec.rb +72 -0
  43. data/spec/controllers/collections_controller_spec.rb +93 -0
  44. data/spec/factories.rb +18 -0
  45. data/spec/factories/.gitkeep +0 -0
  46. data/spec/factories/users.rb +31 -0
  47. data/spec/helpers/collections_helper_spec.rb +29 -0
  48. data/spec/lib/collectible_spec.rb +31 -0
  49. data/spec/lib/search_service_spec.rb +41 -0
  50. data/spec/models/collection_spec.rb +100 -0
  51. data/spec/spec_helper.rb +24 -0
  52. data/spec/support/Gemfile +19 -0
  53. data/spec/support/app/models/sample.rb +37 -0
  54. data/spec/support/app/models/solr_document.rb +5 -0
  55. data/spec/support/app/views/catalog/_document_header.html.erb +11 -0
  56. data/spec/support/app/views/catalog/_sort_and_per_page.html.erb +20 -0
  57. data/spec/support/config/initializers/hydra_config.rb +28 -0
  58. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  59. data/spec/support/lib/generators/test_app_generator.rb +54 -0
  60. data/spec/support/lib/tasks/rspec.rake +9 -0
  61. data/tasks/hydra-collections-dev.rake +68 -0
  62. data/tasks/jetty.rake +40 -0
  63. metadata +194 -0
@@ -0,0 +1,163 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <config>
3
+ <!-- NOTE: various comments and unused configuration possibilities have been purged
4
+ from this file. Please refer to http://wiki.apache.org/solr/SolrConfigXml,
5
+ as well as the default solrconfig file included with Solr -->
6
+
7
+ <abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
8
+
9
+ <luceneMatchVersion>LUCENE_40</luceneMatchVersion>
10
+
11
+ <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>
12
+
13
+ <!-- solr lib dirs -->
14
+ <lib dir="../lib/contrib/analysis-extras/lib" />
15
+ <lib dir="../lib/contrib/analysis-extras/lucene-libs" />
16
+
17
+ <dataDir>${solr.data.dir:}</dataDir>
18
+
19
+ <requestHandler name="search" class="solr.SearchHandler" default="true">
20
+ <!-- default values for query parameters can be specified, these
21
+ will be overridden by parameters in the request
22
+ -->
23
+ <lst name="defaults">
24
+ <str name="defType">edismax</str>
25
+ <str name="echoParams">explicit</str>
26
+ <str name="q.alt">*:*</str>
27
+ <str name="mm">2&lt;-1 5&lt;-2 6&lt;90%</str>
28
+ <int name="qs">1</int>
29
+ <int name="ps">2</int>
30
+ <float name="tie">0.01</float>
31
+ <!-- this qf and pf are used by default, if not otherwise specified by
32
+ client. The default blacklight_config will use these for the
33
+ "keywords" search. See the author_qf/author_pf, title_qf, etc
34
+ below, which the default blacklight_config will specify for
35
+ those searches. You may also be interested in:
36
+ http://wiki.apache.org/solr/LocalParams
37
+ -->
38
+ <str name="qf">
39
+ id
40
+ all_text_timv
41
+ active_fedora_model_ssi
42
+ object_type_si
43
+ </str>
44
+ <str name="pf">
45
+ all_text_timv^10
46
+ </str>
47
+
48
+ <str name="author_qf">
49
+ </str>
50
+ <str name="author_pf">
51
+ </str>
52
+ <str name="title_qf">
53
+ </str>
54
+ <str name="title_pf">
55
+ </str>
56
+ <str name="subject_qf">
57
+ </str>
58
+ <str name="subject_pf">
59
+ </str>
60
+
61
+ <str name="fl">
62
+ *,
63
+ score
64
+ </str>
65
+
66
+ <str name="facet">true</str>
67
+ <str name="facet.mincount">1</str>
68
+ <str name="facet.limit">10</str>
69
+ <str name="facet.field">active_fedora_model_ssi</str>
70
+ <str name="facet.field">object_type_si</str>
71
+
72
+ <str name="spellcheck">true</str>
73
+ <str name="spellcheck.dictionary">default</str>
74
+ <str name="spellcheck.onlyMorePopular">true</str>
75
+ <str name="spellcheck.extendedResults">true</str>
76
+ <str name="spellcheck.collate">false</str>
77
+ <str name="spellcheck.count">5</str>
78
+
79
+ </lst>
80
+ <arr name="last-components">
81
+ <str>spellcheck</str>
82
+ </arr>
83
+ </requestHandler>
84
+
85
+ <requestHandler name="permissions" class="solr.SearchHandler" >
86
+ <lst name="defaults">
87
+ <str name="facet">off</str>
88
+ <str name="echoParams">all</str>
89
+ <str name="rows">1</str>
90
+ <str name="q">{!raw f=id v=$id}</str> <!-- use id=666 instead of q=id:666 -->
91
+ <str name="fl">
92
+ id,
93
+ access_ssim,
94
+ discover_access_group_ssim,discover_access_person_ssim,
95
+ read_access_group_ssim,read_access_person_ssim,
96
+ edit_access_group_ssim,edit_access_person_ssim,
97
+ depositor_ti,
98
+ embargo_release_date_dtsi
99
+ inheritable_access_ssim,
100
+ inheritable_discover_access_group_ssim,inheritable_discover_access_person_ssim,
101
+ inheritable_read_access_group_ssim,inheritable_read_access_person_ssim,
102
+ inheritable_edit_access_group_ssim,inheritable_edit_access_person_ssim,
103
+ inheritable_embargo_release_date_dtsi
104
+ </str>
105
+ </lst>
106
+ </requestHandler>
107
+
108
+ <requestHandler name="standard" class="solr.SearchHandler">
109
+ <lst name="defaults">
110
+ <str name="echoParams">explicit</str>
111
+ <str name="defType">lucene</str>
112
+ </lst>
113
+ </requestHandler>
114
+
115
+ <!-- for requests to get a single document; use id=666 instead of q=id:666 -->
116
+ <requestHandler name="document" class="solr.SearchHandler" >
117
+ <lst name="defaults">
118
+ <str name="echoParams">all</str>
119
+ <str name="fl">*</str>
120
+ <str name="rows">1</str>
121
+ <str name="q">{!raw f=id v=$id}</str> <!-- use id=666 instead of q=id:666 -->
122
+ </lst>
123
+ </requestHandler>
124
+
125
+
126
+ <searchComponent name="spellcheck" class="solr.SpellCheckComponent">
127
+ <str name="queryAnalyzerFieldType">textSpell</str>
128
+ <!-- Multiple "Spell Checkers" can be declared and used by this component
129
+ (e.g. for title_spell field)
130
+ -->
131
+ <lst name="spellchecker">
132
+ <str name="name">default</str>
133
+ <str name="field">spell</str>
134
+ <str name="spellcheckIndexDir">./spell</str>
135
+ <str name="buildOnOptimize">true</str>
136
+ </lst>
137
+ </searchComponent>
138
+
139
+ <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" />
140
+
141
+ <requestDispatcher handleSelect="true" >
142
+ <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048" />
143
+ </requestDispatcher>
144
+
145
+ <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
146
+ <requestHandler name="/update" class="solr.UpdateRequestHandler" />
147
+ <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
148
+
149
+ <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
150
+ <lst name="invariants">
151
+ <str name="q">solrpingquery</str>
152
+ </lst>
153
+ <lst name="defaults">
154
+ <str name="echoParams">all</str>
155
+ </lst>
156
+ </requestHandler>
157
+
158
+ <!-- config for the admin interface -->
159
+ <admin>
160
+ <defaultQuery>search</defaultQuery>
161
+ </admin>
162
+
163
+ </config>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ -->
18
+
19
+ <!--
20
+ All (relative) paths are relative to the installation path
21
+
22
+ persistent: Save changes made via the API to this file
23
+ sharedLib: path to a lib directory that will be shared across all cores
24
+ -->
25
+ <solr persistent="false" sharedLib="lib">
26
+
27
+ <!--
28
+ adminPath: RequestHandler path to manage cores.
29
+ If 'null' (or absent), cores will not be manageable via REST
30
+ -->
31
+ <cores adminPath="/admin/cores" defaultCoreName="development">
32
+ <core name="development" instanceDir="development-core" />
33
+ <core name="test" instanceDir="test-core" />
34
+ </cores>
35
+ </solr>
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ class AcceptsBatchesController < ApplicationController
4
+ include Hydra::Collections::AcceptsBatches
5
+ end
6
+
7
+ describe AcceptsBatchesController do
8
+
9
+ describe "batch" do
10
+ it "should accept batch from parameters" do
11
+ controller.params["batch_document_ids"] = ["abc", "xyz"]
12
+ controller.batch.should == ["abc", "xyz"]
13
+ end
14
+ describe ":all" do
15
+ before do
16
+ doc1 = stub(:id=>123)
17
+ doc2 = stub(:id=>456)
18
+ Hydra::Collections::SearchService.any_instance.should_receive(:last_search_documents).and_return([doc1, doc2])
19
+ controller.stub(:current_user=>stub(:user_key=>'vanessa'))
20
+ end
21
+ it "should add every document in the current resultset to the batch" do
22
+ controller.params["batch_document_ids"] = "all"
23
+ controller.batch.should == [123, 456]
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "should allow filtering for access" do
29
+ before do
30
+ @allowed = [1,2,3]
31
+ @disallowed = [5,6,7]
32
+ subject.batch = @allowed + @disallowed
33
+ end
34
+ it "using filter_docs_with_access!" do
35
+ @allowed.each {|doc_id| subject.should_receive(:can?).with(:foo, doc_id).and_return(true)}
36
+ @disallowed.each {|doc_id| subject.should_receive(:can?).with(:foo, doc_id).and_return(false)}
37
+ subject.send(:filter_docs_with_access!, :foo)
38
+ subject.batch.should
39
+ flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
40
+ end
41
+ it "using filter_docs_with_edit_access!" do
42
+ @allowed.each {|doc_id| subject.should_receive(:can?).with(:edit, doc_id).and_return(true)}
43
+ @disallowed.each {|doc_id| subject.should_receive(:can?).with(:edit, doc_id).and_return(false)}
44
+ subject.send(:filter_docs_with_edit_access!)
45
+ subject.batch.should
46
+ flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
47
+ end
48
+ it "using filter_docs_with_read_access!" do
49
+ @allowed.each {|doc_id| subject.should_receive(:can?).with(:read, doc_id).and_return(true)}
50
+ @disallowed.each {|doc_id| subject.should_receive(:can?).with(:read, doc_id).and_return(false)}
51
+ subject.send(:filter_docs_with_read_access!)
52
+ subject.batch.should
53
+ flash[:notice].should == "You do not have permission to edit the documents: #{@disallowed.join(', ')}"
54
+ end
55
+ it "and be sassy if you didn't select anything" do
56
+ subject.batch = []
57
+ subject.send(:filter_docs_with_read_access!)
58
+ flash[:notice].should == "Select something first"
59
+ end
60
+
61
+ end
62
+
63
+ it "should check for empty" do
64
+ controller.batch = ["77826928", "94120425"]
65
+ controller.check_for_empty_batch?.should == false
66
+ controller.batch = []
67
+ controller.check_for_empty_batch?.should == true
68
+ end
69
+
70
+
71
+
72
+ end
@@ -0,0 +1,93 @@
1
+ # Copyright © 2012 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'spec_helper'
16
+
17
+ describe CollectionsController do
18
+ before do
19
+ controller.stub(:has_access?).and_return(true)
20
+
21
+ @user = FactoryGirl.find_or_create(:user)
22
+ sign_in @user
23
+ User.any_instance.stub(:groups).and_return([])
24
+ controller.stub(:clear_session_user) ## Don't clear out the authenticated session
25
+ end
26
+
27
+ describe '#new' do
28
+ it 'should assign @collection' do
29
+ get :new
30
+ expect(assigns(:collection)).to be_kind_of(Collection)
31
+ end
32
+ it "should pass through batch ids if provided and stick them in the form" do
33
+ pending "Couldn't get have_selector working before I had to move on. - MZ"
34
+ get :new, batch_document_ids: ["test2", "test88"]
35
+ response.should have_selector("p[class='foo']")
36
+ end
37
+ end
38
+
39
+ describe '#create' do
40
+ it "should create a Collection" do
41
+ old_count = Collection.count
42
+ post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
43
+ Collection.count.should == old_count+1
44
+ assigns[:collection].title.should == "My First Collection "
45
+ assigns[:collection].description.should == "The Description\r\n\r\nand more"
46
+ assigns[:collection].depositor.should == @user.user_key
47
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(assigns[:collection].id)
48
+ end
49
+ it "should add docs to collection if batch ids provided" do
50
+ @asset1 = ActiveFedora::Base.create!
51
+ @asset2 = ActiveFedora::Base.create!
52
+ post :create, batch_document_ids: [@asset1, @asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
53
+ assigns[:collection].members.should == [@asset1, @asset2]
54
+ end
55
+ end
56
+
57
+ describe "#update" do
58
+ before do
59
+ @collection = Collection.new
60
+ @collection.apply_depositor_metadata(@user.user_key)
61
+ @collection.save
62
+ @asset1 = ActiveFedora::Base.create!
63
+ @asset2 = ActiveFedora::Base.create!
64
+ @asset3 = ActiveFedora::Base.create!
65
+ controller.should_receive(:authorize!).and_return(true)
66
+ end
67
+ it "should update collection metadata" do
68
+ put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
69
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
70
+ assigns[:collection].title.should == "New Title"
71
+ assigns[:collection].description.should == "New Description"
72
+ end
73
+ it "should support adding batches of members" do
74
+ @collection.members << @asset1
75
+ @collection.save
76
+ put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
77
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
78
+ assigns[:collection].members.should == [@asset2, @asset3, @asset1]
79
+ end
80
+ it "should support removing batches of members" do
81
+ @collection.members = [@asset1, @asset2, @asset3]
82
+ @collection.save
83
+ put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset1, @asset3]
84
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
85
+ assigns[:collection].members.should == [@asset2]
86
+ end
87
+ it "should support setting members array" do
88
+ put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
89
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
90
+ assigns[:collection].members.should == [@asset1,@asset2, @asset3]
91
+ end
92
+ end
93
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Copyright © 2012 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ FactoryGirl.define do
16
+ factory :collection
17
+ end
18
+
File without changes
@@ -0,0 +1,31 @@
1
+ # Copyright © 2012 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ FactoryGirl.define do
16
+ factory :user, :class => User do |u|
17
+ email 'jilluser@example.com'
18
+ password 'password'
19
+ end
20
+
21
+ factory :archivist, :class => User do |u|
22
+ email 'archivist1@example.com'
23
+ password 'password'
24
+ end
25
+
26
+ factory :curator, :class => User do |u|
27
+ email 'curator1@example.com'
28
+ password 'password'
29
+ end
30
+ end
31
+
@@ -0,0 +1,29 @@
1
+ # Copyright © 2013 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'spec_helper'
16
+
17
+ include Hydra::Collections::Engine.routes.url_helpers
18
+
19
+ describe CollectionsHelper do
20
+ it "button_for_create_collection should create a button to the collections new path" do
21
+ html = button_for_create_collection
22
+ html.should have_selector("form[action='#{collections.new_collection_path}']")
23
+ html.should have_selector("input[type='submit']")
24
+ end
25
+ it "button_for_create_collection should create a button with my text" do
26
+ html = button_for_create_collection "Create My Button"
27
+ html.should have_selector("input[value='Create My Button']")
28
+ end
29
+ end