hydra-head 3.1.5 → 3.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +1 -0
  2. data/CREATE_RAILS_APP.textile +2 -3
  3. data/Gemfile.lock +34 -32
  4. data/HISTORY.textile +8 -0
  5. data/app/models/file_asset.rb +1 -111
  6. data/app/models/mods_asset.rb +1 -1
  7. data/hydra-head.gemspec +2 -2
  8. data/lib/hydra-head.rb +1 -0
  9. data/lib/hydra-head/railtie.rb +11 -0
  10. data/lib/hydra-head/version.rb +1 -1
  11. data/lib/hydra.rb +2 -0
  12. data/lib/hydra/assets.rb +1 -1
  13. data/lib/hydra/assets_controller_helper.rb +1 -0
  14. data/lib/hydra/catalog.rb +7 -4
  15. data/lib/hydra/file_assets.rb +6 -17
  16. data/lib/hydra/image.rb +3 -0
  17. data/lib/hydra/model_methods.rb +6 -0
  18. data/lib/hydra/models/file_asset.rb +74 -0
  19. data/lib/railties/hydra-fixtures.rake +1 -3
  20. data/lib/railties/hydra_jetty.rake +1 -1
  21. data/tasks/hydra-head-fixtures.rake +1 -2
  22. data/test_support/features/step_definitions/edit_metadata_steps.rb +4 -4
  23. data/test_support/features/step_definitions/file_list_steps.rb +5 -5
  24. data/test_support/features/step_definitions/user_steps.rb +4 -4
  25. data/test_support/spec/helpers/hydra_assets_helper_spec.rb +5 -57
  26. data/test_support/spec/integration/file_asset_spec.rb +5 -56
  27. data/test_support/spec/models/file_asset_spec.rb +0 -17
  28. data/vendor/cache/{active-fedora-3.1.4.gem → active-fedora-3.2.0.pre5.gem} +0 -0
  29. data/vendor/cache/columnize-0.3.6.gem +0 -0
  30. data/vendor/cache/cucumber-1.1.4.gem +0 -0
  31. data/vendor/cache/{cucumber-rails-1.2.0.gem → cucumber-rails-1.2.1.gem} +0 -0
  32. data/vendor/cache/daemons-1.1.5.gem +0 -0
  33. data/vendor/cache/gherkin-2.7.1.gem +0 -0
  34. data/vendor/cache/haml-3.1.4.gem +0 -0
  35. data/vendor/cache/jettywrapper-1.2.0.gem +0 -0
  36. data/vendor/cache/json-1.6.3.gem +0 -0
  37. data/vendor/cache/json_pure-1.6.4.gem +0 -0
  38. data/vendor/cache/kaminari-0.13.0.gem +0 -0
  39. data/vendor/cache/om-1.4.4.gem +0 -0
  40. data/vendor/cache/rdoc-3.12.gem +0 -0
  41. data/vendor/cache/rubydora-0.3.1.gem +0 -0
  42. data/vendor/cache/selenium-webdriver-2.15.0.gem +0 -0
  43. data/vendor/cache/solrizer-fedora-1.2.2.gem +0 -0
  44. data/vendor/cache/stomp-1.2.0.gem +0 -0
  45. data/vendor/cache/yard-0.7.4.gem +0 -0
  46. metadata +43 -36
  47. data/app/views/catalog/_email_form.html.erb +0 -9
  48. data/vendor/cache/columnize-0.3.5.gem +0 -0
  49. data/vendor/cache/cucumber-1.1.3.gem +0 -0
  50. data/vendor/cache/daemons-1.1.4.gem +0 -0
  51. data/vendor/cache/gherkin-2.6.8.gem +0 -0
  52. data/vendor/cache/haml-3.1.3.gem +0 -0
  53. data/vendor/cache/jettywrapper-1.1.0.gem +0 -0
  54. data/vendor/cache/json-1.6.2.gem +0 -0
  55. data/vendor/cache/json_pure-1.6.2.gem +0 -0
  56. data/vendor/cache/kaminari-0.12.4.gem +0 -0
  57. data/vendor/cache/om-1.4.3.gem +0 -0
  58. data/vendor/cache/rdoc-3.11.gem +0 -0
  59. data/vendor/cache/rubydora-0.2.6.gem +0 -0
  60. data/vendor/cache/selenium-webdriver-2.13.0.gem +0 -0
  61. data/vendor/cache/solrizer-fedora-1.2.0.gem +0 -0
  62. data/vendor/cache/stomp-1.1.10.gem +0 -0
  63. data/vendor/cache/yard-0.7.3.gem +0 -0
