hydra-collections 3.0.0.beta2 → 3.0.0.beta3
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/README.md +3 -3
- data/app/controllers/concerns/hydra/collections_controller_behavior.rb +20 -19
- data/app/helpers/collections_search_helper.rb +1 -2
- data/app/models/concerns/hydra/collection.rb +18 -82
- data/app/models/datastreams/hydra/collection_rdf_datastream.rb +54 -0
- data/app/views/collections/_search_form.html.erb +16 -0
- data/hydra-collections.gemspec +2 -3
- data/lib/hydra/collections/accepts_batches.rb +5 -5
- data/lib/hydra/collections/collectible.rb +8 -15
- data/{app/controllers/concerns → lib}/hydra/collections/selects_collections.rb +8 -3
- data/lib/hydra/collections/solr_document_behavior.rb +15 -0
- data/lib/hydra/collections/version.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +19 -5
- data/spec/controllers/collections_controller_spec.rb +154 -125
- data/spec/controllers/other_collections_controller_spec.rb +15 -13
- data/spec/controllers/selects_collections_spec.rb +48 -39
- data/spec/factories.rb +14 -0
- data/spec/factories/.gitkeep +0 -0
- data/spec/factories/users.rb +14 -0
- data/spec/helpers/collections_helper_spec.rb +16 -14
- data/spec/helpers/collections_search_helper_spec.rb +2 -4
- data/spec/lib/collectible_spec.rb +7 -7
- data/spec/models/collection_spec.rb +133 -78
- data/spec/spec_helper.rb +1 -12
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -1
- data/tasks/hydra-collections-dev.rake +1 -19
- metadata +9 -21
- data/.rspec +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89c0019427e673f40b0abd3a2293d9bf74bd19cc
|
4
|
+
data.tar.gz: d2f4fb9c57d32e5b3a392afb27174a62666f4021
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c09ea609b5bfa9befba296dc44dbb2349d3d52f289f68549feceaefd8afbe07d6d6973e77ed1c9dbd95e5623a779f4c8ce71ff6a2380fda548aa9d04e4cc4124
|
7
|
+
data.tar.gz: eaf736cb88e9690b7b93d09deb2ba3aada36ca27c9d649753592885e88dbfd7d1db0a8e5a8353b4b7e6a8b0c1e6a456494c55e7d3e9436a427d057a5bb0680e4
|
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_pids` 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_pids(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_pids` puts the pids of all associated collections into the `collection` facet.
|
54
54
|
|
55
55
|
### Make the Collection show as a facet in your CatalogController
|
56
56
|
|
@@ -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 exception.action == :edit
|
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,19 +46,18 @@ module Hydra
|
|
46
46
|
|
47
47
|
def after_create
|
48
48
|
respond_to do |format|
|
49
|
-
ActiveFedora::SolrService.instance.conn.commit
|
50
49
|
format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully created.' }
|
51
50
|
format.json { render json: @collection, status: :created, location: @collection }
|
52
51
|
end
|
53
52
|
end
|
54
|
-
|
53
|
+
|
55
54
|
def after_create_error
|
56
55
|
respond_to do |format|
|
57
56
|
format.html { render action: "new" }
|
58
57
|
format.json { render json: @collection.errors, status: :unprocessable_entity }
|
59
58
|
end
|
60
59
|
end
|
61
|
-
|
60
|
+
|
62
61
|
def create
|
63
62
|
@collection.apply_depositor_metadata(current_user.user_key)
|
64
63
|
add_members_to_collection unless batch.empty?
|
@@ -68,8 +67,8 @@ module Hydra
|
|
68
67
|
after_create_error
|
69
68
|
end
|
70
69
|
end
|
71
|
-
|
72
|
-
def after_update
|
70
|
+
|
71
|
+
def after_update
|
73
72
|
if flash[:notice].nil?
|
74
73
|
flash[:notice] = 'Collection was successfully updated.'
|
75
74
|
end
|
@@ -78,14 +77,14 @@ module Hydra
|
|
78
77
|
format.json { render json: @collection, status: :updated, location: @collection }
|
79
78
|
end
|
80
79
|
end
|
81
|
-
|
80
|
+
|
82
81
|
def after_update_error
|
83
82
|
respond_to do |format|
|
84
83
|
format.html { render action: collections.edit_collection_path(@collection) }
|
85
84
|
format.json { render json: @collection.errors, status: :unprocessable_entity }
|
86
85
|
end
|
87
86
|
end
|
88
|
-
|
87
|
+
|
89
88
|
def update
|
90
89
|
process_member_changes
|
91
90
|
@collection.update_attributes(params[:collection].except(:members))
|
@@ -95,21 +94,21 @@ module Hydra
|
|
95
94
|
after_update_error
|
96
95
|
end
|
97
96
|
end
|
98
|
-
|
97
|
+
|
99
98
|
def after_destroy (id)
|
100
99
|
respond_to do |format|
|
101
100
|
format.html { redirect_to catalog_index_path, notice: 'Collection was successfully deleted.' }
|
102
101
|
format.json { render json: {id:id}, status: :destroyed, location: @collection }
|
103
|
-
end
|
102
|
+
end
|
104
103
|
end
|
105
104
|
|
106
105
|
def after_destroy_error (id)
|
107
106
|
respond_to do |format|
|
108
107
|
format.html { redirect_to catalog_index_path, notice: 'Collection could not be deleted.' }
|
109
108
|
format.json { render json: {id:id}, status: :destroy_error, location: @collection }
|
110
|
-
end
|
109
|
+
end
|
111
110
|
end
|
112
|
-
|
111
|
+
|
113
112
|
def destroy
|
114
113
|
if @collection.destroy
|
115
114
|
after_destroy(params[:id])
|
@@ -117,16 +116,16 @@ module Hydra
|
|
117
116
|
after_destroy_error(params[:id])
|
118
117
|
end
|
119
118
|
end
|
120
|
-
|
119
|
+
|
121
120
|
protected
|
122
121
|
|
123
|
-
# Queries Solr for members of the collection.
|
122
|
+
# Queries Solr for members of the collection.
|
124
123
|
# Populates @response and @member_docs similar to Blacklight Catalog#index populating @response and @documents
|
125
124
|
def query_collection_members
|
126
125
|
query = params[:cq]
|
127
126
|
|
128
127
|
#default the rows to 100 if not specified then merge in the user parameters and the attach the collection query
|
129
|
-
solr_params = {
|
128
|
+
solr_params = {rows:100}.merge(params.symbolize_keys).merge({:q => query})
|
130
129
|
|
131
130
|
# run the solr query to find the collections
|
132
131
|
(@response, @member_docs) = get_search_results(solr_params)
|
@@ -143,15 +142,17 @@ module Hydra
|
|
143
142
|
|
144
143
|
def add_members_to_collection collection = nil
|
145
144
|
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
|
150
|
+
@collection.members(true)
|
151
|
+
@collection.member_ids = (@collection.member_ids - batch)
|
151
152
|
end
|
152
153
|
|
153
154
|
def assign_batch_to_collection
|
154
|
-
@collection.members(true)
|
155
|
+
@collection.members(true)
|
155
156
|
@collection.member_ids = batch
|
156
157
|
end
|
157
158
|
|
@@ -165,11 +166,11 @@ module Hydra
|
|
165
166
|
flash[:error] = "An error occured. Files were not moved to #{destination_collection.title} Collection."
|
166
167
|
end
|
167
168
|
end
|
168
|
-
|
169
|
+
|
169
170
|
# include filters into the query to only include the collection memebers
|
170
171
|
def include_collection_ids(solr_parameters, user_parameters)
|
171
172
|
solr_parameters[:fq] ||= []
|
172
|
-
solr_parameters[:fq] << Solrizer.solr_name(:collection
|
173
|
+
solr_parameters[:fq] << Solrizer.solr_name(:collection)+':"'+@collection.id+'"'
|
173
174
|
end
|
174
175
|
end # module CollectionsControllerBehavior
|
175
176
|
end # module Hydra
|
@@ -4,8 +4,7 @@ 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
|
-
|
8
|
-
Collection.find(collection_pid).title || collection_pid
|
7
|
+
Collection.load_instance_from_solr(collection_pid).title || collection_pid
|
9
8
|
end
|
10
9
|
|
11
10
|
end
|
@@ -7,87 +7,26 @@ 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
|
-
|
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
|
10
|
+
has_metadata "descMetadata", type: Hydra::CollectionRdfDatastream
|
11
|
+
has_metadata "properties", type: Hydra::Datastream::Properties
|
12
|
+
|
13
|
+
has_and_belongs_to_many :members, property: :has_collection_member, class_name: "ActiveFedora::Base" , after_remove: :update_member
|
14
|
+
|
15
|
+
has_attributes :depositor, datastream: :properties, multiple: false
|
16
|
+
|
17
|
+
has_attributes :title, :date_uploaded, :date_modified, :description,
|
18
|
+
datastream: :descMetadata, multiple: false
|
19
|
+
has_attributes :creator, :contributor, :based_near, :part_of, :publisher,
|
20
|
+
:date_created, :subject,:resource_type, :rights,
|
21
|
+
:identifier, :language, :tag, :related_url,
|
22
|
+
datastream: :descMetadata, multiple: true
|
85
23
|
|
86
24
|
before_create :set_date_uploaded
|
87
25
|
before_save :set_date_modified
|
88
|
-
before_destroy :update_all_members
|
89
26
|
|
90
27
|
after_save :update_all_members
|
28
|
+
|
29
|
+
before_destroy :update_all_members
|
91
30
|
end
|
92
31
|
|
93
32
|
def terms_for_editing
|
@@ -95,11 +34,7 @@ module Hydra
|
|
95
34
|
end
|
96
35
|
|
97
36
|
def terms_for_display
|
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
|
-
]
|
37
|
+
self.descMetadata.class.properties.keys.map{|v| v.to_sym}
|
103
38
|
end
|
104
39
|
|
105
40
|
def update_all_members
|
@@ -123,5 +58,6 @@ module Hydra
|
|
123
58
|
self.date_modified = Date.today
|
124
59
|
end
|
125
60
|
|
126
|
-
|
61
|
+
end
|
62
|
+
|
127
63
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Hydra
|
2
|
+
class CollectionRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
3
|
+
property :part_of, predicate: RDF::DC.isPartOf
|
4
|
+
property :contributor, predicate: RDF::DC.contributor do |index|
|
5
|
+
index.as :stored_searchable, :facetable
|
6
|
+
end
|
7
|
+
property :creator, predicate: RDF::DC.creator do |index|
|
8
|
+
index.as :stored_searchable, :facetable
|
9
|
+
end
|
10
|
+
property :title, predicate: RDF::DC.title do |index|
|
11
|
+
index.as :stored_searchable
|
12
|
+
end
|
13
|
+
property :description, predicate: RDF::DC.description do |index|
|
14
|
+
index.type :text
|
15
|
+
index.as :stored_searchable
|
16
|
+
end
|
17
|
+
property :publisher, predicate: RDF::DC.publisher do |index|
|
18
|
+
index.as :stored_searchable, :facetable
|
19
|
+
end
|
20
|
+
property :date_created, predicate: RDF::DC.created do |index|
|
21
|
+
index.as :stored_searchable
|
22
|
+
end
|
23
|
+
property :date_uploaded, predicate: RDF::DC.dateSubmitted do |index|
|
24
|
+
index.type :date
|
25
|
+
index.as :stored_sortable
|
26
|
+
end
|
27
|
+
property :date_modified, predicate: RDF::DC.modified do |index|
|
28
|
+
index.type :date
|
29
|
+
index.as :stored_sortable
|
30
|
+
end
|
31
|
+
property :subject, predicate: RDF::DC.subject do |index|
|
32
|
+
index.as :stored_searchable, :facetable
|
33
|
+
end
|
34
|
+
property :language, predicate: RDF::DC.language do |index|
|
35
|
+
index.as :stored_searchable, :facetable
|
36
|
+
end
|
37
|
+
property :rights, predicate: RDF::DC.rights do |index|
|
38
|
+
index.as :stored_searchable
|
39
|
+
end
|
40
|
+
property :resource_type, predicate: RDF::DC.type do |index|
|
41
|
+
index.as :stored_searchable, :facetable
|
42
|
+
end
|
43
|
+
property :identifier, predicate: RDF::DC.identifier do |index|
|
44
|
+
index.as :stored_searchable
|
45
|
+
end
|
46
|
+
property :based_near, predicate: RDF::FOAF.based_near do |index|
|
47
|
+
index.as :stored_searchable, :facetable
|
48
|
+
end
|
49
|
+
property :tag, predicate: RDF::DC.relation do |index|
|
50
|
+
index.as :stored_searchable, :facetable
|
51
|
+
end
|
52
|
+
property :related_url, predicate: RDF::RDFS.seeAlso
|
53
|
+
end
|
54
|
+
end
|
@@ -1,3 +1,19 @@
|
|
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
|
+
|
1
17
|
<div style="float: right;" >
|
2
18
|
<%= form_for([collections, @collection] , :method => :get, :class => "well form-search") do |f| %>
|
3
19
|
|
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/psu-stewardship/hydra-collections"
|
14
14
|
spec.license = "APACHE2"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -19,8 +19,7 @@ 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", "~>
|
23
|
-
spec.add_dependency 'deprecation'
|
22
|
+
spec.add_dependency "hydra-head", "~> 8.0.0.beta1"
|
24
23
|
|
25
24
|
spec.add_development_dependency "engine_cart"
|
26
25
|
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"].nil? || params["batch_document_ids"].empty?
|
22
|
+
return []
|
23
23
|
elsif params["batch_document_ids"] == "all"
|
24
|
-
Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
|
24
|
+
return Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
|
25
25
|
else
|
26
|
-
params["batch_document_ids"]
|
26
|
+
return 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,32 +1,25 @@
|
|
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'
|
4
3
|
module Hydra::Collections::Collectible
|
4
|
+
extend ActiveSupport::Autoload
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
self.deprecation_horizon = "hydra-collections 4.0"
|
8
|
-
|
6
|
+
|
9
7
|
included do
|
10
|
-
|
8
|
+
#after_solrize << :index_collection_pids
|
9
|
+
has_many :collections, property: :has_collection_member, :class_name => "ActiveFedora::Base"
|
11
10
|
end
|
12
11
|
|
13
|
-
# Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
|
12
|
+
# Add this method to your solrization logic (ie. in to_solr) in order to populate the 'collection' facet
|
14
13
|
# with the pids of any collections that contain the current object.
|
15
14
|
# @example
|
16
15
|
# def to_solr(solr_doc={}, opts={})
|
17
16
|
# super(solr_doc, opts)
|
18
|
-
#
|
17
|
+
# index_collection_pids(solr_doc)
|
19
18
|
# return solr_doc
|
20
19
|
# end
|
21
|
-
def
|
20
|
+
def index_collection_pids(solr_doc={})
|
22
21
|
solr_doc[Solrizer.solr_name(:collection, :facetable)] = self.collection_ids
|
23
22
|
solr_doc[Solrizer.solr_name(:collection)] = self.collection_ids
|
24
23
|
solr_doc
|
25
24
|
end
|
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
|
25
|
+
end
|