hydra-head 4.0.3 → 4.1.0
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.
- data/.gitignore +1 -0
- data/HISTORY.textile +17 -2
- data/app/assets/stylesheets/hydra/html_refactor.css +3 -30
- data/app/assets/stylesheets/hydra/styles.css +6 -64
- data/app/controllers/downloads_controller.rb +1 -1
- data/app/controllers/hydra/assets_controller.rb +10 -1
- data/app/controllers/hydra/contributors_controller.rb +15 -1
- data/app/controllers/hydra/file_assets_controller.rb +1 -1
- data/app/controllers/hydra/permissions_controller.rb +14 -0
- data/app/helpers/hydra/article_metadata_helper_behavior.rb +14 -1
- data/app/helpers/hydra/downloads_helper_behavior.rb +6 -0
- data/app/helpers/hydra/facets_helper_behavior.rb +7 -0
- data/app/helpers/hydra/generic_content_objects_helper_behavior.rb +6 -0
- data/app/helpers/hydra/hydra_assets_helper_behavior.rb +10 -0
- data/app/helpers/hydra/hydra_fedora_metadata_helper_behavior.rb +31 -0
- data/app/helpers/hydra/hydra_helper_behavior.rb +18 -7
- data/app/helpers/hydra/hydra_uploader_helper_behavior.rb +5 -0
- data/app/helpers/hydra/inline_editable_metadata_helper_behavior.rb +6 -0
- data/app/helpers/hydra/javascript_includes_helper_behavior.rb +7 -0
- data/app/helpers/hydra/personalization_helper_behavior.rb +5 -0
- data/app/helpers/hydra/release_process_helper_behavior.rb +5 -0
- data/app/models/generic_content.rb +3 -0
- data/app/models/generic_image.rb +3 -0
- data/app/models/superuser.rb +4 -2
- data/app/models/user_attribute.rb +7 -2
- data/app/views/_add_assets_links.html.erb +4 -4
- data/app/views/catalog/_index_partials/_default.html.erb +2 -2
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/generic_contents/_index.html.erb +2 -2
- data/app/views/generic_images/_edit.html.erb +1 -1
- data/app/views/generic_images/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_file_assets_form.html.erb +1 -1
- data/app/views/hydra/file_assets/_index.html.erb +2 -2
- data/app/views/hydra/file_assets/_result.html.erb +1 -1
- data/app/views/layouts/hydra-head.html.erb +4 -1
- data/app/views/mods_assets/_index_list.html.erb +1 -1
- data/app/views/mods_assets/_index_table.html.erb +2 -2
- data/app/views/mods_assets/_show.html.erb +1 -1
- data/app/views/mods_assets/_show_file_assets.html.erb +1 -1
- data/config/jetty.yml +1 -1
- data/config/locales/hydra.en.yml +7 -0
- data/config/solr.yml +1 -1
- data/config/solr_mappings.yml +2 -2
- data/hydra-head.gemspec +5 -4
- data/lib/generators/hydra/head_generator.rb +6 -5
- data/lib/generators/hydra/templates/config/fedora.yml +1 -1
- data/lib/generators/hydra/templates/config/solr.yml +1 -1
- data/lib/hydra-head/version.rb +1 -1
- data/lib/hydra.rb +13 -11
- data/lib/hydra/assets.rb +5 -135
- data/lib/hydra/catalog.rb +6 -44
- data/lib/hydra/controller.rb +10 -27
- data/lib/hydra/controller/assets_controller_behavior.rb +142 -0
- data/lib/hydra/controller/catalog_controller_behavior.rb +56 -0
- data/lib/hydra/controller/controller_behavior.rb +59 -0
- data/lib/hydra/controller/file_assets_behavior.rb +142 -0
- data/lib/hydra/controller/repository_controller_behavior.rb +119 -0
- data/lib/hydra/controller/upload_behavior.rb +139 -0
- data/lib/hydra/file_assets.rb +3 -138
- data/lib/hydra/file_assets_helper.rb +6 -133
- data/lib/hydra/generic_content.rb +15 -0
- data/lib/hydra/generic_image.rb +10 -0
- data/lib/hydra/global_configurable.rb +46 -0
- data/lib/hydra/model_methods.rb +3 -3
- data/lib/hydra/model_mixins.rb +1 -1
- data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
- data/lib/hydra/repository_controller.rb +4 -95
- data/lib/hydra/ui/controller.rb +1 -2
- data/lib/hydra/user.rb +13 -1
- data/lib/railties/hydra-fixtures.rake +1 -1
- data/tasks/hydra-head.rake +2 -0
- data/{app/models → test_support/etc}/common_metadata_asset.rb +1 -2
- data/test_support/features/mods_asset_show.feature +1 -1
- data/test_support/features/support/env.rb +2 -0
- data/test_support/features/support/paths.rb +2 -0
- data/test_support/spec/controllers/catalog_controller_spec.rb +8 -0
- data/test_support/spec/controllers/catalog_controller_viewing_context_spec.rb +10 -1
- data/test_support/spec/controllers/catalog_valid_html_spec.rb +8 -0
- data/test_support/spec/controllers/contributors_controller_spec.rb +10 -0
- data/test_support/spec/controllers/file_assets_controller_spec.rb +15 -3
- data/test_support/spec/controllers/hydra-assets_controller_spec.rb +11 -1
- data/test_support/spec/controllers/hydra_controller_spec.rb +15 -4
- data/test_support/spec/controllers/permissions_controller_spec.rb +8 -0
- data/test_support/spec/helpers/access_controls_enforcement_spec.rb +1 -2
- data/test_support/spec/helpers/file_assets_helper_spec.rb +1 -1
- data/test_support/spec/helpers/generic_content_objects_helper_spec.rb +10 -1
- data/test_support/spec/helpers/hydra-repository_controller_spec.rb +1 -1
- data/test_support/spec/helpers/hydra_assets_helper_spec.rb +8 -0
- data/test_support/spec/helpers/hydra_fedora_metadata_helper_spec.rb +11 -0
- data/test_support/spec/helpers/hydra_helper_spec.rb +18 -0
- data/test_support/spec/helpers/hydra_model_methods_spec.rb +0 -12
- data/test_support/spec/helpers/hydra_uploader_helper_spec.rb +8 -0
- data/test_support/spec/helpers/javascript_includes_helper_spec.rb +9 -1
- data/test_support/spec/lib/catalog_spec.rb +10 -3
- data/test_support/spec/lib/global_configurable_spec.rb +98 -0
- data/test_support/spec/lib/model_methods_spec.rb +29 -0
- data/test_support/spec/models/generic_content_spec.rb +11 -0
- data/test_support/spec/models/generic_image_spec.rb +15 -0
- data/test_support/spec/models/user_spec.rb +25 -0
- metadata +39 -37
- data/app/models/ability.rb +0 -5
- data/app/models/hydra/ability.rb +0 -137
- data/app/models/hydra/datastream/common_mods_index_methods.rb +0 -47
- data/app/models/hydra/datastream/mods_article.rb +0 -530
- data/app/models/hydra/datastream/mods_dataset.rb +0 -173
- data/app/models/hydra/datastream/mods_generic_content.rb +0 -498
- data/app/models/hydra/datastream/mods_image.rb +0 -497
- data/app/models/hydra/datastream/rights_metadata.rb +0 -191
- data/app/models/hydra/role_mapper_behavior.rb +0 -33
- data/app/models/role_mapper.rb +0 -6
- data/lib/hydra/access_controls_enforcement.rb +0 -237
- data/lib/hydra/access_controls_evaluation.rb +0 -38
- data/lib/hydra/common_mods_index_methods.rb +0 -46
- data/lib/hydra/model_mixins/mods_object.rb +0 -17
- data/lib/hydra/model_mixins/rights_metadata.rb +0 -357
- data/lib/hydra/mods_article.rb +0 -535
- data/lib/hydra/mods_dataset.rb +0 -177
- data/lib/hydra/mods_generic_content.rb +0 -500
- data/lib/hydra/mods_image.rb +0 -500
- data/lib/uva/mods_index_methods.rb +0 -30
- data/test_support/spec/lib/common_mods_index_methods_spec.rb +0 -26
- data/test_support/spec/models/ability_spec.rb +0 -40
- data/test_support/spec/models/hydra_rights_metadata_spec.rb +0 -175
- data/test_support/spec/models/role_mapper_spec.rb +0 -22
- data/test_support/spec/unit/rights_metadata_spec.rb +0 -80
@@ -1,139 +1,12 @@
|
|
1
1
|
# will move to lib/hydra/controller / upload_behavior.rb in release 5.x
|
2
|
+
require 'deprecation'
|
2
3
|
module Hydra::FileAssetsHelper
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# @return [FileAsset] the File Asset
|
7
|
-
def create_and_save_file_assets_from_params
|
8
|
-
if params.has_key?(:Filedata)
|
9
|
-
@file_assets = []
|
10
|
-
params[:Filedata].each do |file|
|
11
|
-
@file_asset = create_asset_from_file(file)
|
12
|
-
add_posted_blob_to_asset(@file_asset,file)
|
13
|
-
@file_asset.save
|
14
|
-
@file_assets << @file_asset
|
15
|
-
end
|
16
|
-
return @file_assets
|
17
|
-
else
|
18
|
-
render :text => "400 Bad Request", :status => 400
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Puts the contents of params[:Filedata] (posted blob) into a datastream within the given @asset
|
23
|
-
# Sets asset label and title to filename if they're empty
|
24
|
-
#
|
25
|
-
# @param [FileAsset] asset the File Asset to add the blob to
|
26
|
-
# @return [FileAsset] file the File Asset
|
27
|
-
def add_posted_blob_to_asset(asset, file)
|
28
|
-
#file_name = filename_from_params
|
29
|
-
file_name = file.original_filename
|
30
|
-
options = {:label=>file_name, :mimeType=>mime_type(file_name)}
|
31
|
-
dsid = datastream_id #Only call this once so that it could be a sequence
|
32
|
-
options[:dsid] = dsid if dsid
|
33
|
-
asset.add_file_datastream(file, options)
|
34
|
-
asset.set_title_and_label( file_name, :only_if_blank=>true )
|
35
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
extend Deprecation
|
36
6
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
# Associate the new file asset with its container
|
43
|
-
def associate_file_asset_with_container(file_asset=nil, container_id=nil)
|
44
|
-
if container_id.nil?
|
45
|
-
container_id = params[:asset_id]
|
46
|
-
end
|
47
|
-
if file_asset.nil?
|
48
|
-
file_asset = @file_asset
|
49
|
-
end
|
50
|
-
file_asset.add_relationship(:is_part_of, container_id)
|
51
|
-
file_asset.datastreams["RELS-EXT"].dirty = true
|
52
|
-
file_asset.save
|
53
|
-
end
|
54
|
-
|
55
|
-
# Apply any posted file metadata to the file asset
|
56
|
-
def apply_posted_file_metadata
|
57
|
-
@metadata_update_response = update_document(@file_asset, @sanitized_params)
|
58
|
-
@file_asset.save
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
# The posted File
|
63
|
-
# @return [File] the posted file. Defaults to nil if no file was posted.
|
64
|
-
def posted_file
|
65
|
-
params[:Filedata]
|
66
|
-
end
|
67
|
-
|
68
|
-
# A best-guess filename based on POST params
|
69
|
-
# If Filename was submitted, it uses that. Otherwise, it calls +original_filename+ on the posted file
|
70
|
-
def filename_from_params
|
71
|
-
if !params[:Filename].nil?
|
72
|
-
file_name = params[:Filename]
|
73
|
-
else
|
74
|
-
file_name = posted_file.original_filename
|
75
|
-
params[:Filename] = file_name
|
76
|
-
end
|
7
|
+
included do
|
8
|
+
Deprecation.warn Hydra::FileAssetsHelper, "Hydra::FileAssetsHelper has been moved to Hydra::Controller::UploadBehavior"
|
9
|
+
include Hydra::Controller::UploadBehavior
|
77
10
|
end
|
78
11
|
|
79
|
-
# Creates a File Asset and sets its label from params[:Filename]
|
80
|
-
#
|
81
|
-
# @return [FileAsset] the File Asset
|
82
|
-
def create_asset_from_params
|
83
|
-
file_asset = FileAsset.new
|
84
|
-
file_asset.label = params[:Filename]
|
85
|
-
|
86
|
-
return file_asset
|
87
|
-
end
|
88
|
-
|
89
|
-
# Creates a File Asset and sets its label from filename
|
90
|
-
#
|
91
|
-
# @return [FileAsset] the File Asset
|
92
|
-
def create_asset_from_file(file)
|
93
|
-
file_asset = FileAsset.new
|
94
|
-
file_asset.label = file.original_filename
|
95
|
-
|
96
|
-
return file_asset
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
# This is pre-Hydra code that created an AudioAsset, VideoAsset or ImageAsset based on the
|
101
|
-
# current params in the controller.
|
102
|
-
#
|
103
|
-
# @return [Constant] the recommended Asset class
|
104
|
-
def asset_class_from_params
|
105
|
-
if params.has_key?(:type)
|
106
|
-
chosen_type = case params[:type]
|
107
|
-
when "AudioAsset"
|
108
|
-
AudioAsset
|
109
|
-
when "VideoAsset"
|
110
|
-
VideoAsset
|
111
|
-
when "ImageAsset"
|
112
|
-
ImageAsset
|
113
|
-
else
|
114
|
-
FileAsset
|
115
|
-
end
|
116
|
-
elsif params.has_key?(:Filename)
|
117
|
-
chosen_type = choose_model_by_filename( params[:Filename] )
|
118
|
-
else
|
119
|
-
chosen_type = FileAsset
|
120
|
-
end
|
121
|
-
|
122
|
-
return chosen_type
|
123
|
-
end
|
124
|
-
|
125
|
-
def choose_model_by_filename(filename)
|
126
|
-
choose_model_by_filename_extension( File.extname(filename) )
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
private
|
131
|
-
# Return the mimeType for a given file name
|
132
|
-
# @param [String] file_name The filename to use to get the mimeType
|
133
|
-
# @return [String] mimeType for filename passed in. Default: application/octet-stream if mimeType cannot be determined
|
134
|
-
def mime_type file_name
|
135
|
-
mime_types = MIME::Types.of(file_name)
|
136
|
-
mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
137
|
-
end
|
138
|
-
|
139
12
|
end
|
@@ -3,7 +3,10 @@
|
|
3
3
|
# require "mime/types"
|
4
4
|
|
5
5
|
# will move to lib/hydra/model/generic_content_behavior in release 5.x
|
6
|
+
require 'deprecation'
|
6
7
|
module Hydra::GenericContent
|
8
|
+
extend Deprecation
|
9
|
+
self.deprecation_horizon = 'hydra-head 5.x'
|
7
10
|
|
8
11
|
def self.included(klass)
|
9
12
|
klass.send :include, Hydra::ModelMethods
|
@@ -27,14 +30,17 @@ module Hydra::GenericContent
|
|
27
30
|
def has_#{m}?
|
28
31
|
self.datastreams.keys.include? "#{m}"
|
29
32
|
end
|
33
|
+
deprecation_deprecate :has_#{m}?
|
30
34
|
|
31
35
|
def #{m}
|
32
36
|
datastreams["#{m}"].content if has_#{m}?
|
33
37
|
end
|
38
|
+
deprecation_deprecate :#{m}
|
34
39
|
|
35
40
|
def #{m}=(file)
|
36
41
|
create_or_update_datastream( "#{m}", file )
|
37
42
|
end
|
43
|
+
deprecation_deprecate :#{m}=
|
38
44
|
EOM
|
39
45
|
end
|
40
46
|
|
@@ -46,12 +52,14 @@ module Hydra::GenericContent
|
|
46
52
|
add_datastream(ds)
|
47
53
|
save
|
48
54
|
end
|
55
|
+
deprecation_deprecate :from_url
|
49
56
|
|
50
57
|
def from_binary binary_info, ds_name
|
51
58
|
file = binary_to_file(binary_info[:blob],ds_name,binary_info[:extension])
|
52
59
|
add_file_datastream(file,:dsid=>ds_name,:label=>ds_name)
|
53
60
|
save
|
54
61
|
end
|
62
|
+
deprecation_deprecate :from_binary
|
55
63
|
|
56
64
|
def binary_to_file blob, suffix, ext=nil
|
57
65
|
file_name = Time.now.strftime("%Y%m%d-%H%M%S")
|
@@ -60,6 +68,7 @@ module Hydra::GenericContent
|
|
60
68
|
f.close
|
61
69
|
return f
|
62
70
|
end
|
71
|
+
deprecation_deprecate :binary_to_file
|
63
72
|
|
64
73
|
def create_or_update_datastream ds_name, file
|
65
74
|
case file
|
@@ -76,6 +85,7 @@ module Hydra::GenericContent
|
|
76
85
|
end
|
77
86
|
end
|
78
87
|
end
|
88
|
+
deprecation_deprecate :create_or_update_datastream
|
79
89
|
|
80
90
|
# Returns a human readable filesize appropriate for the given number of bytes (ie. automatically chooses 'bytes','KB','MB','GB','TB')
|
81
91
|
# Based on a bit of python code posted here: http://blogmag.net/blog/read/38/Print_human_readable_file_size
|
@@ -89,9 +99,11 @@ module Hydra::GenericContent
|
|
89
99
|
end
|
90
100
|
end
|
91
101
|
end
|
102
|
+
deprecation_deprecate :bits_to_human_readable
|
92
103
|
|
93
104
|
# augments add_file_datastream to also put file size (in bytes/KB/MB/GB/TB) in mods:physicaldescription/mods:extent
|
94
105
|
def add_file_datastream(file, opts={})
|
106
|
+
Deprecation.warn(Hydra::GenericContent, "add_file_datastream is deprecated and will be removed in hydra-head 5.x")
|
95
107
|
# label = opts.has_key?(:label) ? opts[:label] : ""
|
96
108
|
# mimeType = opts.has_key?(:mimeType) ? opts[:mimeType] : ""
|
97
109
|
# ds = ActiveFedora::Datastream.new(:dsLabel => label, :controlGroup => 'M', :blob => file, :mimeType => mimeType)
|
@@ -107,9 +119,12 @@ module Hydra::GenericContent
|
|
107
119
|
end
|
108
120
|
descMetadata.update_indexed_attributes( [:physical_description, :extent] => size )
|
109
121
|
end
|
122
|
+
# deprecation_deprecate :add_file_datastream ## 'super' call breaks under ree.. ??
|
110
123
|
|
111
124
|
def mime_type file_name
|
112
125
|
mime_types = MIME::Types.of(file_name)
|
113
126
|
mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
114
127
|
end
|
128
|
+
deprecation_deprecate :mime_type
|
129
|
+
|
115
130
|
end
|
data/lib/hydra/generic_image.rb
CHANGED
@@ -9,8 +9,12 @@
|
|
9
9
|
#
|
10
10
|
# will move to lib/hydra/model/generic_image_behavior in release 5.x
|
11
11
|
require "hydra"
|
12
|
+
require 'deprecation'
|
12
13
|
|
13
14
|
module Hydra::GenericImage
|
15
|
+
extend Deprecation
|
16
|
+
self.deprecation_horizon = 'hydra-head 5.x'
|
17
|
+
|
14
18
|
def self.included klass
|
15
19
|
klass.send(:include, Hydra::GenericContent)
|
16
20
|
end
|
@@ -35,30 +39,36 @@ module Hydra::GenericImage
|
|
35
39
|
return DERIVATION_DEFAULTS
|
36
40
|
end
|
37
41
|
end
|
42
|
+
deprecation_deprecate :derivation_options
|
38
43
|
|
39
44
|
DEFAULT_IMAGE_DATASTREAMS.each do |ds_name|
|
40
45
|
class_eval <<-EOM
|
41
46
|
def has_#{ds_name}?
|
42
47
|
self.datastreams.keys.include? "#{ds_name}"
|
43
48
|
end
|
49
|
+
deprecation_deprecate :has_#{ds_name}?
|
44
50
|
|
45
51
|
def #{ds_name}
|
46
52
|
datastreams["#{ds_name}"].content if has_#{ds_name}?
|
47
53
|
end
|
54
|
+
deprecation_deprecate :#{ds_name}
|
48
55
|
|
49
56
|
def #{ds_name}=(file)
|
50
57
|
create_or_update_datastream("#{ds_name}",file)
|
51
58
|
end
|
59
|
+
deprecation_deprecate :#{ds_name}=
|
52
60
|
|
53
61
|
def derive_#{ds_name}
|
54
62
|
derive_datastream "#{ds_name}"
|
55
63
|
end
|
64
|
+
deprecation_deprecate :derive_#{ds_name}
|
56
65
|
EOM
|
57
66
|
end
|
58
67
|
|
59
68
|
def derive_all
|
60
69
|
DEFAULT_IMAGE_DATASTREAMS.each { |ds| self.send "derive_#{ds.to_sym}" }
|
61
70
|
end
|
71
|
+
deprecation_deprecate :derive_all
|
62
72
|
|
63
73
|
|
64
74
|
private
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Hydra::GlobalConfigurable
|
2
|
+
|
3
|
+
# The config environment name used by the #config method
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# class MyThing
|
7
|
+
# extend Hydra::GlobalConfigurable
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Now MyThing.config will be the result of:
|
11
|
+
# MyThing.configure(:production) {|config|}
|
12
|
+
#
|
13
|
+
# You set shared attributes by leaving the first argument blank or passing the :shared value:
|
14
|
+
# MyThing.configure {|config|}
|
15
|
+
# or
|
16
|
+
# MyThing.configure(:shared) {|config|}
|
17
|
+
|
18
|
+
# sets the @configs variable to a new Hash with empty Hash for :shared key and @config to nil
|
19
|
+
def reset_configs!
|
20
|
+
@config = nil
|
21
|
+
@configs = {:shared=>{}}
|
22
|
+
end
|
23
|
+
|
24
|
+
# A hash of all environment configs
|
25
|
+
# The key is the environment name, the value a Hash
|
26
|
+
def configs
|
27
|
+
@configs ? @configs : (reset_configs! and @configs)
|
28
|
+
end
|
29
|
+
|
30
|
+
# The main config accessor. It merges the current configs[::Rails.env]
|
31
|
+
# with configs[:shared] and lazy-loads @config to the result.
|
32
|
+
def config
|
33
|
+
@config ||= configs[:shared].merge(configs[::Rails.env] ||= {})
|
34
|
+
end
|
35
|
+
alias_method :blacklight_config, :config
|
36
|
+
|
37
|
+
# Accepts a value for the environment to configure and a block
|
38
|
+
# A hash is yielded to the block
|
39
|
+
# If the "env" != :shared,
|
40
|
+
# the hash is created by deep cloning the :shared environment config.
|
41
|
+
# This makes it possible to create defaults in the :shared config
|
42
|
+
def configure(env = :shared, &blk)
|
43
|
+
configs[env] = {}
|
44
|
+
yield configs[env]
|
45
|
+
end
|
46
|
+
end
|
data/lib/hydra/model_methods.rb
CHANGED
@@ -16,10 +16,10 @@ module Hydra::ModelMethods
|
|
16
16
|
prop_ds = self.datastreams["properties"]
|
17
17
|
rights_ds = self.datastreams["rightsMetadata"]
|
18
18
|
|
19
|
-
if
|
20
|
-
prop_ds.
|
19
|
+
if prop_ds
|
20
|
+
prop_ds.depositor = depositor_id unless prop_ds.nil?
|
21
21
|
end
|
22
|
-
rights_ds.
|
22
|
+
rights_ds.permissions({:person=>depositor_id}, 'edit') unless rights_ds.nil?
|
23
23
|
return true
|
24
24
|
end
|
25
25
|
|
data/lib/hydra/model_mixins.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Hydra::ModelMixins
|
2
|
+
module SolrDocumentExtension
|
3
|
+
def document_type display_type = CatalogController.blacklight_config.show.display_type
|
4
|
+
type = self.fetch(:medium_t, nil)
|
5
|
+
|
6
|
+
type ||= self.fetch(display_type, nil) if display_type
|
7
|
+
|
8
|
+
type.first.to_s.gsub("info:fedora/afmodel:","").gsub("Hydrangea","").gsub(/^Generic/,"")
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_person_from_role(role, opts={})
|
12
|
+
i = 0
|
13
|
+
while i < 10
|
14
|
+
persons_roles = self["person_#{i}_role_t"].map{|w|w.strip.downcase} unless self["person_#{i}_role_t"].nil?
|
15
|
+
if persons_roles and persons_roles.include?(role.downcase)
|
16
|
+
return {:first=>self["person_#{i}_first_name_t"], :last=>self["person_#{i}_last_name_t"]}
|
17
|
+
end
|
18
|
+
i += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
SolrDocument.use_extension Hydra::ModelMixins::SolrDocumentExtension
|
@@ -18,102 +18,11 @@
|
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
module Hydra::RepositoryController
|
21
|
-
|
22
|
-
def self.included(c)
|
23
|
-
if c.respond_to?(:helper_method)
|
24
|
-
c.helper_method :solr_name
|
25
|
-
c.helper_method :format_pid
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
# This method converts pid strings into xhtml safe IDs, since xhmlt expects namespaces to be defined.
|
32
|
-
# I.E. hydrus:123 = hydrus_123
|
33
|
-
def format_pid(pid)
|
34
|
-
pid.gsub(":", "_")
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def solr_name(field_name, field_type = :text)
|
40
|
-
::ActiveFedora::SolrService.solr_name(field_name, field_type)
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
# Returns a list of datastreams for download.
|
45
|
-
# Uses user's roles and "mime_type" value in submitted params to decide what to return.
|
46
|
-
# if you pass the optional argument of :canonical=>true, it will return the canonical datastream for this object (a single object not a hash of datastreams)
|
47
|
-
def downloadables(fedora_object=@fedora_object, opts={})
|
48
|
-
if opts[:canonical]
|
49
|
-
mime_type = opts[:mime_type] ? opts[:mime_type] : "application/pdf"
|
50
|
-
result = filter_datastreams_for_mime_type(fedora_object.datastreams, mime_type).sort.first[1]
|
51
|
-
elsif can? :edit, fedora_object
|
52
|
-
if params["mime_type"] == "all"
|
53
|
-
result = fedora_object.datastreams
|
54
|
-
else
|
55
|
-
result = Hash[]
|
56
|
-
fedora_object.datastreams.each_pair do |dsid,ds|
|
57
|
-
if !ds.new_object?
|
58
|
-
mime_type = ds.mimeType ? ds.mimeType : ""
|
59
|
-
if mime_type.include?("pdf") || ds.label.include?("_TEXT.xml") || ds.label.include?("_METS.xml")
|
60
|
-
result[dsid] = ds
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
else
|
66
|
-
result = Hash[]
|
67
|
-
fedora_object.datastreams.each_pair do |dsid,ds|
|
68
|
-
if ds.mimeType.include?("pdf")
|
69
|
-
result[dsid] = ds
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
# puts "downloadables result: #{result}"
|
74
|
-
return result
|
75
|
-
end
|
76
|
-
|
77
|
-
protected
|
78
|
-
def load_document
|
79
|
-
@document = load_document_from_params
|
80
|
-
end
|
21
|
+
extend ActiveSupport::Concern
|
81
22
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
af_model = retrieve_af_model(params[:content_type])
|
86
|
-
unless af_model
|
87
|
-
af_model = ModsAsset
|
88
|
-
end
|
89
|
-
return af_model.find(params[:id])
|
23
|
+
included do
|
24
|
+
ActiveSupport::Deprecation.warn "Hydra::RepositoryController has moved to Hydra::Controller::RepositoryControllerBehavior"
|
25
|
+
include Hydra::Controller::RepositoryControllerBehavior
|
90
26
|
end
|
91
27
|
|
92
|
-
def retrieve_af_model(class_name, opts={})
|
93
|
-
if !class_name.nil?
|
94
|
-
klass = Module.const_get(class_name.camelcase)
|
95
|
-
else
|
96
|
-
klass = nil
|
97
|
-
end
|
98
|
-
if klass.is_a?(Class) && klass.superclass == ActiveFedora::Base
|
99
|
-
return klass
|
100
|
-
else
|
101
|
-
return opts.fetch(:default, false)
|
102
|
-
end
|
103
|
-
rescue NameError
|
104
|
-
return false
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def filter_datastreams_for_mime_type(datastreams_hash, mime_type)
|
110
|
-
result = Hash[]
|
111
|
-
datastreams_hash.each_pair do |dsid,ds|
|
112
|
-
ds_mime_type = ds.mimeType ? ds.mimeType : ""
|
113
|
-
if ds_mime_type == mime_type
|
114
|
-
result[dsid] = ds
|
115
|
-
end
|
116
|
-
end
|
117
|
-
return result
|
118
|
-
end
|
119
28
|
end
|