hydra-collections 3.0.0.beta3 → 4.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/README.md +3 -3
- data/{lib → app/controllers/concerns}/hydra/collections/selects_collections.rb +3 -8
- data/app/controllers/concerns/hydra/collections_controller_behavior.rb +19 -20
- data/app/helpers/collections_search_helper.rb +2 -1
- data/app/models/concerns/hydra/collection.rb +82 -18
- data/app/views/collections/_search_form.html.erb +0 -16
- data/hydra-collections.gemspec +3 -2
- data/lib/hydra/collections/accepts_batches.rb +5 -5
- data/lib/hydra/collections/collectible.rb +15 -8
- data/lib/hydra/collections/solr_document_behavior.rb +0 -15
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +5 -19
- data/spec/controllers/collections_controller_spec.rb +125 -154
- data/spec/controllers/other_collections_controller_spec.rb +13 -15
- data/spec/controllers/selects_collections_spec.rb +39 -48
- data/spec/factories.rb +0 -14
- data/spec/factories/users.rb +0 -14
- data/spec/helpers/collections_helper_spec.rb +14 -16
- data/spec/helpers/collections_search_helper_spec.rb +4 -2
- data/spec/lib/collectible_spec.rb +7 -7
- data/spec/models/collection_spec.rb +78 -133
- data/spec/spec_helper.rb +12 -1
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -0
- data/tasks/hydra-collections-dev.rake +3 -1
- metadata +20 -8
- data/app/models/datastreams/hydra/collection_rdf_datastream.rb +0 -54
- data/spec/factories/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c7e16cee43a7fdaf1ef7f112ae42f8eb1ddb684
|
4
|
+
data.tar.gz: d99f69ce5988cf2023a811344fa461bf3b859e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe6f6ae745110afbf7fa17e8139a075124421e9f39796b79eb6ede511e80cfdd75238469262be83dd929b941f6d43f66f03e1af5dc23096ce9d53b7e9a2cc533
|
7
|
+
data.tar.gz: b1a372ad7bfa3419d0fddc0350e11b6966b41dac9a30e53e996b05f494164af66e79afc06fc2325181889aa1477ed5945938b8d6976a2ad976e0d6e8c1939af6
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
### Make your Models Collectible
|
37
37
|
|
38
|
-
Add `include Hydra::Collections::Collectible` to the models for anything that you want to be able to add to collections (ie. GenericFile, Book, Article, etc.), then add `
|
38
|
+
Add `include Hydra::Collections::Collectible` to the models for anything that you want to be able to add to collections (ie. GenericFile, Book, Article, etc.), then add `index_collection_ids` to the solrization logic (ie. put it in to_solr)
|
39
39
|
|
40
40
|
Example:
|
41
41
|
```ruby
|
@@ -44,13 +44,13 @@ class GenericFile < ActiveFedora::Base
|
|
44
44
|
...
|
45
45
|
def to_solr(solr_doc={}, opts={})
|
46
46
|
super(solr_doc, opts)
|
47
|
-
|
47
|
+
index_collection_ids(solr_doc)
|
48
48
|
return solr_doc
|
49
49
|
end
|
50
50
|
end
|
51
51
|
```
|
52
52
|
|
53
|
-
Any items that include the `Hydra::Collections::Collectible` module can look up which collections they belong to via `.collections`. The `
|
53
|
+
Any items that include the `Hydra::Collections::Collectible` module can look up which collections they belong to via `.collections`. The `index_collection_ids` puts the ids of all associated collections into the `collection` facet.
|
54
54
|
|
55
55
|
### Make the Collection show as a facet in your CatalogController
|
56
56
|
|
@@ -1,12 +1,8 @@
|
|
1
|
-
require 'blacklight/catalog'
|
2
|
-
|
3
1
|
module Hydra::Collections::SelectsCollections
|
4
|
-
|
5
|
-
extend ActiveSupport::Autoload
|
6
2
|
extend ActiveSupport::Concern
|
7
3
|
|
8
4
|
def access_levels
|
9
|
-
{read:[:read
|
5
|
+
{ read: [:read, :edit], edit: [:edit] }
|
10
6
|
end
|
11
7
|
|
12
8
|
# add one of the following methods as a before filter on any page that shows the form_for_select_collection
|
@@ -32,11 +28,10 @@ module Hydra::Collections::SelectsCollections
|
|
32
28
|
|
33
29
|
# temporarily set solr_search_params_logic to collection_search_params_logic
|
34
30
|
orig_solr_search_params_logic = self.class.solr_search_params_logic
|
35
|
-
# self.class.solr_search_params_logic += [:add_collection_filter]
|
36
31
|
self.class.solr_search_params_logic = collection_search_params_logic
|
37
32
|
logger.debug "Collection Search logic: "+ self.class.solr_search_params_logic.inspect
|
38
33
|
# run the solr query to find the collections
|
39
|
-
(resp, doc_list) = get_search_results({:
|
34
|
+
(resp, doc_list) = get_search_results({q: ''}, {rows: 100})
|
40
35
|
|
41
36
|
#reset to original solr logic
|
42
37
|
self.class.send(:define_method, "discovery_permissions") { original_permissions } unless access_level.blank?
|
@@ -48,7 +43,7 @@ module Hydra::Collections::SelectsCollections
|
|
48
43
|
|
49
44
|
def add_collection_filter(solr_parameters, user_parameters)
|
50
45
|
solr_parameters[:fq] ||= []
|
51
|
-
solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}
|
46
|
+
solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}:Collection"
|
52
47
|
end
|
53
48
|
|
54
49
|
# Defines which solr_search_params_logic should be used when searching for Collections
|
@@ -14,7 +14,7 @@ module Hydra
|
|
14
14
|
|
15
15
|
# Catch permission errors
|
16
16
|
rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
|
17
|
-
if
|
17
|
+
if exception.action == :edit
|
18
18
|
redirect_to(collections.url_for({:action=>'show'}), :alert => "You do not have sufficient privileges to edit this document")
|
19
19
|
elsif current_user and current_user.persisted?
|
20
20
|
redirect_to root_url, :alert => exception.message
|
@@ -46,18 +46,19 @@ module Hydra
|
|
46
46
|
|
47
47
|
def after_create
|
48
48
|
respond_to do |format|
|
49
|
+
ActiveFedora::SolrService.instance.conn.commit
|
49
50
|
format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully created.' }
|
50
51
|
format.json { render json: @collection, status: :created, location: @collection }
|
51
52
|
end
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
def after_create_error
|
55
56
|
respond_to do |format|
|
56
57
|
format.html { render action: "new" }
|
57
58
|
format.json { render json: @collection.errors, status: :unprocessable_entity }
|
58
59
|
end
|
59
60
|
end
|
60
|
-
|
61
|
+
|
61
62
|
def create
|
62
63
|
@collection.apply_depositor_metadata(current_user.user_key)
|
63
64
|
add_members_to_collection unless batch.empty?
|
@@ -67,8 +68,8 @@ module Hydra
|
|
67
68
|
after_create_error
|
68
69
|
end
|
69
70
|
end
|
70
|
-
|
71
|
-
def after_update
|
71
|
+
|
72
|
+
def after_update
|
72
73
|
if flash[:notice].nil?
|
73
74
|
flash[:notice] = 'Collection was successfully updated.'
|
74
75
|
end
|
@@ -77,14 +78,14 @@ module Hydra
|
|
77
78
|
format.json { render json: @collection, status: :updated, location: @collection }
|
78
79
|
end
|
79
80
|
end
|
80
|
-
|
81
|
+
|
81
82
|
def after_update_error
|
82
83
|
respond_to do |format|
|
83
84
|
format.html { render action: collections.edit_collection_path(@collection) }
|
84
85
|
format.json { render json: @collection.errors, status: :unprocessable_entity }
|
85
86
|
end
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
def update
|
89
90
|
process_member_changes
|
90
91
|
@collection.update_attributes(params[:collection].except(:members))
|
@@ -94,21 +95,21 @@ module Hydra
|
|
94
95
|
after_update_error
|
95
96
|
end
|
96
97
|
end
|
97
|
-
|
98
|
+
|
98
99
|
def after_destroy (id)
|
99
100
|
respond_to do |format|
|
100
101
|
format.html { redirect_to catalog_index_path, notice: 'Collection was successfully deleted.' }
|
101
102
|
format.json { render json: {id:id}, status: :destroyed, location: @collection }
|
102
|
-
end
|
103
|
+
end
|
103
104
|
end
|
104
105
|
|
105
106
|
def after_destroy_error (id)
|
106
107
|
respond_to do |format|
|
107
108
|
format.html { redirect_to catalog_index_path, notice: 'Collection could not be deleted.' }
|
108
109
|
format.json { render json: {id:id}, status: :destroy_error, location: @collection }
|
109
|
-
end
|
110
|
+
end
|
110
111
|
end
|
111
|
-
|
112
|
+
|
112
113
|
def destroy
|
113
114
|
if @collection.destroy
|
114
115
|
after_destroy(params[:id])
|
@@ -116,16 +117,16 @@ module Hydra
|
|
116
117
|
after_destroy_error(params[:id])
|
117
118
|
end
|
118
119
|
end
|
119
|
-
|
120
|
+
|
120
121
|
protected
|
121
122
|
|
122
|
-
# Queries Solr for members of the collection.
|
123
|
+
# Queries Solr for members of the collection.
|
123
124
|
# Populates @response and @member_docs similar to Blacklight Catalog#index populating @response and @documents
|
124
125
|
def query_collection_members
|
125
126
|
query = params[:cq]
|
126
127
|
|
127
128
|
#default the rows to 100 if not specified then merge in the user parameters and the attach the collection query
|
128
|
-
solr_params = {rows:100}.merge(params.symbolize_keys).merge(
|
129
|
+
solr_params = { rows: 100 }.merge(params.symbolize_keys).merge(q: query)
|
129
130
|
|
130
131
|
# run the solr query to find the collections
|
131
132
|
(@response, @member_docs) = get_search_results(solr_params)
|
@@ -142,17 +143,15 @@ module Hydra
|
|
142
143
|
|
143
144
|
def add_members_to_collection collection = nil
|
144
145
|
collection ||= @collection
|
145
|
-
collection.members(true)
|
146
146
|
collection.member_ids = batch.concat(collection.member_ids)
|
147
147
|
end
|
148
148
|
|
149
149
|
def remove_members_from_collection
|
150
|
-
@collection.members(
|
151
|
-
@collection.member_ids = (@collection.member_ids - batch)
|
150
|
+
@collection.members.delete(batch.map { |pid| ActiveFedora::Base.find(pid) })
|
152
151
|
end
|
153
152
|
|
154
153
|
def assign_batch_to_collection
|
155
|
-
@collection.members(true)
|
154
|
+
@collection.members(true) #Force the members to get cached before (maybe) removing some of them
|
156
155
|
@collection.member_ids = batch
|
157
156
|
end
|
158
157
|
|
@@ -166,11 +165,11 @@ module Hydra
|
|
166
165
|
flash[:error] = "An error occured. Files were not moved to #{destination_collection.title} Collection."
|
167
166
|
end
|
168
167
|
end
|
169
|
-
|
168
|
+
|
170
169
|
# include filters into the query to only include the collection memebers
|
171
170
|
def include_collection_ids(solr_parameters, user_parameters)
|
172
171
|
solr_parameters[:fq] ||= []
|
173
|
-
solr_parameters[:fq] << Solrizer.solr_name(:collection)+':"'+@collection.id+'"'
|
172
|
+
solr_parameters[:fq] << Solrizer.solr_name(:collection, :facetable)+':"'+@collection.id+'"'
|
174
173
|
end
|
175
174
|
end # module CollectionsControllerBehavior
|
176
175
|
end # module Hydra
|
@@ -4,7 +4,8 @@ module CollectionsSearchHelper
|
|
4
4
|
# @param [String] collection_pid the pid of a collection
|
5
5
|
# @return [String] the title of the collection if available, otherwise its pid
|
6
6
|
def collection_name(collection_pid)
|
7
|
-
|
7
|
+
#TODO this can be loaded from solr
|
8
|
+
Collection.find(collection_pid).title || collection_pid
|
8
9
|
end
|
9
10
|
|
10
11
|
end
|
@@ -7,26 +7,87 @@ module Hydra
|
|
7
7
|
include Hydra::Collections::Collectible
|
8
8
|
|
9
9
|
included do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
has_and_belongs_to_many :members, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base" , after_remove: :update_member
|
11
|
+
|
12
|
+
property :depositor, predicate: RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt")
|
13
|
+
|
14
|
+
property :part_of, predicate: RDF::DC.isPartOf
|
15
|
+
property :contributor, predicate: RDF::DC.contributor do |index|
|
16
|
+
index.as :stored_searchable, :facetable
|
17
|
+
end
|
18
|
+
property :creator, predicate: RDF::DC.creator do |index|
|
19
|
+
index.as :stored_searchable, :facetable
|
20
|
+
end
|
21
|
+
property :title, predicate: RDF::DC.title do |index|
|
22
|
+
index.as :stored_searchable
|
23
|
+
end
|
24
|
+
property :description, predicate: RDF::DC.description do |index|
|
25
|
+
index.type :text
|
26
|
+
index.as :stored_searchable
|
27
|
+
end
|
28
|
+
property :publisher, predicate: RDF::DC.publisher do |index|
|
29
|
+
index.as :stored_searchable, :facetable
|
30
|
+
end
|
31
|
+
property :date_created, predicate: RDF::DC.created do |index|
|
32
|
+
index.as :stored_searchable
|
33
|
+
end
|
34
|
+
property :date_uploaded, predicate: RDF::DC.dateSubmitted do |index|
|
35
|
+
index.type :date
|
36
|
+
index.as :stored_sortable
|
37
|
+
end
|
38
|
+
property :date_modified, predicate: RDF::DC.modified do |index|
|
39
|
+
index.type :date
|
40
|
+
index.as :stored_sortable
|
41
|
+
end
|
42
|
+
property :subject, predicate: RDF::DC.subject do |index|
|
43
|
+
index.as :stored_searchable, :facetable
|
44
|
+
end
|
45
|
+
property :language, predicate: RDF::DC.language do |index|
|
46
|
+
index.as :stored_searchable, :facetable
|
47
|
+
end
|
48
|
+
property :rights, predicate: RDF::DC.rights do |index|
|
49
|
+
index.as :stored_searchable
|
50
|
+
end
|
51
|
+
property :resource_type, predicate: RDF::DC.type do |index|
|
52
|
+
index.as :stored_searchable, :facetable
|
53
|
+
end
|
54
|
+
property :identifier, predicate: RDF::DC.identifier do |index|
|
55
|
+
index.as :stored_searchable
|
56
|
+
end
|
57
|
+
property :based_near, predicate: RDF::FOAF.based_near do |index|
|
58
|
+
index.as :stored_searchable, :facetable
|
59
|
+
end
|
60
|
+
property :tag, predicate: RDF::DC.relation do |index|
|
61
|
+
index.as :stored_searchable, :facetable
|
62
|
+
end
|
63
|
+
property :related_url, predicate: RDF::RDFS.seeAlso
|
64
|
+
|
65
|
+
# Single-valued properties
|
66
|
+
def depositor
|
67
|
+
super.first
|
68
|
+
end
|
69
|
+
|
70
|
+
def title
|
71
|
+
super.first
|
72
|
+
end
|
73
|
+
|
74
|
+
def date_uploaded
|
75
|
+
super.first
|
76
|
+
end
|
77
|
+
|
78
|
+
def date_modified
|
79
|
+
super.first
|
80
|
+
end
|
81
|
+
|
82
|
+
def description
|
83
|
+
super.first
|
84
|
+
end
|
23
85
|
|
24
86
|
before_create :set_date_uploaded
|
25
87
|
before_save :set_date_modified
|
88
|
+
before_destroy :update_all_members
|
26
89
|
|
27
90
|
after_save :update_all_members
|
28
|
-
|
29
|
-
before_destroy :update_all_members
|
30
91
|
end
|
31
92
|
|
32
93
|
def terms_for_editing
|
@@ -34,7 +95,11 @@ module Hydra
|
|
34
95
|
end
|
35
96
|
|
36
97
|
def terms_for_display
|
37
|
-
|
98
|
+
[
|
99
|
+
:part_of, :contributor, :creator, :title, :description, :publisher,
|
100
|
+
:date_created, :date_uploaded, :date_modified, :subject, :language, :rights,
|
101
|
+
:resource_type, :identifier, :based_near, :tag, :related_url
|
102
|
+
]
|
38
103
|
end
|
39
104
|
|
40
105
|
def update_all_members
|
@@ -58,6 +123,5 @@ module Hydra
|
|
58
123
|
self.date_modified = Date.today
|
59
124
|
end
|
60
125
|
|
61
|
-
|
62
|
-
|
126
|
+
end
|
63
127
|
end
|
@@ -1,19 +1,3 @@
|
|
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
1
|
<div style="float: right;" >
|
18
2
|
<%= form_for([collections, @collection] , :method => :get, :class => "well form-search") do |f| %>
|
19
3
|
|
data/hydra-collections.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["cam156@psu.edu"]
|
11
11
|
spec.description = "A rails engine for managing Hydra Collections"
|
12
12
|
spec.summary = "A rails engine for managing Hydra Collections"
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/projecthydra-labs/hydra-collections"
|
14
14
|
spec.license = "APACHE2"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "blacklight"
|
22
|
-
spec.add_dependency "hydra-head", "~>
|
22
|
+
spec.add_dependency "hydra-head", "~> 9.0.0.beta1"
|
23
|
+
spec.add_dependency 'deprecation'
|
23
24
|
|
24
25
|
spec.add_development_dependency "engine_cart"
|
25
26
|
spec.add_development_dependency "rspec-rails"
|
@@ -18,12 +18,12 @@ module Hydra
|
|
18
18
|
protected
|
19
19
|
|
20
20
|
def batch_ids_from_params
|
21
|
-
if params["batch_document_ids"].
|
22
|
-
|
21
|
+
if params["batch_document_ids"].blank?
|
22
|
+
[]
|
23
23
|
elsif params["batch_document_ids"] == "all"
|
24
|
-
|
24
|
+
Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
|
25
25
|
else
|
26
|
-
|
26
|
+
params["batch_document_ids"]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -52,4 +52,4 @@ module Hydra
|
|
52
52
|
|
53
53
|
end
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
@@ -1,25 +1,32 @@
|
|
1
1
|
# This module adds a `has_many :collections` association to any models that you mix it into, using the :has_collection_member property
|
2
2
|
# It also provides methods to help you index the information as a facet
|
3
|
+
require 'deprecation'
|
3
4
|
module Hydra::Collections::Collectible
|
4
|
-
extend ActiveSupport::Autoload
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
extend Deprecation
|
7
|
+
self.deprecation_horizon = "hydra-collections 4.0"
|
8
|
+
|
7
9
|
included do
|
8
|
-
|
9
|
-
has_many :collections, property: :has_collection_member, :class_name => "ActiveFedora::Base"
|
10
|
+
has_many :collections, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base"
|
10
11
|
end
|
11
12
|
|
12
|
-
# Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
|
13
|
+
# Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
|
13
14
|
# with the pids of any collections that contain the current object.
|
14
15
|
# @example
|
15
16
|
# def to_solr(solr_doc={}, opts={})
|
16
17
|
# super(solr_doc, opts)
|
17
|
-
#
|
18
|
+
# index_collection_ids(solr_doc)
|
18
19
|
# return solr_doc
|
19
20
|
# end
|
20
|
-
def
|
21
|
+
def index_collection_ids(solr_doc={})
|
21
22
|
solr_doc[Solrizer.solr_name(:collection, :facetable)] = self.collection_ids
|
22
23
|
solr_doc[Solrizer.solr_name(:collection)] = self.collection_ids
|
23
24
|
solr_doc
|
24
25
|
end
|
25
|
-
|
26
|
+
|
27
|
+
def index_collection_pids(solr_doc={})
|
28
|
+
index_collection_ids(solr_doc)
|
29
|
+
end
|
30
|
+
deprecation_deprecate :index_collection_pids
|
31
|
+
|
32
|
+
end
|