cul_scv_hydra 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/app/models/bag_aggregator.rb +16 -0
  2. data/app/models/content_aggregator.rb +16 -0
  3. data/app/models/dcdocument.rb +9 -0
  4. data/app/models/generic_aggregator.rb +16 -0
  5. data/app/models/generic_object.rb +16 -0
  6. data/app/models/jp2_image_aggregator.rb +38 -0
  7. data/app/models/mets_structured_aggregator.rb +16 -0
  8. data/app/models/resource.rb +59 -0
  9. data/app/models/static_audio_aggregator.rb +21 -0
  10. data/app/models/static_image_aggregator.rb +21 -0
  11. data/config/fedora.yml +6 -0
  12. data/config/predicate_mappings.yml +56 -0
  13. data/config/solr.yml +15 -0
  14. data/config/solr_mappings.yml +26 -0
  15. data/config/solr_value_maps.yml +29 -0
  16. data/lib/cul_scv_hydra.rb +14 -0
  17. data/lib/cul_scv_hydra/access_controls_enforcement.rb +53 -0
  18. data/lib/cul_scv_hydra/active_fedora.rb +18 -0
  19. data/lib/cul_scv_hydra/active_fedora/model.rb +8 -0
  20. data/lib/cul_scv_hydra/active_fedora/model/aggregator.rb +45 -0
  21. data/lib/cul_scv_hydra/active_fedora/model/common.rb +221 -0
  22. data/lib/cul_scv_hydra/active_fedora/model/dcdocument.rb +43 -0
  23. data/lib/cul_scv_hydra/active_fedora/model/resource.rb +79 -0
  24. data/lib/cul_scv_hydra/controllers.rb +13 -0
  25. data/lib/cul_scv_hydra/controllers/aggregates.rb +95 -0
  26. data/lib/cul_scv_hydra/controllers/aggregator_controller_helper.rb +27 -0
  27. data/lib/cul_scv_hydra/controllers/catalog.rb +13 -0
  28. data/lib/cul_scv_hydra/controllers/content_aggregators.rb +83 -0
  29. data/lib/cul_scv_hydra/controllers/datastreams.rb +146 -0
  30. data/lib/cul_scv_hydra/controllers/helpers.rb +11 -0
  31. data/lib/cul_scv_hydra/controllers/helpers/active_fedora_helper_behavior.rb +9 -0
  32. data/lib/cul_scv_hydra/controllers/helpers/application_helper_behavior.rb +17 -0
  33. data/lib/cul_scv_hydra/controllers/helpers/dc_metadata_helper_behavior.rb +9 -0
  34. data/lib/cul_scv_hydra/controllers/helpers/hydra_assets_helper_behavior.rb +46 -0
  35. data/lib/cul_scv_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb +35 -0
  36. data/lib/cul_scv_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb +34 -0
  37. data/lib/cul_scv_hydra/controllers/helpers/resources_helper_behavior.rb +160 -0
  38. data/lib/cul_scv_hydra/controllers/resources.rb +162 -0
  39. data/lib/cul_scv_hydra/controllers/static_image_aggregators.rb +106 -0
  40. data/lib/cul_scv_hydra/controllers/suggestions.rb +127 -0
  41. data/lib/cul_scv_hydra/controllers/terms.rb +152 -0
  42. data/lib/cul_scv_hydra/engine.rb +9 -0
  43. data/lib/cul_scv_hydra/om.rb +11 -0
  44. data/lib/cul_scv_hydra/om/dc_metadata.rb +70 -0
  45. data/lib/cul_scv_hydra/om/scv_mods_document.rb +132 -0
  46. data/lib/cul_scv_hydra/om/standard_mods.rb +111 -0
  47. data/lib/cul_scv_hydra/solrizer.rb +12 -0
  48. data/lib/cul_scv_hydra/solrizer/extractor.rb +27 -0
  49. data/lib/cul_scv_hydra/solrizer/field_mapper.rb +30 -0
  50. data/lib/cul_scv_hydra/solrizer/terminology_based_solrizer.rb +112 -0
  51. data/lib/cul_scv_hydra/solrizer/value_mapper.rb +35 -0
  52. data/lib/cul_scv_hydra/version.rb +10 -0
  53. metadata +333 -0