@@ -98,14 +98,6 @@ module Hydra::FileAssets
98
98
 
99
99
  # Common destroy method for all AssetsControllers
100
100
  def destroy
101
- # The correct implementation, with garbage collection:
102
- # if params.has_key?(:container_id)
103
- # container = ActiveFedora::Base.load_instance(params[:container_id])
104
- # container.file_objects_remove(params[:id])
105
- # FileAsset.garbage_collect(params[:id])
106
- # else
107
-
108
- # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
109
101
  ActiveFedora::Base.load_instance(params[:id]).delete
110
102
 
111
103
  flash[:notice] = "Deleted #{params[:id]} from #{params[:container_id]}."
@@ -127,17 +119,14 @@ module Hydra::FileAssets
127
119
  flash[:notice]= "No such file asset."
128
120
  redirect_to(:action => 'index', :q => nil , :f => nil)
129
121
  else
130
- # get array of parent (container) objects for this FileAsset
131
- @id_array = @file_asset.containers(:response_format => :id_array)
122
+ # get containing object for this FileAsset
123
+ pid = @file_asset.container_id
132
124
  @downloadable = false
133
125
  # A FileAsset is downloadable iff the user has read or higher access to a parent
134
- @id_array.each do |pid|
135
- @response, @permissions_solr_document = get_solr_response_for_doc_id(pid)
136
- if reader?
137
- @downloadable = true
138
- break
139
- end
140
- end
126
+ @response, @permissions_solr_document = get_solr_response_for_doc_id(pid)
127
+ if reader?
128
+ @downloadable = true
129
+ end
141
130
 
142
131
  if @downloadable
143
132
  # First try to use datastream_id value (set in FileAssetsHelper)
data/lib/hydra/image.rb CHANGED
@@ -28,6 +28,8 @@ require "httparty"
28
28
 
29
29
  module Hydra
30
30
  class Image < ActiveFedora::Base
31
+ =begin
32
+ TODO This doesn't seem to be used anywhere. Commenting out until I hear back. Justin 2011-12-21
31
33
  include Hydra::ModelMethods
32
34
  include HTTParty
33
35
 
@@ -173,5 +175,6 @@ class Image < ActiveFedora::Base
173
175
  "#{admin_site}fedora/objects/#{pid}/datastreams/#{ds_name}/content"
174
176
  end
175
177
 
178
+ =end
176
179
  end
177
180
  end
@@ -1,4 +1,10 @@
1
1
  module Hydra::ModelMethods
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ extend ActiveFedora::Relationships
6
+ extend ActiveFedora::FileManagement
7
+ end
2
8
 
3
9
  #
4
10
  # Adds metadata about the depositor to the asset
