hydra-collections 2.0.5 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +0 -4
  4. data/.rspec +1 -0
  5. data/Gemfile +9 -0
  6. data/README.md +3 -3
  7. data/Rakefile +8 -8
  8. data/{lib → app/controllers/concerns}/hydra/collections/selects_collections.rb +3 -8
  9. data/app/controllers/concerns/hydra/collections_controller_behavior.rb +19 -20
  10. data/app/helpers/collections_search_helper.rb +2 -1
  11. data/app/models/concerns/hydra/collection.rb +80 -16
  12. data/app/views/collections/_search_form.html.erb +0 -16
  13. data/hydra-collections.gemspec +4 -4
  14. data/lib/hydra/collections/accepts_batches.rb +5 -5
  15. data/lib/hydra/collections/collectible.rb +15 -8
  16. data/lib/hydra/collections/solr_document_behavior.rb +0 -15
  17. data/lib/hydra/collections/version.rb +1 -1
  18. data/spec/controllers/catalog_controller_spec.rb +5 -19
  19. data/spec/controllers/collections_controller_spec.rb +125 -154
  20. data/spec/controllers/other_collections_controller_spec.rb +13 -15
  21. data/spec/controllers/selects_collections_spec.rb +39 -48
  22. data/spec/factories.rb +0 -14
  23. data/spec/factories/users.rb +0 -14
  24. data/spec/helpers/collections_helper_spec.rb +14 -16
  25. data/spec/helpers/collections_search_helper_spec.rb +4 -2
  26. data/spec/lib/collectible_spec.rb +7 -7
  27. data/spec/models/collection_spec.rb +40 -42
  28. data/spec/spec_helper.rb +12 -1
  29. data/spec/{support → test_app_templates}/app/models/sample.rb +0 -0
  30. data/spec/{support → test_app_templates}/app/models/solr_document.rb +0 -0
  31. data/spec/{support → test_app_templates}/app/views/catalog/_document_header.html.erb +0 -0
  32. data/spec/{support → test_app_templates}/app/views/catalog/_index_collection.html.erb +0 -0
  33. data/spec/{support → test_app_templates}/app/views/catalog/_sort_and_per_page.html.erb +0 -0
  34. data/spec/{support → test_app_templates}/db/migrate/20111101221803_create_searches.rb +0 -0
  35. data/spec/{support → test_app_templates}/lib/generators/test_app_generator.rb +10 -2
  36. data/spec/{support → test_app_templates}/lib/tasks/rspec.rake +0 -0
  37. data/tasks/hydra-collections-dev.rake +16 -56
  38. metadata +33 -36
  39. data/app/models/datastreams/hydra/collection_rdf_datastream.rb +0 -58
  40. data/spec/factories/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d18580cc6f615f6c2db8d172eafc3295c15112d2
4
- data.tar.gz: 62d0fcd015fe10ddbea811c97d510ea851834af2
3
+ metadata.gz: 3b6be32ab4643ad1b7e135f56f5431cd691f06c9
4
+ data.tar.gz: b332c0d2f798db1e5383cc83cd880724448f0cf1
5
5
  SHA512:
6
- metadata.gz: c2a9e3f91da266b5d23af91de3ff2ae4aae0252d69fb3c7feed87e9323f953528b053f9d8399418377832084e8ea212466d14370098251af22d0c3564ff77a5a
7
- data.tar.gz: 0d571aa1c5108c78d46e4d6d6dc0e75c76d1b07fe77105774a068a12da2642f7e5ed3d6b2cf8d3b50fbf5af49312ab9d27a8bacfcb7e80f0ff0ca8579971864e
6
+ metadata.gz: 5ce2d0de4ac13bca1cf53a7ff8c705f57e401e9836882b80ca63778fd9aba7456a8b8d1f7c08204160c93040074035ca4018ae6badba6259cdc2aadc57d70894
7
+ data.tar.gz: 2ed72913e6c7aa79413d95a0f13f34fa0c405d883133cb4ec7390bc6ed72a05d8f3af035f047ef0c303d7fb85ab28eeb6e5282048d4f0f4e43fec3fa5a0311a8
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
20
  spec/internal
21
+ jetty
data/.gitmodules CHANGED
@@ -1,4 +0,0 @@
1
- [submodule "jetty"]
2
- path = jetty
3
- url = git://github.com/projecthydra/hydra-jetty.git
4
- ignore = dirty
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile CHANGED
@@ -3,6 +3,9 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in hydra-collections.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'active-fedora', '9.0.0.beta3'
7
+ gem 'hydra-head', github: 'projecthydra/hydra-head', branch: 'fedora-4'
8
+
6
9
  group :development, :test do
7
10
  gem 'sqlite3'
8
11
  gem "factory_girl_rails"
@@ -11,3 +14,9 @@ group :development, :test do
11
14
  gem 'jettywrapper'
12
15
  gem 'byebug', require: false
13
16
  end
17
+
18
+ file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
19
+ if File.exists?(file)
20
+ puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
21
+ instance_eval File.read(file)
22
+ end
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 `index_collection_pids` to the solrization logic (ie. put it in to_solr)
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
- index_collection_pids(solr_doc)
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 `index_collection_pids` puts the pids of all associated collections into the `collection` facet.
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
 
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
3
7
 
4
- Dir.glob('tasks/*.rake').each { |r| import r }
5
-
6
- ENV["RAILS_ROOT"] ||= 'spec/internal'
8
+ Bundler::GemHelper.install_tasks
7
9
 
8
- desc 'Run CI tests in e.g. Travis environment'
9
- task :travis => ['clean', 'ci']
10
+ Dir.glob('tasks/*.rake').each { |r| import r }
10
11
 
11
- desc 'Default: run CI'
12
- task :default => [:travis]
12
+ task :default => [:ci]
@@ -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,:edit],edit:[:edit]}
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({:q => ''}, {:rows=>100})
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)}:\"info:fedora/afmodel:Collection\""
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 (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,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({:q => query})
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(true)
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
- Collection.load_instance_from_solr(collection_pid).title || collection_pid
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
- has_metadata "descMetadata", type: Hydra::CollectionRdfDatastream
11
- has_metadata "properties", type: Hydra::Datastream::Properties
10
+ has_and_belongs_to_many :members, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasCollectionMember, class_name: "ActiveFedora::Base" , after_remove: :update_member
12
11
 
13
- has_and_belongs_to_many :members, property: :has_collection_member, class_name: "ActiveFedora::Base" , after_remove: :update_member
12
+ property :depositor, predicate: RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt")
14
13
 
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
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
- self.descMetadata.class.config.keys.map{|v| v.to_sym}
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
- end
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
 
@@ -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/psu-stewardship/hydra-collections"
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,9 +19,9 @@ 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", "~> 7.0"
22
+ spec.add_dependency "hydra-head", "~> 8.0.0.alpha"
23
+ spec.add_dependency 'deprecation'
23
24
 
24
- spec.add_development_dependency "bundler", "~> 1.3"
25
- spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "engine_cart"
26
26
  spec.add_development_dependency "rspec-rails"
27
27
  end
@@ -18,12 +18,12 @@ module Hydra
18
18
  protected
19
19
 
20
20
  def batch_ids_from_params
21
- if params["batch_document_ids"].nil? || params["batch_document_ids"].empty?
22
- return []
21
+ if params["batch_document_ids"].blank?
22
+ []
23
23
  elsif params["batch_document_ids"] == "all"
24
- return Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
24
+ Hydra::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
25
25
  else
26
- return params["batch_document_ids"]
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