hydra-core 5.0.0.pre1

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.
Files changed (105) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +5 -0
  3. data/app/helpers/blacklight_helper.rb +4 -0
  4. data/app/helpers/facets_helper.rb +4 -0
  5. data/app/helpers/hydra/blacklight_helper_behavior.rb +36 -0
  6. data/app/helpers/hydra/facets_helper_behavior.rb +25 -0
  7. data/app/models/hydra/datastream/properties.rb +24 -0
  8. data/app/models/mods_asset.rb +25 -0
  9. data/app/views/_flash_msg.html.erb +5 -0
  10. data/app/views/catalog/_citation.html.erb +11 -0
  11. data/app/views/catalog/_constraints_element.html.erb +34 -0
  12. data/app/views/catalog/_delete_partials/_default.html.erb +22 -0
  13. data/app/views/catalog/_edit_partials/_default.html.erb +57 -0
  14. data/app/views/catalog/_edit_partials/_default_details.html.erb +13 -0
  15. data/app/views/catalog/_facets.html.erb +37 -0
  16. data/app/views/catalog/_home.html.erb +6 -0
  17. data/app/views/catalog/_home_text.html.erb +4 -0
  18. data/app/views/catalog/_index_partials/_default.html.erb +20 -0
  19. data/app/views/catalog/_index_partials/_default_details.html.erb +14 -0
  20. data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -0
  21. data/app/views/catalog/_show_partials/_default.html.erb +21 -0
  22. data/app/views/catalog/_show_partials/_default_details.html.erb +15 -0
  23. data/app/views/catalog/_show_partials/_facets.html.erb +52 -0
  24. data/app/views/catalog/_sms_form.html.erb +21 -0
  25. data/app/views/catalog/_sort_and_per_page.html.erb +23 -0
  26. data/app/views/catalog/_uva_tabs.html.erb +10 -0
  27. data/app/views/catalog/about.html.erb +0 -0
  28. data/app/views/catalog/show.html.erb +40 -0
  29. data/app/views/layouts/hydra-head.html.erb +47 -0
  30. data/config/jetty.yml +6 -0
  31. data/config/locales/hydra.en.yml +7 -0
  32. data/hydra-core.gemspec +40 -0
  33. data/lib/application_helper.rb +3 -0
  34. data/lib/generators/hydra/assets_generator.rb +50 -0
  35. data/lib/generators/hydra/cucumber_support_generator.rb +29 -0
  36. data/lib/generators/hydra/head_generator.rb +160 -0
  37. data/lib/generators/hydra/hyhead_fixtures_generator.rb +27 -0
  38. data/lib/generators/hydra/templates/catalog_controller.rb +162 -0
  39. data/lib/generators/hydra/templates/config/fedora.yml +14 -0
  40. data/lib/generators/hydra/templates/config/initializers/action_dispatch_http_upload_monkey_patch.rb +12 -0
  41. data/lib/generators/hydra/templates/config/initializers/hydra_config.rb +39 -0
  42. data/lib/generators/hydra/templates/config/role_map_cucumber.yml +10 -0
  43. data/lib/generators/hydra/templates/config/role_map_development.yml +12 -0
  44. data/lib/generators/hydra/templates/config/role_map_production.yml +2 -0
  45. data/lib/generators/hydra/templates/config/role_map_test.yml +15 -0
  46. data/lib/generators/hydra/templates/config/solr.yml +10 -0
  47. data/lib/generators/hydra/templates/config/solr_mappings.yml +22 -0
  48. data/lib/generators/hydra/templates/fedora_conf/conf/development/fedora.fcfg +946 -0
  49. data/lib/generators/hydra/templates/fedora_conf/conf/test/fedora.fcfg +946 -0
  50. data/lib/generators/hydra/templates/solr_conf/conf/schema.xml +692 -0
  51. data/lib/generators/hydra/templates/solr_conf/conf/solrconfig.xml +1887 -0
  52. data/lib/generators/hydra/templates/solr_conf/solr.xml +35 -0
  53. data/lib/hydra-core.rb +1 -0
  54. data/lib/hydra-head.rb +27 -0
  55. data/lib/hydra-head/engine.rb +14 -0
  56. data/lib/hydra-head/routes.rb +90 -0
  57. data/lib/hydra-head/version.rb +4 -0
  58. data/lib/hydra.rb +30 -0
  59. data/lib/hydra/catalog.rb +11 -0
  60. data/lib/hydra/controller.rb +25 -0
  61. data/lib/hydra/controller/controller_behavior.rb +39 -0
  62. data/lib/hydra/controller/repository_controller_behavior.rb +78 -0
  63. data/lib/hydra/controller/upload_behavior.rb +139 -0
  64. data/lib/hydra/global_configurable.rb +46 -0
  65. data/lib/hydra/model_methods.rb +109 -0
  66. data/lib/hydra/model_mixins/common_metadata.rb +25 -0
  67. data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
  68. data/lib/hydra/models/file_asset.rb +76 -0
  69. data/lib/hydra/repository_controller.rb +28 -0
  70. data/lib/hydra/solr.rb +9 -0
  71. data/lib/railties/active-fedora.rake +1 -0
  72. data/lib/railties/hydra-fixtures.rake +50 -0
  73. data/lib/railties/hydra_jetty.rake +53 -0
  74. data/spec/.gitignore +1 -0
  75. data/spec/controllers/catalog_controller_spec.rb +101 -0
  76. data/spec/controllers/catalog_valid_html_spec.rb +114 -0
  77. data/spec/factories.rb +11 -0
  78. data/spec/helpers/blacklight_helper_spec.rb +15 -0
  79. data/spec/helpers/facets_helper_spec.rb +15 -0
  80. data/spec/lib/catalog_spec.rb +16 -0
  81. data/spec/lib/global_configurable_spec.rb +98 -0
  82. data/spec/lib/model_methods_spec.rb +29 -0
  83. data/spec/lib/repository_controller_behavior_spec.rb +28 -0
  84. data/spec/models/mods_asset_spec.rb +21 -0
  85. data/spec/models/solr_document_spec.rb +17 -0
  86. data/spec/models/user_spec.rb +32 -0
  87. data/spec/rcov.opts +3 -0
  88. data/spec/spec.opts +4 -0
  89. data/spec/spec_helper.rb +26 -0
  90. data/spec/support/Gemfile +12 -0
  91. data/spec/support/app/models/generic_content.rb +23 -0
  92. data/spec/support/app/models/sample.rb +33 -0
  93. data/spec/support/app/models/solr_document.rb +5 -0
  94. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  95. data/spec/support/lib/generators/test_app_generator.rb +33 -0
  96. data/spec/support/matchers/helper_matcher.rb +14 -0
  97. data/spec/support/matchers/solr_matchers.rb +60 -0
  98. data/spec/support/spec/fixtures/hydra_test_generic_content.foxml.xml +138 -0
  99. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +234 -0
  100. data/spec/unit/hydra-head-engine_spec.rb +8 -0
  101. data/spec/unit/hydra-head_spec.rb +8 -0
  102. data/tasks/hydra-head-fixtures.rake +58 -0
  103. data/tasks/hydra_jetty.rake +53 -0
  104. data/tasks/rspec.rake +53 -0
  105. metadata +469 -0
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <!--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ -->
18
+
19
+ <!--
20
+ All (relative) paths are relative to the installation path
21
+
22
+ persistent: Save changes made via the API to this file
23
+ sharedLib: path to a lib directory that will be shared across all cores
24
+ -->
25
+ <solr persistent="false" sharedLib="lib">
26
+
27
+ <!--
28
+ adminPath: RequestHandler path to manage cores.
29
+ If 'null' (or absent), cores will not be manageable via REST
30
+ -->
31
+ <cores adminPath="/admin/cores">
32
+ <core name="development" instanceDir="development-core" />
33
+ <core name="test" instanceDir="test-core" />
34
+ </cores>
35
+ </solr>
@@ -0,0 +1 @@
1
+ require 'hydra-head'
@@ -0,0 +1,27 @@
1
+ module HydraHead
2
+ require 'hydra-head/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ require 'hydra-head/routes'
4
+ require 'hydra'
5
+
6
+ def self.version
7
+ HydraHead::VERSION
8
+ end
9
+
10
+ def self.root
11
+ @root ||= File.expand_path(File.dirname(File.dirname(__FILE__)))
12
+ end
13
+
14
+ # If you put this in your application's routes.rb, it will add the Hydra Head routes to the app.
15
+ # The hydra:head generator puts this in routes.rb for you by default.
16
+ # See {HydraHead::Routes} for information about how to modify which routes are generated.
17
+ # @example
18
+ # # in config/routes.rb
19
+ # MyAppName::Application.routes.draw do
20
+ # Blacklight.add_routes(self)
21
+ # HydraHead.add_routes(self)
22
+ # end
23
+ def self.add_routes(router, options = {})
24
+ HydraHead::Routes.new(router, options).draw
25
+ end
26
+
27
+ end
@@ -0,0 +1,14 @@
1
+ require "rails"
2
+ module HydraHead
3
+ class Engine < Rails::Engine
4
+ # Config defaults
5
+ config.mount_at = '/'
6
+
7
+ # Load rake tasks
8
+ rake_tasks do
9
+ Dir.glob(File.join(File.expand_path('../', File.dirname(__FILE__)),'railties', '*.rake')).each do |railtie|
10
+ load railtie
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module HydraHead
3
+ class Routes
4
+
5
+ def initialize(router, options)
6
+ @router = router
7
+ @options = options
8
+ end
9
+
10
+ def draw
11
+ route_sets.each do |r|
12
+ self.send(r)
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def add_routes &blk
19
+ @router.instance_exec(@options, &blk)
20
+ end
21
+
22
+ def route_sets
23
+ (@options[:only] || default_route_sets) - (@options[:except] || [])
24
+ end
25
+
26
+ def default_route_sets
27
+ [:catalog, :superuser, :permissions, :assets_with_all_nested_routes]
28
+ end
29
+
30
+ module RouteSets
31
+
32
+
33
+ def assets_with_all_nested_routes
34
+ add_routes do |options|
35
+ match "withdraw", :to => "hydra/assets#withdraw", :as => "withdraw"
36
+ namespace :hydra do
37
+ resources :file_assets
38
+ resources :assets do
39
+ # this is to remove documents from SOLR but not from Fedora.
40
+ resources :contributors, :only=>[:new,:create]
41
+ match '/contributors', :to => 'contributors#update', :as => 'update_contributors'
42
+ # We would need to include the rails JS files (or implement our own) if we want this to work w/ DELETE because we delete from a link not a button.
43
+ #match 'contributors/:contributor_type/:index', :to => 'contributors#destroy', :as => 'connect', :via => 'delete'
44
+ match 'contributors/:contributor_type/:index', :to => 'contributors#destroy', :as => 'connect'
45
+ # There is no ContributorsController#show
46
+ match 'contributors/:contributor_type/:index', :to => 'contributors#show', :as => 'contributor', :via => 'get'
47
+ resources :file_assets
48
+ resources :downloads, :only=>[:index]
49
+ resources :grants, :only=>[:new,:create]
50
+ resources :permissions
51
+ # Allow updates to assets/:asset_id/permissions (no :id necessary)
52
+ match '/permissions', :to => 'permissions#update', :as => 'update_group_permissions'
53
+ end
54
+ end
55
+ match "generic_contents_object/content/:container_id", :to=>"generic_content_objects#create", :as=>'generic_content_object', :via => 'post'
56
+ end
57
+ end
58
+
59
+ def permissions
60
+ add_routes do |options|
61
+ namespace :hydra do
62
+ resources :permissions
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+ def superuser
69
+ add_routes do |options|
70
+ match 'superuser', :to => 'user_sessions#superuser', :as => 'superuser'
71
+ end
72
+ end
73
+
74
+ def catalog
75
+ add_routes do |options|
76
+ match 'catalog/:id/edit', :to => 'catalog#edit', :as => 'edit_catalog'
77
+ # The delete method renders a confirmation page with a button to submit actual destroy request
78
+ match 'catalog/:id/delete', :to => 'catalog#delete', :as => 'delete_catalog'
79
+ end
80
+ end
81
+
82
+
83
+
84
+
85
+ end
86
+ include RouteSets
87
+
88
+ #match 'generic_contents_object/content/:container_id', :to => 'generic_content_objects#create', :as => 'generic_content_object', :via => :post
89
+ end
90
+ end
@@ -0,0 +1,4 @@
1
+ module HydraHead
2
+ VERSION = "5.0.0.pre1"
3
+ end
4
+
@@ -0,0 +1,30 @@
1
+ require 'hydra-access-controls'
2
+
3
+ # Hydra libraries
4
+ module Hydra
5
+ extend ActiveSupport::Autoload
6
+ autoload :GlobalConfigurable
7
+ extend GlobalConfigurable
8
+ autoload :Catalog
9
+ autoload :Controller
10
+ autoload :ModelMethods
11
+ autoload :RepositoryController
12
+ autoload :Solr
13
+
14
+ module ModelMixins
15
+ # We can't autoload ModelMixins, because it's defined by hydra-access-controls
16
+ autoload :CommonMetadata
17
+ autoload :SolrDocumentExtension
18
+ end
19
+ module Models
20
+ extend ActiveSupport::Autoload
21
+ autoload :FileAsset
22
+ end
23
+
24
+ end
25
+
26
+ begin
27
+ SolrDocument.use_extension Hydra::ModelMixins::SolrDocumentExtension
28
+ rescue NameError
29
+ end
30
+
@@ -0,0 +1,11 @@
1
+ require 'hydra/controller/catalog_controller_behavior'
2
+ require 'deprecation'
3
+ module Hydra::Catalog
4
+ extend ActiveSupport::Concern
5
+ extend Deprecation
6
+
7
+ included do
8
+ Deprecation.warn(Hydra::Catalog, "Hydra::Catalog is deprecated and is replaced by Hydra::Controller::CatalogControllerBehavior.")
9
+ include Hydra::Controller::CatalogControllerBehavior
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # Include this module into any of your Controller classes to add Hydra functionality
2
+ #
3
+ # The primary function of this module is to mix in a number of other Hydra Modules, including
4
+ # Hydra::AccessControlsEnforcement
5
+ #
6
+ # @example
7
+ # class CustomHydraController < ApplicationController
8
+ # include Hydra::Controller
9
+ # end
10
+ #
11
+ # will move to lib/hydra/controller/controller_behavior in release 5.x
12
+ module Hydra::Controller
13
+ autoload :AssetsControllerBehavior, 'hydra/controller/assets_controller_behavior'
14
+ autoload :ControllerBehavior, 'hydra/controller/controller_behavior'
15
+ autoload :RepositoryControllerBehavior, 'hydra/controller/repository_controller_behavior'
16
+ autoload :UploadBehavior, 'hydra/controller/upload_behavior'
17
+ autoload :FileAssetsBehavior, 'hydra/controller/file_assets_behavior'
18
+
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ ActiveSupport::Deprecation.warn("Hydra::Controller has been renamed Hydra::Controller::ControllerBehavior.")
23
+ include Hydra::Controller::ControllerBehavior
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ # Include this module into any of your Controller classes to add Hydra functionality
2
+ #
3
+ # The primary function of this module is to mix in a number of other Hydra Modules, including
4
+ # Hydra::AccessControlsEnforcement
5
+ #
6
+ # @example
7
+ # class CustomHydraController < ApplicationController
8
+ # include Hydra::Controller::ControllerBehavior
9
+ # end
10
+ #
11
+ module Hydra::Controller::ControllerBehavior
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ # Other modules to auto-include
16
+ include Hydra::AccessControlsEnforcement
17
+ include Hydra::Controller::RepositoryControllerBehavior
18
+
19
+ # Catch permission errors
20
+ rescue_from Hydra::AccessDenied do |exception|
21
+ if (exception.action == :edit)
22
+ redirect_to({:action=>'show'}, :alert => exception.message)
23
+ elsif current_user and current_user.persisted?
24
+ redirect_to root_url, :alert => exception.message
25
+ else
26
+ session["user_return_to"] = request.url
27
+ redirect_to new_user_session_url, :alert => exception.message
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ # get the currently configured user identifier. Can be overridden to return whatever (ie. login, email, etc)
34
+ # defaults to using whatever you have set as the Devise authentication_key
35
+ def user_key
36
+ current_user.user_key if current_user
37
+ end
38
+
39
+ end
@@ -0,0 +1,78 @@
1
+ # Hydra::RepositoryContollerBehavior is a controller layer mixin. It is in the controller scope: request params, session etc.
2
+ #
3
+ module Hydra::Controller::RepositoryControllerBehavior
4
+
5
+ # TODO, move these to a helper file.
6
+ def self.included(c)
7
+ if c.respond_to?(:helper_method)
8
+ c.helper_method :solr_name
9
+ c.helper_method :format_pid
10
+ end
11
+ end
12
+
13
+
14
+ #
15
+ # This method converts pid strings into xhtml safe IDs, since xhmlt expects namespaces to be defined.
16
+ # I.E. hydrus:123 = hydrus_123
17
+ def format_pid(pid)
18
+ pid.gsub(":", "_")
19
+ end
20
+
21
+
22
+
23
+ def solr_name(field_name, field_type = :text)
24
+ ::ActiveFedora::SolrService.solr_name(field_name, field_type)
25
+ end
26
+
27
+
28
+ # Returns a list of datastreams for download.
29
+ # Uses user's roles and "mime_type" value in submitted params to decide what to return.
30
+ # 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)
31
+ def downloadables(fedora_object=@fedora_object, opts={})
32
+ if opts[:canonical]
33
+ mime_type = opts[:mime_type] ? opts[:mime_type] : "application/pdf"
34
+ result = filter_datastreams_for_mime_type(fedora_object.datastreams, mime_type).sort.first[1]
35
+ elsif can? :edit, fedora_object
36
+ if params["mime_type"] == "all"
37
+ result = fedora_object.datastreams
38
+ else
39
+ result = Hash[]
40
+ fedora_object.datastreams.each_pair do |dsid,ds|
41
+ if !ds.new_object?
42
+ mime_type = ds.mimeType ? ds.mimeType : ""
43
+ if mime_type.include?("pdf") || ds.label.include?("_TEXT.xml") || ds.label.include?("_METS.xml")
44
+ result[dsid] = ds
45
+ end
46
+ end
47
+ end
48
+ end
49
+ else
50
+ result = Hash[]
51
+ fedora_object.datastreams.each_pair do |dsid,ds|
52
+ if ds.mimeType.include?("pdf")
53
+ result[dsid] = ds
54
+ end
55
+ end
56
+ end
57
+ # puts "downloadables result: #{result}"
58
+ return result
59
+ end
60
+
61
+ protected
62
+ def load_document
63
+ @document = ActiveFedora::Base.find(params[:id], :cast=>true)
64
+ end
65
+
66
+ private
67
+
68
+ def filter_datastreams_for_mime_type(datastreams_hash, mime_type)
69
+ result = Hash[]
70
+ datastreams_hash.each_pair do |dsid,ds|
71
+ ds_mime_type = ds.mimeType ? ds.mimeType : ""
72
+ if ds_mime_type == mime_type
73
+ result[dsid] = ds
74
+ end
75
+ end
76
+ return result
77
+ end
78
+ end
@@ -0,0 +1,139 @@
1
+ # will move to lib/hydra/controller / upload_behavior.rb in release 5.x
2
+ module Hydra::Controller::UploadBehavior
3
+
4
+ # Creates a File Asset, adding the posted blob to the File Asset's datastreams and saves the File Asset
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
36
+
37
+ #Override this if you want to specify the datastream_id (dsID) for the created blob
38
+ def datastream_id
39
+ "content"
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
77
+ end
78
+
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
+ end