@@ -0,0 +1,74 @@
1
+ module Hydra
2
+ module Models
3
+ module FileAsset
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ include Hydra::ModelMethods
7
+
8
+ #has_relationship "is_member_of_collection", :has_collection_member, :inbound => true
9
+ #has_bidirectional_relationship "part_of", :is_part_of, :has_part
10
+ belongs_to :container, :class_name=>'ActiveFedora::Base', :property=>:is_part_of
11
+ has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
12
+ end
13
+ end
14
+
15
+
16
+ # Returns a human readable filesize appropriate for the given number of bytes (ie. automatically chooses 'bytes','KB','MB','GB','TB')
17
+ # Based on a bit of python code posted here: http://blogmag.net/blog/read/38/Print_human_readable_file_size
18
+ # @param [Numeric] file size in bits
19
+ def bits_to_human_readable(num)
20
+ ['bytes','KB','MB','GB','TB'].each do |x|
21
+ if num < 1024.0
22
+ return "#{num.to_i} #{x}"
23
+ else
24
+ num = num/1024.0
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ def label
31
+ descMetadata.title_values.first
32
+ end
33
+
34
+ def label=(label)
35
+ super
36
+ descMetadata.title_values = label
37
+ end
38
+
39
+ # augments add_file_datastream to also put file size (in bytes/KB/MB/GB/TB) in dc:extent
40
+ def add_file_datastream(file, opts={})
41
+ super
42
+ if file.respond_to?(:size)
43
+ size = bits_to_human_readable(file.size)
44
+ elsif file.kind_of?(File)
45
+ size = bits_to_human_readable(File.size(file))
46
+ else
47
+ size = ""
48
+ end
49
+ datastreams["descMetadata"].extent_values = size
50
+ end
51
+
52
+ # Override ActiveFedora::Base.to_solr to...
53
+ # Check if we are dealing with a child of FileAsset and if so when calling to_solr from Solrizer indexer we want to skip loading parent metadata again
54
+ #
55
+ # if known models greater than one (without ActiveFedora::Base) and
56
+ # known models contains a child of FileAsset and
57
+ # opts[:model_only] == true and
58
+ # current object class is FileAsset
59
+ # that means that the child already has had to_solr called which included metadata from FileAsset
60
+ # if any of the above is false then call to_solr as normal
61
+ def to_solr(solr_doc=Hash.new, opts={})
62
+
63
+ active_fedora_model_s = solr_doc["active_fedora_model_s"] if solr_doc["active_fedora_model_s"]
64
+ actual_class = active_fedora_model_s.constantize if active_fedora_model_s
65
+ if actual_class && actual_class != self.class && actual_class.superclass == ::FileAsset
66
+ solr_doc
67
+ else
68
+ super(solr_doc,opts)
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -1,4 +1,3 @@
1
- # require File.expand_path(File.dirname(__FILE__) + '/hydra_jetty.rb')
2
1
  require "active-fedora"
3
2
  require "solrizer-fedora"
4
3
  require "active_support" # This is just to load ActiveSupport::CoreExtensions::String::Inflections
@@ -34,7 +33,6 @@ namespace :hydra do
34
33
  raise "You must specify a valid pid. Example: rake hydra:delete pid=demo:12"
35
34
  else
36
35
  pid = ENV["pid"]
37
- puts "Deleting '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
38
36
  begin
39
37
  ActiveFedora::FixtureLoader.delete(pid)
40
38
  rescue Errno::ECONNREFUSED => e
@@ -42,7 +40,7 @@ namespace :hydra do
42
40
  rescue Exception => e
43
41
  logger.error("Received a Fedora error while deleting #{pid}\n#{e}")
44
42
  end
45
- logger.info "Deleted '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
43
+ #logger.info "Deleted '#{pid}' from #{ActiveFedora::RubydoraConnection.instance.options[:url]}"
46
44
  end
47
45
  end
48
46
 
@@ -47,7 +47,7 @@ namespace :hydra do
47
47
  end
48
48
 
49
49
  desc "Copies the default SOLR config files and starts up the fedora instance."
50
- task :load => [:config, :start]
50
+ task :load => [:config, 'jetty:start']
51
51
 
52
52
  end
53
53
  end
@@ -1,4 +1,3 @@
1
- #require 'rake/testtask'
2
1
  require 'rspec/core'
3
2
  require 'rspec/core/rake_task'
4
3
 
@@ -51,4 +50,4 @@ namespace :hyhead do
51
50
  FileUtils.cd('../../')
52
51
  end
53
52
  end
54
- end
53
+ end
@@ -3,11 +3,11 @@ Then /^the following (should contain|contain|should not contain|do not contain):
3
3
  # table is a Cucumber::Ast::Table
4
4
  if bool == "should contain" || bool == "contain"