@@ -0,0 +1,27 @@
1
+ require 'active-fedora'
2
+ module Cul::Scv::Hydra::Controllers
3
+ module AggregatorControllerHelper
4
+ def load_fedora_document
5
+ if params.has_key? :asset_id
6
+ af_base = ActiveFedora::Base.load_instance(params[:asset_id])
7
+ else
8
+ af_base = ActiveFedora::Base.load_instance(params[:id])
9
+ end
10
+ the_model = ActiveFedora::ContentModel.known_models_for( af_base ).first
11
+ if the_model.nil? or the_model == ActiveFedora::Base
12
+ the_model = DcDocument
13
+ end
14
+
15
+ @document_fedora = af_base.adapt_to the_model
16
+ end
17
+ def load_resources
18
+ @document_fedora ||= load_fedora_document
19
+ if @document_fedora.is_a? Cul::Scv::Hydra::ActiveFedora::Model::Aggregator
20
+ @resources = @document_fedora.resources
21
+ else
22
+ logger.debug "Only aggregators have parts!"
23
+ end
24
+ @resources
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'cul_scv_hydra/controllers/aggregator_controller_helper'
2
+ require 'cul_scv_hydra/controllers/helpers/active_fedora_helper_behavior'
3
+ module Cul::Scv::Hydra::Controllers
4
+ module Catalog
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ include Cul::Scv::Hydra::Controllers::AggregatorControllerHelper
8
+ include Cul::Scv::Hydra::Controllers::Helpers::ActiveFedoraHelperBehavior
9
+ before_filter :require_solr, :only=>[:show, :edit, :index, :delete]
10
+ before_filter :load_resources, :only=>[:show, :edit]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,83 @@
1
+ require 'hydra'
2
+ require 'cul_scv_hydra/controllers/helpers/resources_helper_behavior'
3
+ module Cul::Scv::Hydra::Controllers
4
+ module ContentAggregators
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ include Hydra::AssetsControllerHelper
8
+ include Cul::Scv::Hydra::Controllers::Helpers::ResourcesHelperBehavior
9
+ include Hydra::RepositoryController
10
+ include MediaShelf::ActiveFedoraHelper
11
+ include Blacklight::SolrHelper
12
+ before_filter :require_solr, :only=>[:index, :new, :create, :edit, :show, :destroy]
13
+ prepend_before_filter :sanitize_update_params
14
+ end
15
+
16
+ def index
17
+ if params[:layout] == "false"
18
+ # action = "index_embedded"
19
+ layout = false
20
+ end
21
+ if !params[:container_id].nil?
22
+ container_uri = "info:fedora/#{params[:container_id]}"
23
+ escaped_uri = container_uri.gsub(/(:)/, '\\:')
24
+ extra_controller_params = {:q=>"cul_member_of_s:#{escaped_uri}"}
25
+ @response, @document_list = get_search_results( extra_controller_params )
26
+
27
+ # Including this line so permissions tests can be run against the container
28
+ @container_response, @document = get_solr_response_for_doc_id(params[:container_id])
29
+
30
+ # Including these lines for backwards compatibility (until we can use Rails3 callbacks)
31
+ @container = ActiveFedora::Base.load_instance(params[:container_id])
32
+ @solr_result = @container.file_objects(:response_format=>:solr)
33
+ else
34
+ # @solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_field:info\:fedora/ldpd\:Resource', @search_params)
35
+ @solr_result = Resource.find_by_solr(:all)
36
+ end
37
+ render :action=>params[:action], :layout=>layout
38
+ end
39
+
40
+ def new
41
+ @asset = ContentAggregator.new
42
+ apply_depositor_metadata(@asset)
43
+ set_collection_type(@asset, params[:content_type])
44
+ if !params[:container_id].nil?
45
+ associate_resource_with_container(@asset, params[:container_id])
46
+ end
47
+ @asset.save
48
+ msg = "Created a Content Aggregator with pid #{@asset.pid}. Now it's ready to be edited."
49
+ flash[:notice]= msg
50
+
51
+ session[:scripts] = params[:combined] == "true"
52
+ redirect_to url_for(:action=>"edit", :id=>@asset.pid, :new_asset=>true, :controller=>'catalog')
53
+
54
+ end
55
+
56
+ # Common destroy method for all AssetsControllers
57
+ def destroy
58
+ # The correct implementation, with garbage collection:
59
+ # if params.has_key?(:container_id)
60
+ # container = ActiveFedora::Base.load_instance(params[:container_id])
61
+ # container.file_objects_remove(params[:id])
62
+ # FileAsset.garbage_collect(params[:id])
63
+ # else
64
+
65
+ # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
66
+ ActiveFedora::Base.load_instance(params[:id]).delete
67
+ render :text => "Deleted #{params[:id]} from #{params[:container_id]}."
68
+ end
69
+
70
+
71
+ def show
72
+ @image_agg = ContentAggregator.find(params[:id])
73
+ if (@image_agg.nil?)
74
+ logger.warn("No such object: " + params[:id])
75
+ flash[:notice]= "No such object."
76
+ redirect_to(:action => 'index', :q => nil , :f => nil)
77
+ else
78
+ @id_array = @image_agg.containers(:response_format => :id_array)
79
+ end
80
+ render :action=>params[:action], :layout=>(params[:layout]=="false")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,146 @@
1
+ require 'cul_scv_hydra/controllers/helpers/application_helper_behavior'
2
+ module Cul::Scv::Hydra::Controllers
3
+ module Datastreams
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ include Cul::Scv::Hydra::Controllers::Helpers::ApplicationHelperBehavior
8
+ include Hydra::AssetsControllerHelper
9
+ include Hydra::AssetsControllerHelper
10
+ include Hydra::FileAssetsHelper
11
+ include Hydra::RepositoryController
12
+ include MediaShelf::ActiveFedoraHelper
13
+ include Blacklight::SolrHelper
14
+ before_filter :require_solr, :only=>[:index, :create, :show, :destroy]
15
+ prepend_before_filter :sanitize_update_params
16
+ end
17
+
18
+ def index
19
+ if params[:layout] == "false"
20
+ # action = "index_embedded"
21
+ layout = false
22
+ end
23
+ unless params[:asset_id].nil?
24
+
25
+ # Including this line so permissions tests can be run against the container
26
+ @container_response, @document = get_solr_response_for_doc_id(params[:asset_id])
27
+
28
+ # Including these lines for backwards compatibility (until we can use Rails3 callbacks)
29
+ @container = ActiveFedora::Base.load_instance(params[:asset_id])
30
+ @ds = @container.datastreams(params[:id])
31
+ else
32
+ # What are we doing here without a containing object?
33
+ raise "called DatastreamsController#index without containing object"
34
+ end
35
+ render :action=>params[:action], :layout=>layout
36
+ end
37
+
38
+ def new
39
+ render :partial=>"new", :layout=>false
40
+ end
41
+
42
+ # Creates and Saves a Datastream to contain the the Uploaded file
43
+ def create
44
+ if params[:asset_id].nil?
45
+ raise "Cannot created a datastream without a containing object"
46
+ else
47
+ @container = ActiveFedora::Base.load_instance(params[:asset_id])
48
+ end
49
+
50
+ if params[:id].nil?
51
+ raise "Cannot created a datastream without a datastream id"
52
+ end
53
+
54
+ if params.has_key?(:Filedata)
55
+ file_name = filename_from_params
56
+ mime_type = params[:mime_type] || mime_type(file_name)
57
+ @container.add_file_datastream(posted_file, :dsid=>params[:id], :label=>file_name, :mimeType=>mime_type, :size=>posted_file.size)
58
+ @container.save
59
+ # apply_depositor_metadata(@file_asset)
60
+
61
+ flash[:notice] = "The file #{params[:Filename]} has been saved as #{params[:datastream_id]} in <a href=\"#{asset_url(@container.pid)}\">#{@container.pid}</a>."
62
+
63
+ ## Apply any posted file metadata
64
+ unless params[:asset].nil?
65
+ # logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
66
+ # apply_file_metadata
67
+ end
68
+ # If redirect_params has not been set, use {:action=>:index}
69
+ logger.debug "Created #{@container.pid}##{params[:datastream_id]}."
70
+ elsif params.has_key?(:Source)
71
+ file_name = filename_from_url(params[:Source])
72
+ mime_type = params[:mime_type] || mime_type(file_name)
73
+ ds_props = {:dsid=>params[:id], :label=>file_name, :mimeType=>mime_type, :dsLocation=>params[:Source]}
74
+ @container.add_datastream(ActiveFedora::Datastream.new(ds_props))
75
+ @container.save
76
+
77
+ flash[:notice] = "#{params[:Source]} has been saved as #{params[:datastream_id]} in <a href=\"#{asset_url(@container.pid)}\">#{@container.pid}</a>."
78
+ else
79
+ flash[:notice] = "You must specify a file to upload or a source URL."
80
+ end
81
+
82
+ unless params[:container_id].nil?
83
+ redirect_params = {:controller=>"catalog", :id=>params[:asset_id], :action=>:edit}
84
+ end
85
+
86
+ redirect_params ||= {:action=>:index}
87
+
88
+ redirect_to redirect_params
89
+ end
90
+
91
+ # Datastream destroy method
92
+ def destroy
93
+ @container = ActiveFedora::Base.load_instance(params[:asset_id])
94
+ @container.datastreams[params[:datastream_id]].delete
95
+ render :text => "Deleted #{params[:datastream_id]} from #{params[:asset_id]}."
96
+ # Does the index need to be updated on delete here?
97
+ @container.save
98
+ end
99
+
100
+ def update
101
+ self.create
102
+ end
103
+
104
+ def show
105
+ @container = ActiveFedora::Base.find(params[:asset_id])
106
+ if (@container.nil?)
107
+ logger.warn("No such fedora object: " + params[:asset_id])
108
+ flash[:notice]= "No such fedora object."
109
+ redirect_to(:action => 'index', :q => nil , :f => nil)
110
+ return
111
+ else
112
+ # get array of parent (container) objects for this FileAsset
113
+ @downloadable = false
114
+ # A FileAsset is downloadable iff the user has read or higher access to a parent
115
+ @response, @document = get_solr_response_for_doc_id(params[:asset_id])
116
+ if reader?
117
+ @downloadable = true
118
+ end
119
+
120
+ if @downloadable
121
+ if @container.datastreams_in_memory.include?(params[:id])
122
+ ds = @container.datastreams_in_memory[params[:id]]
123
+ opts = {:filename => ds.label}
124
+ if params[:mime_type].nil?
125
+ opts[:type] = ds.attributes["mimeType"]
126
+ else
127
+ opts[:type] = params[:mime_type]
128
+ end
129
+ if params[:disposition].nil?
130
+ opts[:disposition] = "attachment"
131
+ else
132
+ opts[:disposition] = params[:disposition]
133
+ end
134
+ logger.debug opts.inspect
135
+ send_data ds.content, opts
136
+ return
137
+ end
138
+ else
139
+ flash[:notice]= "You do not have sufficient access privileges to download this document, which has been marked private."
140
+ redirect_to(:action => 'index', :q => nil , :f => nil)
141
+ return
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,11 @@
1
+ module Cul::Scv::Hydra::Controllers
2
+ module Helpers
3
+ end
4
+ end
5
+ require 'cul_scv_hydra/controllers/helpers/active_fedora_helper_behavior.rb'
6
+ require 'cul_scv_hydra/controllers/helpers/application_helper_behavior.rb'
7
+ require 'cul_scv_hydra/controllers/helpers/dc_metadata_helper_behavior.rb'
8
+ require 'cul_scv_hydra/controllers/helpers/hydra_assets_helper_behavior.rb'
9
+ require 'cul_scv_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb'
10
+ require 'cul_scv_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb'
11
+ require 'cul_scv_hydra/controllers/helpers/resources_helper_behavior.rb'
@@ -0,0 +1,9 @@
1
+ module Cul::Scv::Hydra::Controllers::Helpers
2
+ module ActiveFedoraHelperBehavior
3
+ def load_dc_document_from_solr(doc)
4
+ pid = doc[:id] ? doc[:id] : doc[:id.to_s]
5
+ result = pid ? Cul::Scv::Hydra::ActiveFedora::Model::DcDocument.load_instance_from_solr(pid,doc) : nil
6
+ result
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'cul_scv_hydra/active_fedora/model/dcdocument'
2
+ # Methods added to this helper will be available to all templates in the application.
3
+ module Cul::Scv::Hydra::Controllers::Helpers
4
+ module ApplicationHelperBehavior
5
+ def load_dc_document_from_solr(doc)
6
+ pid = doc[:id] ? doc[:id] : doc[:id.to_s]
7
+ result = pid ? Cul::Scv::Hydra::ActiveFedora::Model::DcDocument.load_instance_from_solr(pid,doc) : nil
8
+ result
9
+ end
10
+ def get_aggregate_count(doc)
11
+ count = 0
12
+ obj = load_dc_document_from_solr(doc)
13
+ count += obj.parts.length unless obj.nil?
14
+ count
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Cul::Scv::Hydra::Controllers::Helpers
2
+ module DcMetadataHelperBehavior
3
+ def dcmi_types
4
+ ['', 'Collection', 'Dataset', 'Event', 'Image', 'InteractiveResource',
5
+ 'MovingImage', 'PhysicalObject', 'Service', 'Software', 'Sound',
6
+ 'StillImage', 'Text']
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ require 'mediashelf/active_fedora_helper'
2
+
3
+ module Cul::Scv::Hydra::Controllers::Helpers::HydraAssetsHelperBehavior
4
+ include MediaShelf::ActiveFedoraHelper
5
+
6
+ def link_to_create_asset(link_label, content_type, container_id=nil)
7
+ opts = {:action => 'new', :controller => "#{content_type}s", :content_type => content_type}
8
+ opts[:container_id] = container_id unless container_id.nil?
9
+ if current_user
10
+ link_to link_label, opts, :class=>"create_asset"
11
+ else
12
+ link_to link_label, {:action => 'new', :controller => 'user_sessions', :redirect_params => opts}, :class=>"create_asset"
13
+ end
14
+ end
15
+
16
+ def get_file_asset_description(document)
17
+ obj = load_af_instance_from_solr(document)
18
+ if obj.nil? || obj.file_objects.empty?
19
+ return ""
20
+ else
21
+ fobj = Resource.load_instance_from_solr(obj.file_objects.first.pid)
22
+ fad = ""
23
+ unless fobj.nil?
24
+ unless fobj.datastreams["descMetadata"].nil?
25
+ fad = short_description(fobj.datastreams["descMetadata"].get_values("description").first)
26
+ else
27
+ fad = short_description(fobj.datastreams["DC"].get_values("description").first)
28
+ end
29
+ end
30
+ fad
31
+ end
32
+ end
33
+
34
+ def apply_depositor_metadata(user, is_public=false)
35
+ if self.is_a? ActiveFedora::Base
36
+ rights_md = self.datastreams['rightsMetadata']
37
+ if rights_md
38
+ rights_md.permissions({"person"=>user}, "edit")
39
+ rights_md.permissions({"person"=>user}, "read")
40
+ if is_public
41
+ rights_md.permissions({"group"=>"public"}, "read")
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Cul::Scv::Hydra::Controllers::Helpers
2
+ module HydraAutocompleteHelperBehavior
3
+ def autocomplete_fedora_text_field(resource, datastream_name, field_key, opts={})
4
+ field_name = field_name_for(field_key)
5
+ field_values = get_values_from_datastream(resource, datastream_name, field_key, opts)
6
+ field_values = [""] if field_values.empty?
7
+ field_values = [field_values.first] unless opts.fetch(:multiple, true)
8
+ required = opts.fetch(:required, true) ? "required" : ""
9
+ body = ""
10
+ field_values.each_with_index do |current_value, z|
11
+ base_id = generate_base_id(field_name, current_value, field_values, opts)
12
+ name = "asset[#{datastream_name}][#{field_name}][#{z}]"
13
+ body << "<input class=\"editable-edit edit autocomplete\" id=\"#{base_id}\" data-datastream-name=\"#{datastream_name}\" name=\"#{name}\" value=\"#{h(current_value.strip)}\" #{required} type=\"text\" />"
14
+ body << "<a href=\"\" title=\"Delete '#{h(current_value)}'\" class=\"destructive field\">Delete</a>" if opts.fetch(:multiple, true) && !current_value.empty?
15
+ end
16
+ result = field_selectors_for(datastream_name, field_key)
17
+ result << body
18
+ return body
19
+ end
20
+ def field_name_for(field_key)
21
+ if field_key.kind_of?(Array)
22
+ return OM::XML::Terminology.pointers_to_flat_array(field_key, true).join("__")
23
+ else
24
+ return field_key.to_s
25
+ end
26
+ end
27
+ def generate_base_id(field_name, current_value, values, opts)
28
+ if opts.fetch(:multiple, true)
29
+ return field_name+"__"+values.index(current_value).to_s
30
+ else
31
+ return field_name
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ module Cul::Scv::Hydra::Controllers::Helpers
2
+ module HydraUploaderHelperBehavior
3
+
4
+ # Generate the appropriate url for posting uploads to
5
+ # Uses the +container_id+ method to figure out what container uploads should go into
6
+ def upload_url(in_place=false)
7
+ if in_place
8
+ upload_url = asset_datastream_path(:asset_id=>container_id, :id=>'CONTENT')
9
+ else
10
+ upload_url = asset_resources_path(:container_id=>container_id)
11
+ end
12
+ end
13
+
14
+ def asset_id
15
+ if !params[:asset_id].nil?
16
+ return params[:asset_id]
17
+ else
18
+ return params[:id]
19
+ end
20
+ end
21
+
22
+ # The id of the container that uploads should be posted into
23
+ # If params[:container_id] is not set, it uses params[:id] (assumes that you're uploading items into the current object)
24
+ def container_id
25
+ if !params[:container_id].nil?
26
+ return params[:container_id]
27
+ elsif !params[:asset_id].nil?
28
+ return params[:asset_id]
29
+ else
30
+ return params[:id]
31
+ end
32
+ end
33
+ end
34
+ end