cul_hydra 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/cul/hydra/application_id_behavior.rb +5 -6
  3. data/app/models/administrative_set.rb +0 -1
  4. data/app/models/concept.rb +0 -1
  5. data/app/models/concerns/cul/hydra/models.rb +1 -0
  6. data/app/models/concerns/cul/hydra/models/common.rb +8 -9
  7. data/app/models/concerns/cul/hydra/models/rels_int.rb +18 -0
  8. data/app/models/concerns/ore/proxy.rb +2 -3
  9. data/app/models/cul/hydra/datastreams/rels_int.rb +179 -0
  10. data/app/models/dc_document.rb +0 -1
  11. data/app/models/generic_aggregator.rb +0 -1
  12. data/app/models/generic_object.rb +0 -1
  13. data/app/models/generic_resource.rb +1 -3
  14. data/fixtures/spec/CUL_RELS_INT/rels_int_blank.xml +2 -0
  15. data/fixtures/spec/CUL_RELS_INT/rels_int_profile.xml +19 -0
  16. data/fixtures/spec/CUL_RELS_INT/rels_int_test.xml +12 -0
  17. data/fixtures/spec/FOXML/resource-thumb.xml +2 -1
  18. data/lib/cul_hydra.rb +1 -4
  19. data/lib/cul_hydra/rels_int.rb +9 -0
  20. data/lib/cul_hydra/rels_int/rdf_xml_writer.rb +33 -0
  21. data/lib/cul_hydra/version.rb +1 -1
  22. data/lib/tasks/cul_hydra_dev.rake +0 -28
  23. metadata +32 -58
  24. data/app/models/jp2_image_aggregator.rb +0 -34
  25. data/app/models/mets_structured_aggregator.rb +0 -18
  26. data/app/models/resource.rb +0 -78
  27. data/app/models/resource_aggregator.rb +0 -22
  28. data/app/models/static_audio_aggregator.rb +0 -12
  29. data/app/models/static_image_aggregator.rb +0 -32
  30. data/lib/cul_hydra/controllers.rb +0 -14
  31. data/lib/cul_hydra/controllers/aggregates.rb +0 -93
  32. data/lib/cul_hydra/controllers/aggregator_controller_helper.rb +0 -27
  33. data/lib/cul_hydra/controllers/catalog.rb +0 -12
  34. data/lib/cul_hydra/controllers/collections.rb +0 -81
  35. data/lib/cul_hydra/controllers/content_aggregators.rb +0 -81
  36. data/lib/cul_hydra/controllers/datastreams.rb +0 -145
  37. data/lib/cul_hydra/controllers/helpers.rb +0 -10
  38. data/lib/cul_hydra/controllers/helpers/active_fedora_helper_behavior.rb +0 -9
  39. data/lib/cul_hydra/controllers/helpers/application_helper_behavior.rb +0 -16
  40. data/lib/cul_hydra/controllers/helpers/dc_metadata_helper_behavior.rb +0 -9
  41. data/lib/cul_hydra/controllers/helpers/hydra_assets_helper_behavior.rb +0 -46
  42. data/lib/cul_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb +0 -35
  43. data/lib/cul_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb +0 -34
  44. data/lib/cul_hydra/controllers/helpers/resources_helper_behavior.rb +0 -159
  45. data/lib/cul_hydra/controllers/resources.rb +0 -161
  46. data/lib/cul_hydra/controllers/static_image_aggregators.rb +0 -105
  47. data/lib/cul_hydra/controllers/suggestions.rb +0 -126
  48. data/lib/cul_hydra/controllers/terms.rb +0 -205
