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,160 @@
1
+ require 'hydra'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'tempfile'
5
+ require 'uri'
6
+ module Cul::Scv::Hydra::Controllers::Helpers
7
+ module ResourcesHelperBehavior
8
+ IMAGE_MIME_TYPES = [
9
+ 'image/bmp',
10
+ 'image/gif',
11
+ 'image/jpeg',
12
+ 'image/png',
13
+ 'image/tiff'
14
+ ]
15
+
16
+ # Creates a Resource, adding the posted blob to the Resource's datastreams and saves the Resource
17
+ #
18
+ # @return [Resource] the Resource
19
+ def create_and_save_resources_from_params
20
+ if params.has_key?(:Fileurl)
21
+ # parse url for file name, default to index.html
22
+ file_url = params[:Fileurl]
23
+ file_url = URI.parse(file_url) unless file_url.nil?
24
+ file_name = 'index.html'
25
+ if file_url.scheme
26
+ file_name = file_url.path[1...file_url.path.length]
27
+ end
28
+ # download resource; override file name with header value if present
29
+ blob = Tempfile.new('temp')
30
+ blob.binmode
31
+ # download header? buffered writing?
32
+ response = Net::HTTP.get_response(file_url)
33
+ blob.write response.body
34
+ if response['Content-Disposition']
35
+ header = response['Content-Disposition']
36
+ if header =~ /filename=\"?(\w+)\"?/
37
+ file_name = $1
38
+ end
39
+ end
40
+ # add filename and resource to params
41
+ params[:Filedata] = [ActionDispatch::Http::UploadedFile.new(:tempfile=>blob,:filename=>file_name,:type=>mime_type(file_name))]
42
+ end
43
+ if params.has_key?(:Filedata)
44
+ @resources = []
45
+ params[:Filedata].each do |file|
46
+ file.content_type = mime_type(file.original_filename) unless file.content_type
47
+ @resource = create_resource_from_file(file)
48
+ @resource.save
49
+ @resources << @resource
50
+ @resource.refresh
51
+ add_posted_blob_to_resource(file, @resource)
52
+ @resource.save
53
+ end
54
+ else
55
+ render :text => "400 Bad Request", :status => 400
56
+ end
57
+ @resources
58
+ end
59
+
60
+ def update_resource_from_params
61
+ if params.has_key?(:Fileurl)
62
+ # parse url for file name, default to index.html
63
+ file_url = params[:Fileurl]
64
+ file_url = URI.parse(file_url) unless file_url.nil?
65
+ file_name = 'index.html'
66
+ if file_url.scheme
67
+ file_name = file_url.path[1...file_url.path.length]
68
+ end
69
+ # download resource; override file name with header value if present
70
+ blob = Tempfile.new('temp')
71
+ blob.binmode
72
+ # download header? buffered writing?
73
+ response = Net::HTTP.get_response(file_url)
74
+ blob.write response.body
75
+ if response['Content-Disposition']
76
+ header = response['Content-Disposition']
77
+ if header =~ /filename=\"?(\w+)\"?/
78
+ file_name = $1
79
+ end
80
+ end
81
+ # add filename and resource to params
82
+ params[:Filedata] = ActionDispatch::Http::UploadedFile.new(:tempfile=>blob,:filename=>file_name,:type=>mime_type(file_name))
83
+ end
84
+ if params.has_key?(:Filedata)
85
+ file = params[:Filedata]
86
+ file.content_type = mime_type(file.original_filename) unless file.content_type
87
+ update_resource_from_file(@document_fedora,file)
88
+ add_posted_blob_to_resource(file, @document_fedora)
89
+ @document_fedora.save
90
+ else
91
+ render :text => "400 Bad Request", :status => 400
92
+ end
93
+ @document_fedora
94
+ end
95
+ def update_resource_from_file(resource,file)
96
+ file_name = filename_for(file)
97
+ resource.label = file_name
98
+ resource.datastreams["DC"].update_values([:source=>0]=>[file_name])
99
+ resource
100
+ end
101
+ def create_resource_from_file(file)
102
+ resource = Resource.new
103
+ resource.datastreams["rightsMetadata"].ng_xml = Hydra::RightsMetadata.xml_template
104
+ update_resource_from_file(resource,file)
105
+ end
106
+
107
+ # Puts the contents of params[:Filedata] (posted blob) into a datastream within the given @resource
108
+ # Sets resource label and title to filename if they're empty
109
+ #
110
+ # @param [Resource] the Resource to add the blob to
111
+ # @return [Resource] the Resource
112
+ def add_posted_blob_to_resource(file, resource=@resource)
113
+ resource.add_content_blob(file.tempfile, :file_name=>file.original_filename, :mime_type=>file.content_type)
114
+ end
115
+
116
+ # Associate the new file resource with its container
117
+ def associate_resource_with_container(resource=@resource, container_id=nil)
118
+ if container_id.nil?
119
+ container_id = params[:container_id]
120
+ end
121
+ container_id = "info:fedora/#{container_id}" unless container_id =~ /info:fedora\/.+/
122
+ resource.containers_append(container_id)
123
+ resource.datastreams["RELS-EXT"].dirty = true
124
+ end
125
+
126
+ def remove_resource_from_container(resource=nil, container_id=nil)
127
+ if container_id.nil?
128
+ container_id = params[:container_id]
129
+ end
130
+ if resource.nil?
131
+ resource = @resource
132
+ end
133
+ resource.containers_remove(container_id)
134
+ #resource.remove_relationship(:cul_member_of, container_id)
135
+ resource.datastreams["RELS-EXT"].dirty = true
136
+ end
137
+
138
+ # Apply any posted file metadata to the file asset
139
+ def apply_posted_file_metadata(resource=@resource)
140
+ @metadata_update_response = update_document(resource, @sanitized_params)
141
+ end
142
+
143
+
144
+ # A best-guess filename
145
+ # If Filename was submitted, it uses that. Otherwise, it calls +original_filename+ on the posted file
146
+ def filename_for(file)
147
+ file.instance_variable_get(:@original_filename) || file.original_filename
148
+ end
149
+
150
+ private
151
+ # Return the mimeType for a given file name
152
+ # @param [String] file_name The filename to use to get the mimeType
153
+ # @return [String] mimeType for filename passed in. Default: application/octet-stream if mimeType cannot be determined
154
+ def mime_type file_name
155
+ mime_types = MIME::Types.of(file_name)
156
+ mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
157
+ end
158
+
159
+ end
160
+ end
@@ -0,0 +1,162 @@
1
+ module Cul::Scv::Hydra::Controllers
2
+ module Resources
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Hydra::AssetsControllerHelper
7
+ include Cul::Scv::Hydra::Controllers::Helpers::ResourcesHelperBehavior
8
+ include Hydra::Controller
9
+ include Hydra::RepositoryController
10
+ include MediaShelf::ActiveFedoraHelper
11
+ include Blacklight::SolrHelper
12
+ before_filter :require_solr, :only=>[:index, :create, :show, :destroy]
13
+ before_filter :load_fedora_document, :only=>[:update]
14
+ prepend_before_filter :sanitize_update_params
15
+ end
16
+
17
+ def index
18
+ if params[:layout] == "false"
19
+ # action = "index_embedded"
20
+ layout = false
21
+ end
22
+ if !params[:container_id].nil?
23
+ container_uri = "info:fedora/#{params[:container_id]}"
24
+ escaped_uri = container_uri.gsub(/(:)/, '\\:')
25
+ extra_controller_params = {:q=>"cul_member_of_s:#{escaped_uri}"}
26
+ @response, @document_list = get_search_results( extra_controller_params )
27
+
28
+ # Including this line so permissions tests can be run against the container
29
+ @container_response, @document = get_solr_response_for_doc_id(params[:container_id])
30
+
31
+ # Including these lines for backwards compatibility (until we can use Rails3 callbacks)
32
+ @container = ActiveFedora::Base.load_instance(params[:container_id])
33
+ @solr_result = @container.file_objects(:response_format=>:solr)
34
+ else
35
+ # @solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_field:info\:fedora/ldpd\:Resource', @search_params)
36
+ @solr_result = Resource.find_by_solr(:all)
37
+ end
38
+ render :action=>params[:action], :layout=>layout
39
+ end
40
+
41
+ def new
42
+ render :partial=>"new", :layout=>false
43
+ end
44
+
45
+ # Creates and Saves a File Asset to contain the the Uploaded file
46
+ # If container_id is provided:
47
+ # * the File Asset will use RELS-EXT to assert that it's a part of the specified container
48
+ # * the method will redirect to the container object's edit view after saving
49
+ def create
50
+ if params.has_key?(:Filedata) or params.has_key?(:Fileurl)
51
+ flash[:notice] = process_files # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>."
52
+ else
53
+ flash[:notice] = "You must specify a file to upload."
54
+ end
55
+
56
+ if !params[:container_id].nil?
57
+ redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit}
58
+ end
59
+
60
+ redirect_params ||= {:action=>:index}
61
+
62
+ redirect_to redirect_params
63
+ end
64
+
65
+ def update
66
+ if params.has_key?(:Filedata) or params.has_key?(:Fileurl)
67
+ flash[:notice] = update_file # "The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@resource.pid)}\">#{@resource.pid}</a>."
68
+ else
69
+ flash[:notice] = "You must specify a file to upload."
70
+ end
71
+ if !params[:id].nil?
72
+ redirect_params = {:controller=>"catalog", :id=>params[:id], :action=>:edit}
73
+ end
74
+
75
+ redirect_params ||= {:action=>:index}
76
+
77
+ redirect_to redirect_params
78
+ end
79
+
80
+ def process_files
81
+ @resources = create_and_save_resources_from_params
82
+ notice = []
83
+ @resources.each do |resource|
84
+ apply_depositor_metadata(resource)
85
+ notice << "The file #{resource.label} has been saved in <a href=\"#{asset_url(resource.pid)}\">#{resource.pid}</a>."
86
+ if !params[:container_id].nil?
87
+ associate_resource_with_container(resource,params[:container_id])
88
+ end
89
+ ## Apply any posted file metadata
90
+ unless params[:asset].nil?
91
+ logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
92
+ apply_posted_file_metadata(resource)
93
+ end
94
+ resource.save
95
+ logger.debug("Created #{resource.pid}.")
96
+ end
97
+ end
98
+
99
+ def update_file
100
+ update_resource_from_params
101
+ apply_depositor_metadata(@document_fedora)
102
+ notice << "The file #{@document_fedora.label} has been saved in <a href=\"#{asset_url(@document_fedora.pid)}\">#{@document_fedora.pid}</a>."
103
+ unless params[:asset].nil?
104
+ logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
105
+ apply_posted_file_metadata(@document_fedora)
106
+ end
107
+ @document_fedora.save
108
+ logger.debug("Created #{@document_fedora.pid}.")
109
+ end
110
+ # Common destroy method for all AssetsControllers
111
+ def destroy
112
+ # The correct implementation, with garbage collection:
113
+ # if params.has_key?(:container_id)
114
+ # container = ActiveFedora::Base.load_instance(params[:container_id])
115
+ # container.file_objects_remove(params[:id])
116
+ # FileAsset.garbage_collect(params[:id])
117
+ # else
118
+
119
+ # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
120
+ ActiveFedora::Base.load_instance(params[:id]).delete
121
+ flash[:notice] = "Deleted #{params[:id]}."
122
+ if !params[:container_id].nil?
123
+ redirect_params = {:controller=>"catalog", :id=>params[:container_id], :action=>:edit}
124
+ end
125
+
126
+ redirect_params ||= {:action=>:index}
127
+
128
+ redirect_to redirect_params
129
+ end
130
+
131
+
132
+ def show
133
+ @file_asset = Resource.find(params[:id])
134
+ if (@file_asset.nil?)
135
+ logger.warn("No such resource: " + params[:id])
136
+ flash[:notice]= "No such resource."
137
+ redirect_to(:action => 'index', :q => nil , :f => nil)
138
+ else
139
+ # get array of parent (container) objects for this FileAsset
140
+ @id_array = @file_asset.containers(:response_format => :id_array)
141
+ @downloadable = false
142
+ # A FileAsset is downloadable iff the user has read or higher access to a parent
143
+ @id_array.each do |pid|
144
+ @response, @document = get_solr_response_for_doc_id(pid)
145
+ if reader?
146
+ @downloadable = true
147
+ break
148
+ end
149
+ end
150
+
151
+ if @downloadable
152
+ if @file_asset.datastreams_in_memory.include?("CONTENT")
153
+ send_datastream @file_asset.datastreams_in_memory["CONTENT"]
154
+ end
155
+ else
156
+ flash[:notice]= "You do not have sufficient access privileges to download this document, which has been marked private."
157
+ redirect_to(:action => 'index', :q => nil , :f => nil)
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,106 @@
1
+ require 'cul_scv_hydra/controllers/helpers/resources_helper_behavior'
2
+ module Cul::Scv::Hydra::Controllers
3
+ module StaticImageAggregators
4
+ extend ActiveSupport::Concern
5
+
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_fedora
13
+ before_filter :require_solr, :only=>[:index, :new, :create, :edit, :show, :destroy]
14
+ prepend_before_filter :sanitize_update_params
15
+ end
16
+
17
+ def index
18
+ if params[:layout] == "false"
19
+ # action = "index_embedded"
20
+ layout = false
21
+ end
22
+ if !params[:container_id].nil?
23
+ container_uri = "info:fedora/#{params[:container_id]}"
24
+ escaped_uri = container_uri.gsub(/(:)/, '\\:')
25
+ extra_controller_params = {:q=>"cul_member_of_s:#{escaped_uri}"}
26
+ @response, @document_list = get_search_results( extra_controller_params )
27
+
28
+ # Including this line so permissions tests can be run against the container
29
+ @container_response, @document = get_solr_response_for_doc_id(params[:container_id])
30
+
31
+ # Including these lines for backwards compatibility (until we can use Rails3 callbacks)
32
+ @container = ActiveFedora::Base.load_instance(params[:container_id])
33
+ @solr_result = @container.file_objects(:response_format=>:solr)
34
+ else
35
+ # @solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_field:info\:fedora/ldpd\:Resource', @search_params)
36
+ @solr_result = Resource.find_by_solr(:all)
37
+ end
38
+ render :action=>params[:action], :layout=>layout
39
+ end
40
+
41
+ def new
42
+ @asset = StaticImageAggregator.new
43
+ apply_depositor_metadata(@asset)
44
+ set_collection_type(@asset, params[:content_type])
45
+ if !params[:container_id].nil?
46
+ associate_resource_with_container(@asset, params[:container_id])
47
+ end
48
+ @asset.save
49
+ @asset.refresh
50
+ msg = "Created a Static Image Aggregator with pid #{@asset.pid}. Now it's ready to be edited."
51
+ flash[:notice]= msg
52
+
53
+ if params.has_key?(:Filedata)
54
+ @file_asset = create_and_save_resource_from_params
55
+ apply_depositor_metadata(@file_asset)
56
+
57
+ flash[:notice] += " The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@file_asset.pid)}\">#{@file_asset.pid}</a>."
58
+
59
+ if !params[:container_id].nil?
60
+ associate_resource_with_container(@file_asset, @asset.pid)
61
+ end
62
+
63
+ ## Apply any posted file metadata
64
+ unless params[:asset].nil?
65
+ logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
66
+ @metadata_update_response = update_document(@file_asset, @sanitized_params)
67
+ end
68
+ @file_asset.save
69
+ # If redirect_params has not been set, use {:action=>:index}
70
+ logger.debug "Created #{@file_asset.pid}."
71
+ end
72
+ @asset.save
73
+
74
+ session[:scripts] = params[:combined] == "true"
75
+ redirect_to url_for(:action=>"edit", :id=>@asset.pid, :new_asset=>true, :controller=>'catalog')
76
+
77
+ end
78
+
79
+ # Common destroy method for all AssetsControllers
80
+ def destroy
81
+ # The correct implementation, with garbage collection:
82
+ # if params.has_key?(:container_id)
83
+ # container = ActiveFedora::Base.load_instance(params[:container_id])
84
+ # container.file_objects_remove(params[:id])
85
+ # FileAsset.garbage_collect(params[:id])
86
+ # else
87
+
88
+ # The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
89
+ ActiveFedora::Base.load_instance(params[:id]).delete
90
+ render :text => "Deleted #{params[:id]} from #{params[:container_id]}."
91
+ end
92
+
93
+
94
+ def show
95
+ @image_agg = StaticImageAggregator.find(params[:id])
96
+ if (@image_agg.nil?)
97
+ logger.warn("No such object: " + params[:id])
98
+ flash[:notice]= "No such object."
99
+ redirect_to(:action => 'index', :q => nil , :f => nil)
100
+ else
101
+ @id_array = @image_agg.containers(:response_format => :id_array)
102
+ end
103
+ render :action=>params[:action], :layout=>(params[:layout]=="false")
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,127 @@
1
+ require 'cul_scv_hydra'
2
+ require 'json'
3
+ module Cul::Scv::Hydra::Controllers
4
+ module Suggestions
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ include Blacklight::SolrHelper
8
+ include MediaShelf::ActiveFedoraHelper
9
+ before_filter :require_solr, :only=>[:index]
10
+ end
11
+
12
+ def index
13
+ stub = params[:term] || ""
14
+ if params[:term_id].nil?
15
+ raise "Cannot provide suggestions without a term name"
16
+ end
17
+ field_name = params[:term_id]
18
+ field_key = field_key_from(field_name, Cul::Scv::Hydra::Om::ModsDocument.terminology)
19
+ solr_name = get_solr_name(field_key, Cul::Scv::Hydra::Om::ModsDocument)
20
+ solr_params = {}
21
+ solr_params['wt'] = 'json'
22
+ solr_params['terms'] = 'true'
23
+ solr_params['terms.fl'] = solr_name
24
+ solr_params['terms.lower'] = stub
25
+ solr_params['terms.lower.incl'] = false
26
+ solr_params['terms.prefix'] = stub
27
+ solr_params['terms.sort'] = 'index'
28
+ solr_response = Blacklight.solr.get 'terms', {:params => solr_params}
29
+ result = []
30
+ hash = {}
31
+ (1...solr_response['terms'].length).step(2) { |ix|
32
+ solr_response['terms'][ix].each { |val|
33
+ result << val if val.is_a? String
34
+ }
35
+ }
36
+ send_data result.to_json, :disposition => 'inline', :type => 'text/plain'
37
+ return
38
+ end
39
+
40
+ ## field_key_from(field_name) to reverse this method from HydraFedoraMetadataHelper
41
+ # def field_name_for(field_key)
42
+ # if field_key.kind_of?(Array)
43
+ # return OM::XML::Terminology.term_hierarchical_name(*field_key)
44
+ # else
45
+ # field_key.to_s
46
+ # end
47
+ # end
48
+
49
+ def field_key_from(field_name, terminology)
50
+ # this is a hack, but necessary until/unless OM generates names differently
51
+ candidates = field_name.split('__')
52
+ field_key = []
53
+ candidates.each_with_index { |candidate, ix|
54
+ if (candidates[ix + 1] and candidates[ix + 1].match(/\d+/))
55
+ field_key << {OM.destringify(candidate) => Integer(candidates.delete_at(ix + 1))}
56
+ else
57
+ field_key << OM.destringify(candidate)
58
+ end
59
+ }
60
+ logger.debug field_key.inspect
61
+ field_key
62
+ end
63
+
64
+ # ** largely copied from ActiveFedora::NokogiriDatastream.get_values **
65
+ def get_solr_name(term_pointer, dsClass)
66
+ term = dsClass.terminology.retrieve_term(*OM.pointers_to_flat_array(term_pointer, false))
67
+ names = []
68
+ if is_hierarchical_term_pointer?(*term_pointer)
69
+ bases = []
70
+ #add first item in term_pointer as start of bases
71
+ # then iterate through possible nodes that might exist
72
+ term_pointer.first.kind_of?(Hash) ? bases << term_pointer.first.keys.first : bases << term_pointer.first
73
+ for i in 1..(term_pointer.length-1)
74
+ #iterate in reverse so that we can modify the bases array while iterating
75
+ (bases.length-1).downto(0) do |j|
76
+ current_last = (term_pointer[i].kind_of?(Hash) ? term_pointer[i].keys.first : term_pointer[i])
77
+ if (term_pointer[i-1].kind_of?(Hash))
78
+ #just use index supplied instead of trying possibilities
79
+ index = term_pointer[i-1].values.first
80
+ solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
81
+ solr_name = generate_solr_symbol(solr_name_base, term.data_type)
82
+ bases.delete_at(j)
83
+ #insert the new solr name base if found
84
+ bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
85
+ else
86
+ #detect how many nodes exist
87
+ index = 0
88
+ current_base = bases[j]
89
+ bases.delete_at(j)
90
+ solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
91
+ solr_name = generate_solr_symbol(solr_name_base, term.data_type)
92
+ bases.insert(j,solr_name_base)
93
+ end
94
+ end
95
+ end
96
+ bases.each do |base|
97
+ names << generate_solr_symbol(base.to_sym, term.data_type)
98
+ end
99
+ else
100
+ #this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
101
+ generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
102
+ names << generate_solr_symbol(generic_field_name_base, term.data_type)
103
+ end
104
+ names
105
+ end
106
+
107
+ # ** copied from ActiveFedora::NokogiriDatastream **
108
+ #@return true if the term_pointer contains an index
109
+ # ====Example:
110
+ # [:image, {:title_set=>1}, :title] return true
111
+ # [:image, :title_set, :title] return false
112
+ def is_hierarchical_term_pointer?(*term_pointer)
113
+ if term_pointer.length>1
114
+ term_pointer.each do |pointer|
115
+ if pointer.kind_of?(Hash)
116
+ return true
117
+ end
118
+ end
119
+ end
120
+ return false
121
+ end
122
+ # ** copied from ActiveFedora::NokogiriDatastream **
123
+ def generate_solr_symbol(base, data_type)
124
+ Solrizer::XML::TerminologyBasedSolrizer.default_field_mapper.solr_name(base.to_sym, data_type)
125
+ end
126
+ end
127
+ end