5
5
  table.rows_hash.each do |name, value|
6
- Then %{the "#{name}" field should contain "#{value}"}
6
+ step %{the "#{name}" field should contain "#{value}"}
7
7
  end
8
8
  elsif bool == "should not contain" || bool == "do not contain"
9
9
  table.rows_hash.each do |name, value|
10
- Then %{the "#{name}" field should not contain "#{value}"}
10
+ step %{the "#{name}" field should not contain "#{value}"}
11
11
  end
12
12
  else
13
13
  pending
@@ -17,14 +17,14 @@ end
17
17
  When /^I select the following(?: within "([^"]*)")?$/ do |scope_selector, table|
18
18
  # table is a Cucumber::Ast::Table
19
19
  table.rows_hash.each do |field_selector, value|
20
- Given %{I select "#{value}" from "#{field_selector}" within "#{scope_selector}"}
20
+ step %{I select "#{value}" from "#{field_selector}" within "#{scope_selector}"}
21
21
  end
22
22
  end
23
23
 
24
24
  Then /^the following should be selected(?: within "([^"]*)")?$/ do |scope_selector, table|
25
25
  # table is a Cucumber::Ast::Table
26
26
  table.rows_hash.each do |field_selector, value|
27
- Then %{"#{value}" should be selected from "#{field_selector}" within "#{scope_selector}"}
27
+ step %{"#{value}" should be selected from "#{field_selector}" within "#{scope_selector}"}
28
28
  # Then %{the "#{field_selector}" field within "#{scope_selector}" should contain "#{value}"}
29
29
  end
30
30
  end
@@ -2,9 +2,9 @@
2
2
  Then /^I (should|should not) see "([^"]*)" in the file assets list$/ do |bool, arg|
3
3
  with_scope("#file_assets") do
4
4
  if bool == "should"
5
- Then %{I should see "#{arg}"}
5
+ step %{I should see "#{arg}"}
6
6
  else
7
- Then %{I should not see "#{arg}"}
7
+ step %{I should not see "#{arg}"}
8
8
  end
9
9
  end
10
10
  end
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  Then /^I should see a link to "([^"]*)" in the file assets list$/ do |link_name|
14
14
  with_scope("#file_assets") do
15
- Then %{I should see a link called "#{link_name}"}
15
+ step %{I should see a link called "#{link_name}"}
16
16
  end
17
17
  end
18
18
 