@@ -1,10 +0,0 @@
1
- module Cul::Hydra::Controllers::Helpers
2
- autoload :Aggregates, 'cul_hydra/controllers/helpers/aggregates'
3
- autoload :ActiveFedoraHelperBehavior, 'cul_hydra/controllers/helpers/active_fedora_helper_behavior'
4
- autoload :ApplicationHelperBehavior, 'cul_hydra/controllers/helpers/application_helper_behavior'
5
- autoload :DcMetadataHelperBehavior, 'cul_hydra/controllers/helpers/dc_metadata_helper_behavior'
6
- autoload :HydraAssetsHelperBehavior, 'cul_hydra/controllers/helpers/hydra_assets_helper_behavior'
7
- autoload :HydraAutocompleteHelperBehavior, 'cul_hydra/controllers/helpers/hydra_autocomplete_helper_behavior'
8
- autoload :HydraUploaderHelperBehavior, 'cul_hydra/controllers/helpers/hydra_uploader_helper_behavior'
9
- autoload :ResourcesHelperBehavior, 'cul_hydra/controllers/helpers/resources_helper_behavior'
10
- end
@@ -1,9 +0,0 @@
1
- module Cul::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 ? DcDocument.load_instance_from_solr(pid,doc) : nil
6
- result
7
- end
8
- end
9
- end
@@ -1,16 +0,0 @@
1
- # Methods added to this helper will be available to all templates in the application.
2
- module Cul::Hydra::Controllers::Helpers
3
- module ApplicationHelperBehavior
4
- def load_dc_document_from_solr(doc)
5
- pid = doc[:id] ? doc[:id] : doc[:id.to_s]
6
- result = pid ? DcDocument.load_instance_from_solr(pid,doc) : nil
7
- result
8
- end
9
- def get_aggregate_count(doc)
10
- count = 0
11
- obj = load_dc_document_from_solr(doc)
12
- count += obj.parts.length unless obj.nil?
13
- count
14
- end
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- module Cul::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
@@ -1,46 +0,0 @@
1
- #require 'mediashelf/active_fedora_helper'
2
-
3
- module Cul::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
@@ -1,35 +0,0 @@
1
- module Cul::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
@@ -1,34 +0,0 @@
1
- module Cul::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
@@ -1,159 +0,0 @@
1
- require 'net/http'
2
- require 'open-uri'
3
- require 'tempfile'
4
- require 'uri'
5
- module Cul::Hydra::Controllers::Helpers
6
- module ResourcesHelperBehavior
7
- IMAGE_MIME_TYPES = [
8
- 'image/bmp',
9
- 'image/gif',
10
- 'image/jpeg',
11
- 'image/png',
12
- 'image/tiff'
13
- ]
14
-
15
- # Creates a Resource, adding the posted blob to the Resource's datastreams and saves the Resource
16
- #
17
- # @return [Resource] the Resource
18
- def create_and_save_resources_from_params
19
- if params.has_key?(:Fileurl)
20
- # parse url for file name, default to index.html
21
- file_url = params[:Fileurl]
22
- file_url = URI.parse(file_url) unless file_url.nil?
23
- file_name = 'index.html'
24
- if file_url.scheme
25
- file_name = file_url.path[1...file_url.path.length]
26
- end
27
- # download resource; override file name with header value if present
28
- blob = Tempfile.new('temp')
29
- blob.binmode
30
- # download header? buffered writing?
31
- response = Net::HTTP.get_response(file_url)
32
- blob.write response.body
33
- if response['Content-Disposition']
34
- header = response['Content-Disposition']
35
- if header =~ /filename=\"?(\w+)\"?/
36
- file_name = $1
37
- end
38
- end
39
- # add filename and resource to params
40
- params[:Filedata] = [ActionDispatch::Http::UploadedFile.new(:tempfile=>blob,:filename=>file_name,:type=>mime_type(file_name))]
41
- end
42
- if params.has_key?(:Filedata)
43
- @resources = []
44
- params[:Filedata].each do |file|
45
- file.content_type = mime_type(file.original_filename) unless file.content_type
46
- @resource = create_resource_from_file(file)
47
- @resource.save
48
- @resources << @resource
49
- @resource.refresh
50
- add_posted_blob_to_resource(file, @resource)
51
- @resource.save
52
- end
53
- else
54
- render :text => "400 Bad Request", :status => 400
55
- end
56
- @resources
57
- end
58
-
59
- def update_resource_from_params
60
- if params.has_key?(:Fileurl)
61
- # parse url for file name, default to index.html
62
- file_url = params[:Fileurl]
63
- file_url = URI.parse(file_url) unless file_url.nil?
64
- file_name = 'index.html'
65
- if file_url.scheme
66
- file_name = file_url.path[1...file_url.path.length]
67
- end
68
- # download resource; override file name with header value if present
69
- blob = Tempfile.new('temp')
70
- blob.binmode
71
- # download header? buffered writing?
72
- response = Net::HTTP.get_response(file_url)
73
- blob.write response.body
74
- if response['Content-Disposition']
75
- header = response['Content-Disposition']
76
- if header =~ /filename=\"?(\w+)\"?/
77
- file_name = $1
78
- end
79
- end
80
- # add filename and resource to params
81
- params[:Filedata] = ActionDispatch::Http::UploadedFile.new(:tempfile=>blob,:filename=>file_name,:type=>mime_type(file_name))
82
- end
83
- if params.has_key?(:Filedata)
84
- file = params[:Filedata]
85
- file.content_type = mime_type(file.original_filename) unless file.content_type
86
- update_resource_from_file(@document_fedora,file)
87
- add_posted_blob_to_resource(file, @document_fedora)
88
- @document_fedora.save
89
- else
90
- render :text => "400 Bad Request", :status => 400
91
- end
92
- @document_fedora
93
- end
94
- def update_resource_from_file(resource,file)
95
- file_name = filename_for(file)
96
- resource.label = file_name
97
- resource.datastreams["DC"].update_values([:source=>0]=>[file_name])
98
- resource
99
- end
100
- def create_resource_from_file(file)
101
- resource = Resource.new
102
- resource.datastreams["rightsMetadata"].ng_xml = Hydra::RightsMetadata.xml_template
103
- update_resource_from_file(resource,file)
104
- end
105
-
106
- # Puts the contents of params[:Filedata] (posted blob) into a datastream within the given @resource
107
- # Sets resource label and title to filename if they're empty
108
- #
109
- # @param [Resource] the Resource to add the blob to
110
- # @return [Resource] the Resource
111
- def add_posted_blob_to_resource(file, resource=@resource)
112
- resource.add_content_blob(file.tempfile, :file_name=>file.original_filename, :mime_type=>file.content_type)
113
- end
114
-
115
- # Associate the new file resource with its container
116
- def associate_resource_with_container(resource=@resource, container_id=nil)
117
- if container_id.nil?
118
- container_id = params[:container_id]
119
- end
120
- container_id = "info:fedora/#{container_id}" unless container_id =~ /info:fedora\/.+/
121
- resource.containers_append(container_id)
122
- resource.datastreams["RELS-EXT"].dirty = true
123
- end
124
-
125
- def remove_resource_from_container(resource=nil, container_id=nil)
126
- if container_id.nil?
127
- container_id = params[:container_id]
128
- end
129
- if resource.nil?
130
- resource = @resource
131
- end
132
- resource.containers_remove(container_id)
133
- #resource.remove_relationship(:cul_member_of, container_id)
134
- resource.datastreams["RELS-EXT"].dirty = true
135
- end
136
-
137
- # Apply any posted file metadata to the file asset
138
- def apply_posted_file_metadata(resource=@resource)
139
- @metadata_update_response = update_document(resource, @sanitized_params)
140
- end
141
-
142
-
143
- # A best-guess filename
144
- # If Filename was submitted, it uses that. Otherwise, it calls +original_filename+ on the posted file
145
- def filename_for(file)
146
- file.instance_variable_get(:@original_filename) || file.original_filename
147
- end
148
-
149
- private
150
- # Return the mimeType for a given file name
151
- # @param [String] file_name The filename to use to get the mimeType
152
- # @return [String] mimeType for filename passed in. Default: application/octet-stream if mimeType cannot be determined
153
- def mime_type file_name
154
- mime_types = MIME::Types.of(file_name)
155
- mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
156
- end
157
-
158
- end
159
- end
@@ -1,161 +0,0 @@
1
- module Cul::Hydra::Controllers
2
- module Resources
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- include Hydra::AssetsControllerHelper
7
- include Cul::Hydra::Controllers::Helpers::ResourcesHelperBehavior
8
- include Hydra::Controller
9
- include Hydra::RepositoryController
10
- include MediaShelf::ActiveFedoraHelper
11
- include Blacklight::SolrHelper
12
- before_filter :load_fedora_document, :only=>[:update]
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
- render :partial=>"new", :layout=>false
42
- end
43
-
44
- # Creates and Saves a File Asset to contain the the Uploaded file
45
- # If container_id is provided:
46
- # * the File Asset will use RELS-EXT to assert that it's a part of the specified container
47
- # * the method will redirect to the container object's edit view after saving
48
- def create
49
- if params.has_key?(:Filedata) or params.has_key?(:Fileurl)
50
- flash[:notice] = process_files # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>."
51
- else
52
- flash[:notice] = "You must specify a file to upload."
53
- end
54
-
55
- if !params[:container_id].nil?
56
- redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit}
57
- end
58
-
59
- redirect_params ||= {:action=>:index}
60
-
61
- redirect_to redirect_params
62
- end
63
-
64
- def update
65
- if params.has_key?(:Filedata) or params.has_key?(:Fileurl)
66
- flash[:notice] = update_file # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>."
67
- else
68
- flash[:notice] = "You must specify a file to upload."
69
- end
70
- if !params[:id].nil?
71
- redirect_params = {:controller=>"catalog", :id=>params[:id], :action=>:edit}
72
- end
73
-
74
- redirect_params ||= {:action=>:index}
75
-
76
- redirect_to redirect_params
77
- end
78
-
79
- def process_files
80
- @resources = create_and_save_resources_from_params
81
- notice = []
82
- @resources.each do |resource|
83
- apply_depositor_metadata(resource)
84
- notice << "The file #{resource.label} has been saved in <a href=\"#{asset_url(resource.pid)}\">#{resource.pid}</a>."
85
- if !params[:container_id].nil?
86
- associate_resource_with_container(resource,params[:container_id])
87
- end
88
- ## Apply any posted file metadata
89
- unless params[:asset].nil?
90
- logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
91
- apply_posted_file_metadata(resource)
92
- end
93
- resource.save
94
- logger.debug("Created #{resource.pid}.")
95
- end
96
- end
97
-
98
- def update_file
99
- update_resource_from_params
100
- apply_depositor_metadata(@document_fedora)
101
- notice << "The file #{@document_fedora.label} has been saved in <a href=\"#{asset_url(@document_fedora.pid)}\">#{@document_fedora.pid}</a>."
102
- unless params[:asset].nil?
103
- logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
104
- apply_posted_file_metadata(@document_fedora)
105
- end
106
- @document_fedora.save
107
- logger.debug("Created #{@document_fedora.pid}.")
108
- end
109
- # Common destroy method for all AssetsControllers
110
- def destroy
111
- # The correct implementation, with garbage collection:
112
- # if params.has_key?(:container_id)
113
- # container = ActiveFedora::Base.load_instance(params[:container_id])
114
- # container.file_objects_remove(params[:id])
115
- # FileAsset.garbage_collect(params[:id])
116
- # else
117
-
118
- # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
119
- ActiveFedora::Base.load_instance(params[:id]).delete
120
- flash[:notice] = "Deleted #{params[:id]}."
121
- if !params[:container_id].nil?
122
- redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit}
123
- end
124
-
125
- redirect_params ||= {:action=>:index}
126
-
127
- redirect_to redirect_params
128
- end
129
-
130
-
131
- def show
132
- @file_asset = Resource.find(params[:id])
133
- if (@file_asset.nil?)
134
- logger.warn("No such resource: " + params[:id])
135
- flash[:notice]= "No such resource."
136
- redirect_to(:action => 'index', :q => nil , :f => nil)
137
- else
138
- # get array of parent (container) objects for this FileAsset
139
- @id_array = @file_asset.containers(:response_format => :id_array)
140
- @downloadable = false
141
- # A FileAsset is downloadable iff the user has read or higher access to a parent
142
- @id_array.each do |pid|
143
- @response, @document = get_solr_response_for_doc_id(pid)
144
- if reader?
145
- @downloadable = true
146
- break
147
- end
148
- end
149
-
150
- if @downloadable
151
- if @file_asset.datastreams_in_memory.include?("CONTENT")
152
- send_datastream @file_asset.datastreams_in_memory["CONTENT"]
153
- end
154
- else
155
- flash[:notice]= "You do not have sufficient access privileges to download this document, which has been marked private."
156
- redirect_to(:action => 'index', :q => nil , :f => nil)
157
- end
158
- end
159
- end
160
- end
161
- end