hydra-collections 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9f1837b7839dd05eb2e4491c0880601f1e9085d
4
- data.tar.gz: 0ae0566206139f10230859c5eac19a9056ee8f70
3
+ metadata.gz: a7149da28869268dc7f98e013bc2ff9bfc0f1d4f
4
+ data.tar.gz: fca470f837199a78ab3f0d7f72035cdd81af2bea
5
5
  SHA512:
6
- metadata.gz: 1798220406600445cf05d2e8fcaf94a3fa68fcc6eea05afebc31f79caddd1c85be19b2c1b81e0a3c1a72b997a98d242199d9ae548b4881900522210b22f1a06e
7
- data.tar.gz: 3a5c84107f842c2dea9b4ca6cfbd1efee7f7704d35854c6d3bf0b47653e28df81c3402b9f93ac8de82e6fd5026ebf7cdc331d98c070910fa8dff9681ed381660
6
+ metadata.gz: 57fd97a1cd596b776e1a3bce56ed6da35123638f2fbdaecb559c81f7dab2e78084e5a17da23e70827976965eb2b4fbb0e603f18d2545176ba2bc19d5baaf2d7d
7
+ data.tar.gz: f1983ca6f58409e4345a988dcae8149308265f260ad40c29f7754f4fd7105c53cea46486e23059e9963db53a9d36ee3cb5aaaf272b14a1fbe7f4e05197aef709
@@ -1,7 +1,7 @@
1
1
  $(function () {
2
2
 
3
3
  // change the action based which collection is selected
4
- $('input.submits-batches').on('click', function() {
4
+ $('input.updates-collection').on('click', function() {
5
5
 
6
6
  var form = $(this).closest("form");
7
7
  var collection_id = $(".collection-selector:checked")[0].value;
@@ -1,4 +1,4 @@
1
- # View Helpers for Hydra Batch Edit functionality
1
+ # View Helpers for Hydra Collections functionality
2
2
  module CollectionsHelper
3
3
 
4
4
 
@@ -21,6 +21,11 @@ module CollectionsHelper
21
21
  render partial:'/collections/button_remove_from_collection', locals:{label:label, document:document}
22
22
  end
23
23
 
24
+ def button_for_remove_selected_from_collection(collection, label = 'Remove From Collection')
25
+ render partial:'/collections/button_for_remove_selected_from_collection', locals:{collection:collection, label:label}
26
+ end
27
+
28
+
24
29
  # add hidden fields to a form for removing a single document from a collection
25
30
  def single_item_action_remove_form_fields(form, document)
26
31
  single_item_action_form_fields(form, document, "remove")
@@ -0,0 +1,34 @@
1
+ # View Helper methods for Hydra Collections in search results
2
+ module CollectionsSearchHelper
3
+
4
+ def collection_name(collection_pid)
5
+ # junk, pid = collection_pid.split('/')
6
+ escaped_pid = collection_pid.sub(':', '\:')
7
+ solr_opts = {params: {:q=>"id:#{escaped_pid}"}}
8
+ result = Blacklight.solr.get("select", solr_opts)
9
+ docs = result["response"]["docs"]
10
+
11
+ if docs
12
+ if docs.first[Solrizer.solr_name(:title, :displayable)]
13
+ res = docs.first[Solrizer.solr_name(:title, :displayable)]
14
+ res.kind_of?(Array) ? res.first : res
15
+ else
16
+ logger.warn "#{docs.first['id']} does not have a #{Solrizer.solr_name(:title, :displayable)} in solr"
17
+ docs.first['id']
18
+ end
19
+ else
20
+ 'Not Found'
21
+ end
22
+ end
23
+
24
+ def display_value_for_facet(facet, value)
25
+ if facet == Solrizer.solr_name(:collection, :facetable)
26
+ collection_name(value)
27
+ elsif ['release_date_desc_facet', 'last_update_date_desc_facet'].include? facet
28
+ Narm::DateFacet.decode(value)
29
+ else
30
+ value
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,8 @@
1
+ <%# button for removing a batch from a collection %>
2
+ <%# collection -- collection to be updated %>
3
+ <%# label -- button label %>
4
+ <%= form_for collection, url:collections.collection_path(collection.id), :method=>:put do |f| %>
5
+ <%= f.hidden_field :members, :value => "remove" %>
6
+ <%= f.submit label, :class => "btn btn-primary collection-remove-selected updates-collection submits-batches" %>
7
+ <% end %>
8
+
@@ -0,0 +1,26 @@
1
+ <%#
2
+ Copyright © 2012 The Pennsylvania State University
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ %>
16
+
17
+ <div style="float: right;" >
18
+ <%= form_for([collections, @collection] , :method => :get, :class => "well form-search") do |f| %>
19
+
20
+ <label class="accessible-hidden">Search Collection <%=@collection.title %></label>
21
+ <%= text_field_tag :cq, params[:cq], :class => "collection-query", :placeholder => "Search Collection", :size => '30', :type => "search", :id => "collection_search" %>
22
+ <%= hidden_field_tag :sort, params[:sort], :id => 'collection_sort' %>
23
+ <%= search_as_hidden_fields(:omit_keys => [:cq, :sort, :qt, :page]).html_safe %>
24
+ <button type="submit" class="btn btn-primary" id="collection_submit"><i class="icon-search"></i> Go</button>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,3 @@
1
+ <h1>Edit Collection</h1>
2
+
3
+ <%= render 'form' %>
@@ -1,4 +1,5 @@
1
1
  <h1><%=@collection.title%><h1>
2
2
  <h3><%=@collection.description%> </h3>
3
3
  <h3> <u>Contained Files </u></h3>
4
+ <%= render partial: 'search_form'%>
4
5
  <%= render partial:'document_list', locals:{documents: @member_docs} %>
@@ -6,22 +6,32 @@ module Hydra
6
6
  extend ActiveSupport::Concern
7
7
  extend ActiveSupport::Autoload
8
8
  autoload :Permissions
9
- include Hydra::ModelMethods # for access to apply_depositor_metadata
10
- include Hydra::ModelMixins::RightsMetadata
11
-
12
- included do
9
+ include Hydra::ModelMethods # for access to apply_depositor_metadata
10
+ include Hydra::ModelMixins::RightsMetadata
11
+ include Hydra::Collections::Collectible
12
+
13
+ included do
13
14
  has_metadata :name => "descMetadata", :type => CollectionRdfDatastream
14
15
  has_metadata :name => "properties", :type => Hydra::Datastream::Properties
15
16
  has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
16
17
 
17
- has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base"
18
+ has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base" , :after_remove => :remove_member
18
19
 
19
20
  delegate_to :properties, [:depositor], :unique => true
20
- delegate_to :descMetadata, [:date_uploaded, :date_modified,
21
- :title, :description], :unique => true
21
+
22
+ delegate_to :descMetadata, [:title, :date_uploaded, :date_modified,
23
+ :description], :unique => true
24
+ delegate_to :descMetadata, [:creator, :contributor, :based_near, :part_of,
25
+ :publisher, :date_created, :subject,:resource_type, :rights, :identifier,
26
+ :language, :tag, :related_url]
22
27
 
23
28
  before_create :set_date_uploaded
24
29
  before_save :set_date_modified
30
+
31
+ after_save :local_update_members
32
+ after_create :create_member_index
33
+
34
+ before_destroy :remove_all_members
25
35
  end
26
36
 
27
37
  # TODO: Move this override into ScholarSphere
@@ -36,7 +46,12 @@ module Hydra
36
46
  end
37
47
 
38
48
  def terms_for_display
39
- self.descMetadata.class.config.keys
49
+ self.descMetadata.class.config.keys.map{|v| v.to_sym}
50
+ end
51
+
52
+ def remove_member(member)
53
+ #member.collections.delete self if member.respond_to?(:collections)
54
+ member.reload.update_index
40
55
  end
41
56
 
42
57
  private
@@ -49,5 +64,34 @@ module Hydra
49
64
  self.date_modified = Date.today
50
65
  end
51
66
 
52
- end
67
+ # cause the members to index the relationship
68
+ def local_update_members
69
+ if self.respond_to?(:members)
70
+ self.members.each do |member|
71
+ member.reload.update_index
72
+ end
73
+ end
74
+ end
75
+
76
+ def create_member_index
77
+ self.members.each do |member|
78
+ member.to_solr # not sure why this to_solr is needed but it caused the removal and update to work
79
+ if member.respond_to?(:collections)
80
+ member.collections << self
81
+ member.update_index
82
+ member.collections << self if self.members.size == 1 #again who konw why but this allows on asset to be added
83
+ end
84
+ end
85
+ end
86
+
87
+ def remove_all_members
88
+ self.members.each do |member|
89
+ member.to_solr # not sure why this to_solr is needed but it caused the removal and update to work
90
+ member.collections.delete(self) if member.respond_to?(:collections)
91
+ member.update_index
92
+ end
93
+ end
94
+
95
+ end
96
+
53
97
  end
@@ -19,6 +19,7 @@ module Hydra::Collections::Collectible
19
19
  # end
20
20
  def index_collection_pids(solr_doc={})
21
21
  solr_doc[Solrizer.solr_name(:collection, :facetable)] = self.collection_ids
22
+ solr_doc[Solrizer.solr_name(:collection)] = self.collection_ids
22
23
  solr_doc
23
24
  end
24
25
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Collections
3
- VERSION = "0.0.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -44,6 +44,10 @@ module Hydra
44
44
  # actions: audit, index, create, new, edit, show, update, destroy, permissions, citation
45
45
  before_filter :authenticate_user!, :except => [:show]
46
46
  load_and_authorize_resource :except=>[:index]
47
+ before_filter :query_collection_members, only:[:show, :edit]
48
+
49
+ #This includes only the collection members in the search
50
+ self.solr_search_params_logic += [:include_collection_ids]
47
51
  end
48
52
 
49
53
  def new
@@ -51,19 +55,6 @@ module Hydra
51
55
  end
52
56
 
53
57
  def show
54
- logger.warn "Got to show"
55
-
56
- if @collection.member_ids.length > 0
57
- query = @collection.member_ids.join " OR "
58
-
59
- # run the solr query to find the collections
60
- (@response, @member_docs) = get_search_results(:q => query, :rows=>100)
61
- else
62
- #pretend we ran a solr query to get the colelctions since we do not need to really do it since there should be no results
63
- @member_docs = []
64
- @response = Blacklight::SolrResponse.new({'responseHeader'=>{'status'=>0,'QTime'=>5,'params'=>{'wt'=>'ruby','q'=>'xxzxas'}},'response'=>{'numFound'=>0,'start'=>0,'maxScore'=>0.0,'docs'=>[]},'facet_counts'=>{'facet_queries'=>{},'facet_fields'=>{'active_fedora_model_ssi'=>[],'object_type_si'=>[]},'facet_dates'=>{},'facet_ranges'=>{}},'spellcheck'=>{'suggestions'=>['correctlySpelled',false]}},"")
65
- end
66
-
67
58
  end
68
59
 
69
60
  def edit
@@ -147,30 +138,61 @@ module Hydra
147
138
 
148
139
  protected
149
140
 
141
+ # Queries Solr for members of the collection.
142
+ # Populates @response and @member_docs similar to Blacklight Catalog#index populating @response and @documents
143
+ def query_collection_members
144
+ if @collection.member_ids.length > 0
145
+ # run the solr query to find the collections
146
+ query = params[:cq]
147
+ (@response, @member_docs) = get_search_results(:q => query, :rows=>100)
148
+ else
149
+ #pretend we ran a solr query to get the colelctions since we do not need to really do it since there should be no results
150
+ @member_docs = []
151
+ @response = Blacklight::SolrResponse.new({'responseHeader'=>{'status'=>0,'QTime'=>5,'params'=>{'wt'=>'ruby','q'=>'xxzxas'}},'response'=>{'numFound'=>0,'start'=>0,'maxScore'=>0.0,'docs'=>[]},'facet_counts'=>{'facet_queries'=>{},'facet_fields'=>{'active_fedora_model_ssi'=>[],'object_type_si'=>[]},'facet_dates'=>{},'facet_ranges'=>{}},'spellcheck'=>{'suggestions'=>['correctlySpelled',false]}},"")
152
+ end
153
+ end
154
+
150
155
  def process_member_changes
151
156
  unless params[:collection].nil?
157
+ change_members = []
158
+ batch.each do |pid|
159
+ change_members << ActiveFedora::Base.find(pid, :cast=>true)
160
+ end
161
+
152
162
  case params[:collection][:members]
153
- when "add"
154
- batch.each do |pid|
155
- @collection.add_relationship(:has_collection_member, "info:fedora/#{pid}")
156
- end
157
- when "remove"
158
- batch.each do |pid|
159
- @collection.remove_relationship(:has_collection_member, "info:fedora/#{pid}")
160
- end
161
- when Array
162
- @collection.clear_relationship(:has_collection_member)
163
- params[:collection][:members].each do |pid|
164
- @collection.add_relationship(:has_collection_member, "info:fedora/#{pid}")
165
- end
163
+ when "add"
164
+ change_members.each do |member|
165
+ @collection.members << member
166
+ #@collection.add_relationship(:has_collection_member, "info:fedora/#{pid}")
167
+ end
168
+ when "remove"
169
+ change_members.each do |member|
170
+ @collection.members.delete(member)
171
+ #puts "removing pid"
172
+ #@collection.remove_relationship(:has_collection_member, "info:fedora/#{pid}")
173
+ end
174
+ when Array
175
+ @collection.members.replace(change_members)
176
+ #@collection.clear_relationship(:has_collection_member)
177
+ #params[:collection][:members].each do |pid|
178
+ # @collection.add_relationship(:has_collection_member, "info:fedora/#{pid}")
179
+ #end
166
180
  end
167
181
  end
168
- end
182
+ end
169
183
 
170
184
  # this is only needed until the version of balcklight that we are using this include it in it's solr helper
171
185
  def blacklight_solr
172
186
  Blacklight.solr
173
187
  end
174
-
188
+
189
+ # include filters into the query to only include the collection memebers
190
+ def include_collection_ids(solr_parameters, user_parameters)
191
+ solr_parameters[:fq] ||= []
192
+ if @collection.member_ids.length > 0
193
+ query = @collection.member_ids.map{|id| 'id:"'+id+'"'}.join " OR "
194
+ solr_parameters[:fq] << query
195
+ end
196
+ end
175
197
  end # module CollectionsControllerBehavior
176
198
  end # module Hydra
@@ -16,6 +16,13 @@ require 'active_fedora'
16
16
  module Hydra
17
17
  class CollectionRdfDatastream < ActiveFedora::NtriplesRDFDatastream
18
18
  map_predicates do |map|
19
+ map.part_of(:to => "isPartOf", :in => RDF::DC)
20
+ map.contributor(:in => RDF::DC) do |index|
21
+ index.as :stored_searchable, :facetable
22
+ end
23
+ map.creator(:in => RDF::DC) do |index|
24
+ index.as :stored_searchable, :facetable
25
+ end
19
26
  map.title(:in => RDF::DC) do |index|
20
27
  index.as :stored_searchable
21
28
  end
@@ -23,6 +30,12 @@ module Hydra
23
30
  index.type :text
24
31
  index.as :stored_searchable
25
32
  end
33
+ map.publisher(:in => RDF::DC) do |index|
34
+ index.as :stored_searchable, :facetable
35
+ end
36
+ map.date_created(:to => "created", :in => RDF::DC) do |index|
37
+ index.as :stored_searchable
38
+ end
26
39
  map.date_uploaded(:to => "dateSubmitted", :in => RDF::DC) do |index|
27
40
  index.type :date
28
41
  index.as :stored_sortable
@@ -31,6 +44,35 @@ module Hydra
31
44
  index.type :date
32
45
  index.as :stored_sortable
33
46
  end
47
+ map.subject(:in => RDF::DC) do |index|
48
+ index.as :stored_searchable, :facetable
49
+ end
50
+ map.language(:in => RDF::DC) do |index|
51
+ index.as :stored_searchable, :facetable
52
+ end
53
+ map.rights(:in => RDF::DC) do |index|
54
+ index.as :stored_searchable
55
+ end
56
+ map.resource_type(:to => "type", :in => RDF::DC) do |index|
57
+ index.as :stored_searchable, :facetable
58
+ end
59
+ map.identifier(:in => RDF::DC) do |index|
60
+ index.as :stored_searchable
61
+ end
62
+ map.based_near(:in => RDF::FOAF) do |index|
63
+ index.as :stored_searchable, :facetable
64
+ end
65
+ map.tag(:to => "relation", :in => RDF::DC) do |index|
66
+ index.as :stored_searchable, :facetable
67
+ end
68
+ map.related_url(:to => "seeAlso", :in => RDF::RDFS)
69
+ end
70
+ begin
71
+ LocalAuthority.register_vocabulary(self, "subject", "lc_subjects")
72
+ LocalAuthority.register_vocabulary(self, "language", "lexvo_languages")
73
+ LocalAuthority.register_vocabulary(self, "tag", "lc_genres")
74
+ rescue
75
+ puts "tables for vocabularies missing"
34
76
  end
35
77
  end
36
78
  end
@@ -40,6 +40,7 @@
40
40
  all_text_timv
41
41
  active_fedora_model_ssi
42
42
  object_type_si
43
+ label_tesim
43
44
  </str>
44
45
  <str name="pf">
45
46
  all_text_timv^10
@@ -15,6 +15,28 @@
15
15
  require 'spec_helper'
16
16
 
17
17
  describe CollectionsController do
18
+ before(:all) do
19
+ @user = FactoryGirl.find_or_create(:user)
20
+ class GenericFile < ActiveFedora::Base
21
+ include Hydra::Collections::Collectible
22
+
23
+
24
+ attr_accessor :title
25
+ def to_solr(solr_doc={})
26
+ super
27
+ solr_doc = index_collection_pids(solr_doc)
28
+ solr_doc["label_tesim"] = self.title
29
+ solr_doc
30
+ end
31
+ end
32
+ end
33
+ after(:all) do
34
+ @user.destroy
35
+ GenericFile.destroy_all
36
+ Collection.destroy_all
37
+ Object.send(:remove_const, :GenericFile)
38
+ end
39
+
18
40
  before do
19
41
  controller.stub(:has_access?).and_return(true)
20
42
 
@@ -56,17 +78,44 @@ describe CollectionsController do
56
78
  controller.should_receive(:after_create).and_call_original
57
79
  post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
58
80
  end
81
+
82
+ it "should add one doc to collection if batch ids provided and add the collection id to the document in the colledction" do
83
+ @asset1 = GenericFile.create!
84
+ post :create, batch_document_ids: [@asset1], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
85
+ assigns[:collection].members.should == [@asset1]
86
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
87
+ asset_results["response"]["numFound"].should == 1
88
+ doc = asset_results["response"]["docs"].first
89
+ doc["id"].should == @asset1.pid
90
+ afterupdate = GenericFile.find(@asset1.pid)
91
+ puts doc
92
+ doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
93
+ end
94
+ it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
95
+ @asset1 = GenericFile.create!
96
+ @asset2 = GenericFile.create!
97
+ post :create, batch_document_ids: [@asset1,@asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
98
+ assigns[:collection].members.should == [@asset1,@asset2]
99
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
100
+ asset_results["response"]["numFound"].should == 1
101
+ doc = asset_results["response"]["docs"].first
102
+ doc["id"].should == @asset1.pid
103
+ afterupdate = GenericFile.find(@asset1.pid)
104
+ puts doc
105
+ doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
106
+ end
59
107
  end
60
-
108
+
61
109
  describe "#update" do
62
110
  before do
63
111
  @collection = Collection.new
64
112
  @collection.apply_depositor_metadata(@user.user_key)
65
113
  @collection.save
66
- @asset1 = ActiveFedora::Base.create!
67
- @asset2 = ActiveFedora::Base.create!
68
- @asset3 = ActiveFedora::Base.create!
69
- controller.should_receive(:authorize!).and_return(true)
114
+ @asset1 = GenericFile.create!
115
+ @asset2 = GenericFile.create!
116
+ @asset3 = GenericFile.create!
117
+ controller.stub(:authorize!).and_return(true)
118
+ controller.should_receive(:authorize!).at_least(:once)
70
119
  end
71
120
  it "should update collection metadata" do
72
121
  put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
@@ -96,8 +145,34 @@ describe CollectionsController do
96
145
  it "should support setting members array" do
97
146
  put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
98
147
  response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
99
- assigns[:collection].members.should == [@asset1,@asset2, @asset3]
148
+ assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
100
149
  end
150
+ it "should support setting members array" do
151
+ put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3, @asset1]
152
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
153
+ assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
154
+ end
155
+ it "should set collection on members" do
156
+ @collection.members << @asset1
157
+ @collection.save
158
+ put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
159
+ response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
160
+ assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
161
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
162
+ asset_results["response"]["numFound"].should == 1
163
+ doc = asset_results["response"]["docs"].first
164
+ doc["id"].should == @asset2.pid
165
+ afterupdate = GenericFile.find(@asset2.pid)
166
+ doc[Solrizer.solr_name(:collection)].should == afterupdate.to_solr[Solrizer.solr_name(:collection)]
167
+ put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids:[@asset2]
168
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
169
+ asset_results["response"]["numFound"].should == 1
170
+ doc = asset_results["response"]["docs"].first
171
+ doc["id"].should == @asset2.pid
172
+ afterupdate = GenericFile.find(@asset2.pid)
173
+ doc[Solrizer.solr_name(:collection)].should be_nil
174
+ end
175
+
101
176
  end
102
177
 
103
178
  describe "#destroy" do
@@ -113,14 +188,87 @@ describe CollectionsController do
113
188
  response.should redirect_to Rails.application.routes.url_helpers.catalog_index_path
114
189
  flash[:notice].should == "Collection was successfully deleted."
115
190
  end
116
- it "should call after_destroy" do
117
- controller.should_receive(:after_destroy).and_call_original
191
+ it "should after_destroy" do
192
+ controller.should_receive(:after_destroy).and_call_original
118
193
  delete :destroy, id: @collection.id
119
194
  end
195
+ it "should call update members" do
196
+ @asset1 = GenericFile.create!
197
+ @collection.members << @asset1
198
+ @collection.save
199
+ @asset1 = @asset1.reload
200
+ @asset1.update_index
201
+ @asset1.collections.should == [@collection]
202
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
203
+ asset_results["response"]["numFound"].should == 1
204
+ doc = asset_results["response"]["docs"].first
205
+ doc[Solrizer.solr_name(:collection)].should == [@collection.pid]
206
+
207
+ delete :destroy, id: @collection.id
208
+ @asset1.reload.collections.should == []
209
+ asset_results = Blacklight.solr.get "select", params:{fq:["id:\"#{@asset1.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
210
+ asset_results["response"]["numFound"].should == 1
211
+ doc = asset_results["response"]["docs"].first
212
+ doc[Solrizer.solr_name(:collection)].should be_nil
213
+ @asset1.destroy
214
+ end
120
215
  end
121
216
  it "should not delete an invalid collection" do
122
217
  expect {delete :destroy, id: 'zz:-1'}.to raise_error
123
218
  end
124
219
  end
125
220
 
221
+ describe "#show" do
222
+ before do
223
+ @asset1 = GenericFile.create!(title: "First of the Assets")
224
+ @asset2 = GenericFile.create!(title: "Second of the Assets")
225
+ @asset3 = GenericFile.create!(title: "Third of the Assets")
226
+ @collection = Collection.new
227
+ @collection.title = "My collection"
228
+ @collection.apply_depositor_metadata(@user.user_key)
229
+ @collection.members = [@asset1,@asset2,@asset3]
230
+ @collection.save
231
+ controller.should_receive(:authorize!).and_return(true)
232
+ controller.stub(:apply_gated_search)
233
+ end
234
+ it "should show the collections" do
235
+ get :show, id: @collection.id
236
+ assigns[:collection].title.should == @collection.title
237
+ ids = assigns[:member_docs].map {|d| d.id}
238
+ ids.should include @asset1.pid
239
+ ids.should include @asset2.pid
240
+ ids.should include @asset3.pid
241
+ end
242
+ it "should show only the collections assets" do
243
+ @asset4 = GenericFile.create!(title: "#{@asset1.id}")
244
+ get :show, id: @collection.id
245
+ assigns[:collection].title.should == @collection.title
246
+ ids = assigns[:member_docs].map {|d| d.id}
247
+ ids.should include @asset1.pid
248
+ ids.should include @asset2.pid
249
+ ids.should include @asset3.pid
250
+ ids.should_not include @asset4.pid
251
+ end
252
+ it "should query the collections" do
253
+ get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
254
+ assigns[:collection].title.should == @collection.title
255
+ ids = assigns[:member_docs].map {|d| d.id}
256
+ ids.should include @asset1.pid
257
+ ids.should_not include @asset2.pid
258
+ ids.should_not include @asset3.pid
259
+ end
260
+ it "should query the collections and show only the collection assets" do
261
+ @asset4 = GenericFile.create!(title: "#{@asset1.id} #{@asset1.title}")
262
+ @asset5 = GenericFile.create!(title: "#{@asset1.title}")
263
+ get :show, id: @collection.id, cq:"\"#{@asset1.title}\""
264
+ assigns[:collection].title.should == @collection.title
265
+ ids = assigns[:member_docs].map {|d| d.id}
266
+ ids.should include @asset1.pid
267
+ ids.should_not include @asset2.pid
268
+ ids.should_not include @asset3.pid
269
+ ids.should_not include @asset4.pid
270
+ ids.should_not include @asset5.pid
271
+ end
272
+ end
273
+
126
274
  end
@@ -45,4 +45,22 @@ describe "button_for_delete_collection" do
45
45
  html.should have_selector("input[value='Delete My Button']")
46
46
  end
47
47
  end
48
+ describe "button_for_remove_selected_from_collection" do
49
+ before (:all) do
50
+ @collection = Collection.create title:"Test Public"
51
+ end
52
+ after (:all) do
53
+ @collection.delete
54
+ end
55
+ it " should create a button to the collections delete path" do
56
+ html = button_for_remove_selected_from_collection @collection
57
+ html.should have_selector("form[action='#{collections.collection_path(@collection.pid)}']")
58
+ html.should have_selector("input[type='submit']")
59
+ end
60
+ it "should create a button with my text" do
61
+ html = button_for_remove_selected_from_collection @collection, "Remove My Button"
62
+ html.should have_selector("input[value='Remove My Button']")
63
+ end
64
+ end
65
+
48
66
  end
@@ -0,0 +1,43 @@
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
+ describe CollectionsSearchHelper do
18
+ before do
19
+ @collection = Collection.create(title: "Title of Collection 1")
20
+ class CollectionWithMetadata < ActiveFedora::Base
21
+ include Hydra::Collection
22
+ def to_solr(solr_doc={})
23
+ super
24
+ solr_doc[Solrizer.solr_name(:title, :displayable)] = self.descMetadata.title
25
+ solr_doc
26
+ end
27
+ end
28
+ @collection_with_metadata = CollectionWithMetadata.create(title: "Title of Collection 2")
29
+ end
30
+ describe "collection_name" do
31
+ it "should return the pid if no title available" do
32
+ collection_name(@collection.pid).should == @collection.pid
33
+ end
34
+ it "should return the title value associated with the given pid" do
35
+ collection_name(@collection_with_metadata.pid).should == "Title of Collection 2"
36
+ end
37
+ end
38
+ describe "display_value_for_facet" do
39
+ it "should look up collection_name when displaying collection facet" do
40
+ display_value_for_facet(Solrizer.solr_name(:collection, :facetable), @collection_with_metadata.pid).should == "Title of Collection 2"
41
+ end
42
+ end
43
+ end
@@ -16,7 +16,7 @@ describe Hydra::Collections::Collectible do
16
16
  @collection1.save
17
17
  @collectible.collections << @collection2
18
18
  reloaded = CollectibleThing.find(@collectible.pid)
19
- @collection2.members.should == [@collectible]
19
+ @collection2.reload.members.should == [@collectible]
20
20
  reloaded.collections.should == [@collection1, @collection2]
21
21
  end
22
22
  end
@@ -85,10 +85,10 @@ describe Collection do
85
85
  Collection.find(@collection.pid).description.should == @collection.description
86
86
  end
87
87
  it "should have the expected display terms" do
88
- @collection.terms_for_display.should == [:title, :description, :date_uploaded, :date_modified]
88
+ @collection.terms_for_display.should == [:part_of, :contributor, :creator, :title, :description, :publisher, :date_created, :date_uploaded, :date_modified, :subject, :language, :rights, :resource_type, :identifier, :based_near, :tag, :related_url]
89
89
  end
90
90
  it "should have the expected edit terms" do
91
- @collection.terms_for_editing.should == [:title,:description]
91
+ @collection.terms_for_editing.should == [:part_of, :contributor, :creator, :title, :description, :publisher, :date_created, :subject, :language, :rights, :resource_type, :identifier, :based_near, :tag, :related_url]
92
92
  end
93
93
  it "should not delete member files when deleted" do
94
94
  @collection.members = [@gf1, @gf2]
@@ -31,10 +31,6 @@ class TestAppGenerator < Rails::Generators::Base
31
31
  copy_file "lib/tasks/rspec.rake"
32
32
  end
33
33
 
34
- def copy_hydra_config
35
- copy_file "config/initializers/hydra_config.rb"
36
- end
37
-
38
34
  def delete_generated_noise
39
35
  remove_file("public/index.html")
40
36
  remove_file("spec/models/user_spec.rb")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carolyn Cole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-23 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blacklight
@@ -102,6 +102,7 @@ files:
102
102
  - app/controllers/collections_controller.rb
103
103
  - app/helpers/batch_select_helper.rb
104
104
  - app/helpers/collections_helper.rb
105
+ - app/helpers/collections_search_helper.rb
105
106
  - app/models/collection.rb
106
107
  - app/models/solr_document.rb
107
108
  - app/views/batch_select/_add_button.html.erb
@@ -109,13 +110,16 @@ files:
109
110
  - app/views/batch_select/_tools.html.erb
110
111
  - app/views/collections/_button_create_collection.html.erb
111
112
  - app/views/collections/_button_for_delete_collection.html.erb
113
+ - app/views/collections/_button_for_remove_selected_from_collection.html.erb
112
114
  - app/views/collections/_button_for_update_collection.html.erb
113
115
  - app/views/collections/_button_remove_from_collection.html.erb
114
116
  - app/views/collections/_document_header.html.erb
115
117
  - app/views/collections/_document_list.html.erb
116
118
  - app/views/collections/_form.html.erb
117
119
  - app/views/collections/_form_for_select_collection.html.erb
120
+ - app/views/collections/_search_form.html.erb
118
121
  - app/views/collections/_single_item_action_fields.html.erb
122
+ - app/views/collections/edit.html.erb
119
123
  - app/views/collections/new.html.erb
120
124
  - app/views/collections/show.html.erb
121
125
  - config/jetty.yml
@@ -145,6 +149,7 @@ files:
145
149
  - spec/factories/.gitkeep
146
150
  - spec/factories/users.rb
147
151
  - spec/helpers/collections_helper_spec.rb
152
+ - spec/helpers/collections_search_helper_spec.rb
148
153
  - spec/lib/collectible_spec.rb
149
154
  - spec/lib/search_service_spec.rb
150
155
  - spec/models/collection_spec.rb
@@ -155,7 +160,6 @@ files:
155
160
  - spec/support/app/views/catalog/_document_header.html.erb
156
161
  - spec/support/app/views/catalog/_index_collection.html.erb
157
162
  - spec/support/app/views/catalog/_sort_and_per_page.html.erb
158
- - spec/support/config/initializers/hydra_config.rb
159
163
  - spec/support/db/migrate/20111101221803_create_searches.rb
160
164
  - spec/support/lib/generators/test_app_generator.rb
161
165
  - spec/support/lib/tasks/rspec.rake
@@ -194,6 +198,7 @@ test_files:
194
198
  - spec/factories/.gitkeep
195
199
  - spec/factories/users.rb
196
200
  - spec/helpers/collections_helper_spec.rb
201
+ - spec/helpers/collections_search_helper_spec.rb
197
202
  - spec/lib/collectible_spec.rb
198
203
  - spec/lib/search_service_spec.rb
199
204
  - spec/models/collection_spec.rb
@@ -204,7 +209,6 @@ test_files:
204
209
  - spec/support/app/views/catalog/_document_header.html.erb
205
210
  - spec/support/app/views/catalog/_index_collection.html.erb
206
211
  - spec/support/app/views/catalog/_sort_and_per_page.html.erb
207
- - spec/support/config/initializers/hydra_config.rb
208
212
  - spec/support/db/migrate/20111101221803_create_searches.rb
209
213
  - spec/support/lib/generators/test_app_generator.rb
210
214
  - spec/support/lib/tasks/rspec.rake
@@ -1,28 +0,0 @@
1
- # The following lines determine which user attributes your hydrangea app will use
2
- # This configuration allows you to use the out of the box ActiveRecord associations between users and user_attributes
3
- # It also allows you to specify your own user attributes
4
- # The easiest way to override these methods would be to create your own module to include in User
5
- # For example you could create a module for your local LDAP instance called MyLocalLDAPUserAttributes:
6
- # User.send(:include, MyLocalLDAPAttributes)
7
- # As long as your module includes methods for full_name, affiliation, and photo the personalization_helper should function correctly
8
- #
9
-
10
- # windows doesn't properly require hydra-head (from the gemfile), so we need to require it explicitly here:
11
- require 'hydra/head' unless defined? Hydra
12
-
13
- if Hydra.respond_to?(:configure)
14
- Hydra.configure(:shared) do |config|
15
- # This specifies the solr field names of permissions-related fields.
16
- # You only need to change these values if you've indexed permissions by some means other than the Hydra's built-in tooling.
17
- # If you change these, you must also update the permissions request handler in your solrconfig.xml to return those values
18
- indexer = Solrizer::Descriptor.new(:string, :stored, :indexed, :multivalued)
19
- config[:permissions] = {
20
- :discover => {:group =>ActiveFedora::SolrService.solr_name("discover_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("discover_access_person", indexer)},
21
- :read => {:group =>ActiveFedora::SolrService.solr_name("read_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("read_access_person", indexer)},
22
- :edit => {:group =>ActiveFedora::SolrService.solr_name("edit_access_group", indexer), :individual=>ActiveFedora::SolrService.solr_name("edit_access_person", indexer)},
23
- :owner => ActiveFedora::SolrService.solr_name("depositor", indexer),
24
- :embargo_release_date => ActiveFedora::SolrService.solr_name("embargo_release_date", Solrizer::Descriptor.new(:date, :stored, :indexed))
25
- }
26
-
27
- end
28
- end