@@ -20,9 +20,9 @@ end
20
20
  Then /^I (should|should not) see a link to "([^"]*)" with label "([^"]*)" in the file assets list$/ do |bool, link_name, label_name|
21
21
  with_scope("#file_assets") do
22
22
  if bool == "should"
23
- Then %{I should see a link to "#{link_name}" with label "#{label_name}"}
23
+ step %{I should see a link to "#{link_name}" with label "#{label_name}"}
24
24
  else
25
- Then %{I should not see a link to "#{link_name}" with label "#{label_name}"}
25
+ step %{I should not see a link to "#{link_name}" with label "#{label_name}"}
26
26
  end
27
27
  end
28
28
  end
@@ -11,8 +11,8 @@ Given /^I (?:am )?log(?:ged)? in as "([^\"]*)"$/ do |email|
11
11
  fill_in "Email", :with => email
12
12
  fill_in "Password", :with => "password"
13
13
  click_button "Sign in"
14
- Then %{I should see a link to "my account info" with label "#{email}"}
15
- And %{I should see a link to "logout"}
14
+ step %{I should see a link to "my account info" with label "#{email}"}
15
+ step %{I should see a link to "logout"}
16
16
  end
17
17
 
18
18
  Given /^I am logged in as "([^\"]*)" with "([^\"]*)" permissions$/ do |login,permission_group|
@@ -21,14 +21,14 @@ Given /^I am logged in as "([^\"]*)" with "([^\"]*)" permissions$/ do |login,per
21
21
  end
22
22
 
23
23
  Given /^I am a superuser$/ do
24
- Given %{I am logged in as "bigwig@example.com"}
24
+ step %{I am logged in as "bigwig@example.com"}
25
25
  bigwig_id = User.find_by_email("bigwig@example.com").id
26
26
  superuser = Superuser.create(:id => 20, :user_id => bigwig_id)
27
27
  visit superuser_path
28
28
  end
29
29
 
30
30
  Given /^I am not logged in$/ do
31
- Given %{I log out}
31
+ step %{I log out}
32
32
  end
33
33
 
34
34
  Given /^I log out$/ do
@@ -64,68 +64,35 @@ describe HydraAssetsHelper do
64
64
  before(:each) do
65
65
  #setup objects for following cases
66
66
  #
67
- #outbound has_collection_member
68
- #outbound has_collection_member + inbound is_part_of
69
- #outbound has_collection_member + outbound has_part + inbound is_part_of
70
67
  #outbound has_part
71
68
  #outbound has_part + inbound is_part_of
72
69
  #inbound is_part_of
73
70
  #none
74
- @asset_object1 = ActiveFedora::Base.new
75
- @asset_object2 = ActiveFedora::Base.new
76
- @asset_object3 = ActiveFedora::Base.new
77
71
  @asset_object4 = ActiveFedora::Base.new
78
72
  @asset_object5 = ActiveFedora::Base.new
79
73
  @asset_object6 = ActiveFedora::Base.new
80
74
  @asset_object7 = ActiveFedora::Base.new
81
75
  @file_object1 = ActiveFedora::Base.new
82
76
  @file_object2 = ActiveFedora::Base.new
83
- @file_object3 = ActiveFedora::Base.new
84
- @file_object4 = ActiveFedora::Base.new
85
77
 
86
- @asset_object1.collection_members_append(@file_object1)
87
- @asset_object1.collection_members_append(@file_object2)
88
78
 
89
- @asset_object2.collection_members_append(@file_object1)
90
- @asset_object2.collection_members_append(@file_object2)
91
- @asset_object2.add_relationship(:has_part,@file_object3)
92
-
93
- @asset_object3.collection_members_append(@file_object1)
94
- @asset_object3.collection_members_append(@file_object2)
95
- @asset_object3.add_relationship(:has_part,@file_object3)
96
- @file_object4.part_of_append(@asset_object3)
97
79
 
98
80
  @asset_object4.add_relationship(:has_part,@file_object1)
81
+ @asset_object5.save
99
82
  @asset_object5.add_relationship(:has_part,@file_object1)
100
83
  @file_object2.part_of_append(@asset_object5)
84
+ @asset_object6.save
101
85
  @file_object1.part_of_append(@asset_object6)
102
86
 
103
- @asset_object1.save
104
- @asset_object2.save
105
- @asset_object3.save
87
+ @file_object1.save
88
+ @file_object2.save
106
89
  @asset_object4.save
107
90
  @asset_object5.save
108
91
  @asset_object6.save
109
92
  @asset_object7.save
110
- @file_object1.save
111
- @file_object2.save
112
- @file_object3.save
113
- @file_object4.save
114
93
  end
115
94
 
116
95
  after(:each) do
117
- begin
118
- @asset_object1.delete
119
- rescue
120
- end
121
- begin
122
- @asset_object2.delete
123
- rescue
124
- end
125
- begin
126
- @asset_object3.delete
127
- rescue
128
- end
129
96
  begin
130
97
  @asset_object4.delete
131
98
  rescue
@@ -150,36 +117,17 @@ describe HydraAssetsHelper do
150
117
  @file_object2.delete
151
118
  rescue
152
119
  end
153
- begin
154
- @file_object3.delete
155
- rescue
156
- end
157
- begin
158
- @file_object4.delete
159
- rescue
160
- end
161
120
  end
162
121
 
163
122
  it "should return the correct number of assets with either has_collection_member file assets or parts" do
164
123
 
165
124
  #cases are
166
- #outbound has_collection_member
167
- #outbound has_collection_member + inbound is_part_of
168
- #outbound has_collection_member + outbound has_part + inbound is_part_of
169
125
  #outbound has_part
170
126
  #outbound has_part + inbound is_part_of
171
127
  #inbound is_part_of
172
128
  #none
173
129
 
174
- result = ActiveFedora::Base.find_by_solr(@asset_object1.pid)
175
- doc = result.hits.first
176
- get_file_asset_count(doc).should == 2
177
- result = ActiveFedora::Base.find_by_solr(@asset_object2.pid)
178
- doc = result.hits.first
179
- get_file_asset_count(doc).should == 3
180
- result = ActiveFedora::Base.find_by_solr(@asset_object3.pid)
181
- doc = result.hits.first
182
- get_file_asset_count(doc).should == 4
130
+
183
131
  result = ActiveFedora::Base.find_by_solr(@asset_object4.pid)
184
132
  doc = result.hits.first
185
133
  get_file_asset_count(doc).should == 1
@@ -21,71 +21,20 @@ describe FileAsset do
21
21
  describe "with parts" do
22
22
  before(:each) do
23
23
  @asset1 = ActiveFedora::Base.new
24
- @asset2 = ActiveFedora::Base.new
25
- @asset3 = ActiveFedora::Base.new
26
24
  @asset1.save
27
- @asset2.save
28
- @asset3.save
29
25
  end
30
26
 
31
27
  after(:each) do
32
- begin
33
28
  @asset1.delete
34
- rescue
35
- end
36
- begin
37
- @asset2.delete
38
- rescue
39
- end
40
- begin
41
- @asset3.delete
42
- rescue
43
- end
44
- end
45
-
46
- describe ".containers" do
47
- it "should return asset container objects via either inbound has_collection_member, inbound has_part, or outbound is_part_of relationships" do
48
- #test all possible combinations...
49
- #none
50
- @file_asset.containers(:response_format=>:id_array).should == []
51
- #is_part_of
52
- @file_asset.part_of_append(@asset1)
53
- @file_asset.containers(:response_format=>:id_array).should == [@asset1.pid]
54
- #has_part + is_part_of
55
- @asset2.parts_append(@file_asset)
56
- @asset2.save
57
- @file_asset.containers(:response_format=>:id_array).should == [@asset2.pid,@asset1.pid]
58
- #has_part
59
- @file_asset.part_of_remove(@asset1)
60
- @file_asset.containers(:response_format=>:id_array).should == [@asset2.pid]
61
- #has_collection_member
62
- @asset2.parts_remove(@file_asset)
63
- @asset2.save
64
- @asset3.collection_members_append(@file_asset)
65
- @asset3.save
66
- @file_asset.containers(:response_format=>:id_array).should == [@asset3.pid]
67
- #is_part_of + has_collection_member
68
- @file_asset.part_of_append(@asset1)
69
- @file_asset.containers(:response_format=>:id_array).should == [@asset3.pid,@asset1.pid]
70
- #has_part + has_collection_member
71
- @file_asset.part_of_remove(@asset1)
72
- @asset2.parts_append(@file_asset)
73
- @asset2.save
74
- @file_asset.containers(:response_format=>:id_array).should == [@asset3.pid,@asset2.pid]
75
- #has_collection_member + has_part + is_part_of
76
- @file_asset.part_of_append(@asset1)
77
- @file_asset.containers(:response_format=>:id_array).should == [@asset3.pid,@asset2.pid,@asset1.pid]
78
- end
79
29
  end
80
30
 
81
- describe ".containers_ids" do
82
- it "should return an array of container ids instead of objects" do
83
- #test all possible combinations...
31
+ describe ".container_id" do
32
+ it "should return asset container objects via is_part_of relationships" do
84
33
  #none
85
- @file_asset.containers_ids.should == []
34
+ @file_asset.container_id.should be_nil
86
35
  #is_part_of
87
- @file_asset.part_of_append(@asset1)
88
- @file_asset.containers_ids.should == [@asset1.pid]
36
+ @file_asset.container = @asset1
37
+ @file_asset.container_id.should == @asset1.pid
89
38
  end
90
39
  end
91
40
  end