cul_hydra 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/images/cul_hydra/crystal/binary.png +0 -0
- data/app/assets/images/cul_hydra/crystal/document.png +0 -0
- data/app/assets/images/cul_hydra/crystal/file.png +0 -0
- data/app/assets/images/cul_hydra/crystal/file_broken.png +0 -0
- data/app/assets/images/cul_hydra/crystal/folder_documents.png +0 -0
- data/app/assets/images/cul_hydra/crystal/folder_images.png +0 -0
- data/app/assets/images/cul_hydra/crystal/folder_music.png +0 -0
- data/app/assets/images/cul_hydra/crystal/folder_sound.png +0 -0
- data/app/assets/images/cul_hydra/crystal/folder_video.png +0 -0
- data/app/assets/images/cul_hydra/crystal/kmultiple.png +0 -0
- data/app/assets/images/cul_hydra/crystal/knotify.png +0 -0
- data/app/assets/images/cul_hydra/crystal/mp3.png +0 -0
- data/app/assets/images/cul_hydra/crystal/multimedia2.png +0 -0
- data/app/assets/images/cul_hydra/crystal/video.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/application.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/code.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/css.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/db.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/directory.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/doc.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/file.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/film.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/flash.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/folder_open.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/html.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/java.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/linux.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/music.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/pdf.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/php.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/picture.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/ppt.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/psd.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/ruby.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/script.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/spinner.gif +0 -0
- data/app/assets/images/cul_hydra/filesystem/txt.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/xls.png +0 -0
- data/app/assets/images/cul_hydra/filesystem/zip.png +0 -0
- data/app/controllers/concerns/cul/hydra/application_id_behavior.rb +43 -0
- data/app/controllers/concerns/cul/hydra/controller.rb +22 -0
- data/app/controllers/concerns/cul/hydra/resolver.rb +69 -0
- data/app/controllers/concerns/cul/hydra/thumbnails.rb +62 -0
- data/app/helpers/cul/hydra/ore_proxies_helper_behavior.rb +119 -0
- data/app/helpers/cul/hydra/struct_metadata_helper_behavior.rb +89 -0
- data/app/models/bag_aggregator.rb +7 -0
- data/app/models/concept.rb +23 -0
- data/app/models/concerns/cul/hydra/models.rb +24 -0
- data/app/models/concerns/cul/hydra/models/aggregator.rb +121 -0
- data/app/models/concerns/cul/hydra/models/common.rb +220 -0
- data/app/models/concerns/cul/hydra/models/image_resource.rb +106 -0
- data/app/models/concerns/cul/hydra/models/linkable_resources.rb +108 -0
- data/app/models/concerns/cul/hydra/models/resource.rb +87 -0
- data/app/models/concerns/nfo/common.rb +17 -0
- data/app/models/concerns/nfo/file_data_object.rb +10 -0
- data/app/models/concerns/nfo/folder.rb +10 -0
- data/app/models/concerns/nie/information_element.rb +10 -0
- data/app/models/concerns/ore/proxy.rb +124 -0
- data/app/models/concerns/rdf/cul.rb +77 -0
- data/app/models/concerns/rdf/fcrepo3.rb +360 -0
- data/app/models/concerns/rdf/nfo.rb +807 -0
- data/app/models/concerns/rdf/nie.rb +338 -0
- data/app/models/concerns/rdf/olo.rb +100 -0
- data/app/models/concerns/rdf/ore.rb +101 -0
- data/app/models/concerns/rdf/pimo.rb +605 -0
- data/app/models/concerns/rdf/sc.rb +47 -0
- data/app/models/concerns/sc/canvas.rb +12 -0
- data/app/models/concerns/sc/sequence.rb +21 -0
- data/app/models/content_aggregator.rb +3 -0
- data/app/models/cul/hydra/datastreams/dc_metadata.rb +107 -0
- data/app/models/cul/hydra/datastreams/mods_document.rb +195 -0
- data/app/models/cul/hydra/datastreams/struct_metadata.rb +176 -0
- data/app/models/dc_document.rb +39 -0
- data/app/models/generic_aggregator.rb +68 -0
- data/app/models/generic_object.rb +18 -0
- data/app/models/generic_resource.rb +210 -0
- data/app/models/jp2_image_aggregator.rb +34 -0
- data/app/models/mets_structured_aggregator.rb +18 -0
- data/app/models/resource.rb +78 -0
- data/app/models/resource_aggregator.rb +22 -0
- data/app/models/static_audio_aggregator.rb +12 -0
- data/app/models/static_image_aggregator.rb +32 -0
- data/bin/rails +12 -0
- data/config/fedora.yml +17 -0
- data/config/jetty.yml +6 -0
- data/config/locales/ldpd_hydra.en.yml +125 -0
- data/config/predicate_mappings.yml +79 -0
- data/config/solr.yml +8 -0
- data/config/solr_mappings.yml +26 -0
- data/config/solr_value_maps.yml +41 -0
- data/config/subs.yml +17 -0
- data/fixtures/cmodels/ldpd_ADLMetadata.xml +56 -0
- data/fixtures/cmodels/ldpd_AESMetadata.xml +56 -0
- data/fixtures/cmodels/ldpd_BagAggregator.xml +70 -0
- data/fixtures/cmodels/ldpd_Concept.xml +69 -0
- data/fixtures/cmodels/ldpd_ContentAggregator.xml +70 -0
- data/fixtures/cmodels/ldpd_DynamicAggregator.xml +56 -0
- data/fixtures/cmodels/ldpd_JP2ImageAggregator.xml +60 -0
- data/fixtures/cmodels/ldpd_METSMetadata.xml +56 -0
- data/fixtures/cmodels/ldpd_METSStructuredAggregator.xml +53 -0
- data/fixtures/cmodels/ldpd_MODSMetadata.xml +73 -0
- data/fixtures/cmodels/ldpd_MostRecent.xml +46 -0
- data/fixtures/cmodels/ldpd_PTIFImageAggregator.xml +63 -0
- data/fixtures/cmodels/ldpd_Resource.xml +72 -0
- data/fixtures/cmodels/ldpd_RestrictedResource.xml +54 -0
- data/fixtures/cmodels/ldpd_Since.xml +62 -0
- data/fixtures/cmodels/ldpd_StaticAudioAggregator.xml +54 -0
- data/fixtures/cmodels/ldpd_StaticImageAggregator.xml +71 -0
- data/fixtures/cmodels/ldpd_htest.xml +54 -0
- data/fixtures/cmodels/ldpd_nullbind.xml +63 -0
- data/fixtures/cmodels/ldpd_sdef.Aggregator.xml +71 -0
- data/fixtures/cmodels/ldpd_sdef.Core.xml +48 -0
- data/fixtures/cmodels/ldpd_sdef.Image.xml +47 -0
- data/fixtures/cmodels/ldpd_sdef.Metadata.xml +62 -0
- data/fixtures/cmodels/ldpd_sdef.Resource.xml +76 -0
- data/fixtures/cmodels/ldpd_sdef.ZoomingImage.xml +46 -0
- data/fixtures/cmodels/ldpd_sdep.BagAggregator.xml +160 -0
- data/fixtures/cmodels/ldpd_sdep.BagAggregatorCore.xml +221 -0
- data/fixtures/cmodels/ldpd_sdep.ContentAggregatorCore.xml +221 -0
- data/fixtures/cmodels/ldpd_sdep.DynamicAggregator.xml +171 -0
- data/fixtures/cmodels/ldpd_sdep.DynamicAggregatorCore.xml +215 -0
- data/fixtures/cmodels/ldpd_sdep.JP2Image.xml +220 -0
- data/fixtures/cmodels/ldpd_sdep.JP2ImageAggregator.xml +167 -0
- data/fixtures/cmodels/ldpd_sdep.JP2ImageCore.xml +229 -0
- data/fixtures/cmodels/ldpd_sdep.MODSMetadata.xml +158 -0
- data/fixtures/cmodels/ldpd_sdep.MODSMetadataCore.xml +227 -0
- data/fixtures/cmodels/ldpd_sdep.PTIFImage.xml +222 -0
- data/fixtures/cmodels/ldpd_sdep.PTIFImageAggregator.xml +167 -0
- data/fixtures/cmodels/ldpd_sdep.PTIFImageCore.xml +215 -0
- data/fixtures/cmodels/ldpd_sdep.StaticImage.xml +210 -0
- data/fixtures/cmodels/ldpd_sdep.StaticImageAggregator.xml +186 -0
- data/fixtures/cmodels/ldpd_sdep.StaticImageCore.xml +220 -0
- data/fixtures/cmodels/ore_Proxy.xml +50 -0
- data/fixtures/spec/BLOB/test001.jpg +0 -0
- data/fixtures/spec/CUL_DC/dc.xml +5 -0
- data/fixtures/spec/CUL_MODS/mods-001.xml +25 -0
- data/fixtures/spec/CUL_MODS/mods-all.xml +65 -0
- data/fixtures/spec/CUL_MODS/mods-bad-repo.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-created-range.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-created-single.xml +6 -0
- data/fixtures/spec/CUL_MODS/mods-date-end-with-all-u-characters.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-issued-range.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-issued-single.xml +6 -0
- data/fixtures/spec/CUL_MODS/mods-date-other-range.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-other-single.xml +6 -0
- data/fixtures/spec/CUL_MODS/mods-date-range-short-years.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-date-start-with-all-u-characters.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-dates-with-all-u-characters.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-dates-with-some-u-characters.xml +7 -0
- data/fixtures/spec/CUL_MODS/mods-item.xml +31 -0
- data/fixtures/spec/CUL_MODS/mods-names.xml +35 -0
- data/fixtures/spec/CUL_MODS/mods-notes.xml +8 -0
- data/fixtures/spec/CUL_MODS/mods-ns.xml +2 -0
- data/fixtures/spec/CUL_MODS/mods-origin-info.xml +9 -0
- data/fixtures/spec/CUL_MODS/mods-part.xml +22 -0
- data/fixtures/spec/CUL_MODS/mods-physical-description.xml +12 -0
- data/fixtures/spec/CUL_MODS/mods-physical-location.xml +9 -0
- data/fixtures/spec/CUL_MODS/mods-record-info.xml +4 -0
- data/fixtures/spec/CUL_MODS/mods-relateditem-project.xml +8 -0
- data/fixtures/spec/CUL_MODS/mods-subjects.xml +73 -0
- data/fixtures/spec/CUL_MODS/mods-textual-date.xml +8 -0
- data/fixtures/spec/CUL_MODS/mods-titles.xml +33 -0
- data/fixtures/spec/CUL_MODS/mods-top-level-location-vs-relateditem-location.xml +21 -0
- data/fixtures/spec/CUL_MODS/mods-unmapped-project.xml +7 -0
- data/fixtures/spec/CUL_SOLR/mods-001.xml +1 -0
- data/fixtures/spec/CUL_SOLR/mods-001.yml +30 -0
- data/fixtures/spec/FOXML/content-aggregator.xml +64 -0
- data/fixtures/spec/FOXML/content-cmodel.xml +48 -0
- data/fixtures/spec/FOXML/image-cmodel.xml +48 -0
- data/fixtures/spec/FOXML/resource-max.xml +83 -0
- data/fixtures/spec/FOXML/resource-screen.xml +273 -0
- data/fixtures/spec/FOXML/resource-thumb.xml +86 -0
- data/fixtures/spec/FOXML/static-image-aggregator.xml +31 -0
- data/fixtures/spec/STRUCTMAP/structmap-examples.xml +21 -0
- data/fixtures/spec/STRUCTMAP/structmap-nested.xml +10 -0
- data/fixtures/spec/STRUCTMAP/structmap-recto.xml +4 -0
- data/fixtures/spec/STRUCTMAP/structmap-seq.xml +5 -0
- data/fixtures/spec/STRUCTMAP/structmap-unordered-seq.xml +5 -0
- data/lib/cul_hydra.rb +20 -0
- data/lib/cul_hydra/access_controls_enforcement.rb +53 -0
- data/lib/cul_hydra/controllers.rb +13 -0
- data/lib/cul_hydra/controllers/aggregates.rb +93 -0
- data/lib/cul_hydra/controllers/aggregator_controller_helper.rb +27 -0
- data/lib/cul_hydra/controllers/catalog.rb +12 -0
- data/lib/cul_hydra/controllers/content_aggregators.rb +81 -0
- data/lib/cul_hydra/controllers/datastreams.rb +145 -0
- data/lib/cul_hydra/controllers/helpers.rb +10 -0
- data/lib/cul_hydra/controllers/helpers/active_fedora_helper_behavior.rb +9 -0
- data/lib/cul_hydra/controllers/helpers/application_helper_behavior.rb +16 -0
- data/lib/cul_hydra/controllers/helpers/dc_metadata_helper_behavior.rb +9 -0
- data/lib/cul_hydra/controllers/helpers/hydra_assets_helper_behavior.rb +46 -0
- data/lib/cul_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb +35 -0
- data/lib/cul_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb +34 -0
- data/lib/cul_hydra/controllers/helpers/resources_helper_behavior.rb +159 -0
- data/lib/cul_hydra/controllers/resources.rb +161 -0
- data/lib/cul_hydra/controllers/static_image_aggregators.rb +105 -0
- data/lib/cul_hydra/controllers/suggestions.rb +126 -0
- data/lib/cul_hydra/controllers/terms.rb +205 -0
- data/lib/cul_hydra/engine.rb +31 -0
- data/lib/cul_hydra/fedora.rb +41 -0
- data/lib/cul_hydra/fedora/dummy_object.rb +37 -0
- data/lib/cul_hydra/fedora/rubydora_patch.rb +16 -0
- data/lib/cul_hydra/fedora/url_helper_behavior.rb +32 -0
- data/lib/cul_hydra/indexer.rb +102 -0
- data/lib/cul_hydra/om.rb +7 -0
- data/lib/cul_hydra/om/standard_mods.rb +115 -0
- data/lib/cul_hydra/risearch_members.rb +92 -0
- data/lib/cul_hydra/solrizer.rb +10 -0
- data/lib/cul_hydra/solrizer/extractor.rb +27 -0
- data/lib/cul_hydra/solrizer/mods_fieldable.rb +473 -0
- data/lib/cul_hydra/solrizer/terminology_based_solrizer.rb +35 -0
- data/lib/cul_hydra/solrizer/value_mapper.rb +46 -0
- data/lib/cul_hydra/solrizer_patch.rb +172 -0
- data/lib/cul_hydra/version.rb +8 -0
- data/lib/cul_hydra/version.rb~ +8 -0
- data/lib/tasks/cmodel.rake +122 -0
- data/lib/tasks/cul_hydra_dev.rake +54 -0
- data/lib/tasks/index.rake +73 -0
- data/lib/tasks/transform.rake +23 -0
- metadata +503 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'cul_hydra/controllers/helpers/resources_helper_behavior'
|
2
|
+
module Cul::Hydra::Controllers
|
3
|
+
module StaticImageAggregators
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Hydra::AssetsControllerHelper
|
8
|
+
include Cul::Hydra::Controllers::Helpers::ResourcesHelperBehavior
|
9
|
+
include Hydra::RepositoryController
|
10
|
+
include MediaShelf::ActiveFedoraHelper
|
11
|
+
include Blacklight::SolrHelper
|
12
|
+
before_filter :require_fedora
|
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 = StaticImageAggregator.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
|
+
@asset.refresh
|
49
|
+
msg = "Created a Static Image Aggregator with pid #{@asset.pid}. Now it's ready to be edited."
|
50
|
+
flash[:notice]= msg
|
51
|
+
|
52
|
+
if params.has_key?(:Filedata)
|
53
|
+
@file_asset = create_and_save_resource_from_params
|
54
|
+
apply_depositor_metadata(@file_asset)
|
55
|
+
|
56
|
+
flash[:notice] += " The file #{params[:Filename]} has been saved in <a href=\"#{asset_url(@file_asset.pid)}\">#{@file_asset.pid}</a>."
|
57
|
+
|
58
|
+
if !params[:container_id].nil?
|
59
|
+
associate_resource_with_container(@file_asset, @asset.pid)
|
60
|
+
end
|
61
|
+
|
62
|
+
## Apply any posted file metadata
|
63
|
+
unless params[:asset].nil?
|
64
|
+
logger.debug("applying submitted file metadata: #{@sanitized_params.inspect}")
|
65
|
+
@metadata_update_response = update_document(@file_asset, @sanitized_params)
|
66
|
+
end
|
67
|
+
@file_asset.save
|
68
|
+
# If redirect_params has not been set, use {:action=>:index}
|
69
|
+
logger.debug "Created #{@file_asset.pid}."
|
70
|
+
end
|
71
|
+
@asset.save
|
72
|
+
|
73
|
+
session[:scripts] = params[:combined] == "true"
|
74
|
+
redirect_to url_for(:action=>"edit", :id=>@asset.pid, :new_asset=>true, :controller=>'catalog')
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
# Common destroy method for all AssetsControllers
|
79
|
+
def destroy
|
80
|
+
# The correct implementation, with garbage collection:
|
81
|
+
# if params.has_key?(:container_id)
|
82
|
+
# container = ActiveFedora::Base.load_instance(params[:container_id])
|
83
|
+
# container.file_objects_remove(params[:id])
|
84
|
+
# FileAsset.garbage_collect(params[:id])
|
85
|
+
# else
|
86
|
+
|
87
|
+
# The dirty implementation (leaves relationship in container object, deletes regardless of whether the file object has other containers)
|
88
|
+
ActiveFedora::Base.load_instance(params[:id]).delete
|
89
|
+
render :text => "Deleted #{params[:id]} from #{params[:container_id]}."
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def show
|
94
|
+
@image_agg = StaticImageAggregator.find(params[:id])
|
95
|
+
if (@image_agg.nil?)
|
96
|
+
logger.warn("No such object: " + params[:id])
|
97
|
+
flash[:notice]= "No such object."
|
98
|
+
redirect_to(:action => 'index', :q => nil , :f => nil)
|
99
|
+
else
|
100
|
+
@id_array = @image_agg.containers(:response_format => :id_array)
|
101
|
+
end
|
102
|
+
render :action=>params[:action], :layout=>(params[:layout]=="false")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'cul_hydra'
|
2
|
+
require 'json'
|
3
|
+
module Cul::Hydra::Controllers
|
4
|
+
module Suggestions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
include Blacklight::SolrHelper
|
8
|
+
include MediaShelf::ActiveFedoraHelper
|
9
|
+
end
|
10
|
+
|
11
|
+
def index
|
12
|
+
stub = params[:term] || ""
|
13
|
+
if params[:term_id].nil?
|
14
|
+
raise "Cannot provide suggestions without a term name"
|
15
|
+
end
|
16
|
+
field_name = params[:term_id]
|
17
|
+
field_key = field_key_from(field_name, Cul::Hydra::Om::ModsDocument.terminology)
|
18
|
+
solr_name = get_solr_name(field_key, Cul::Hydra::Om::ModsDocument)
|
19
|
+
solr_params = {}
|
20
|
+
solr_params['wt'] = 'json'
|
21
|
+
solr_params['terms'] = 'true'
|
22
|
+
solr_params['terms.fl'] = solr_name
|
23
|
+
solr_params['terms.lower'] = stub
|
24
|
+
solr_params['terms.lower.incl'] = false
|
25
|
+
solr_params['terms.prefix'] = stub
|
26
|
+
solr_params['terms.sort'] = 'index'
|
27
|
+
solr_response = Blacklight.solr.get 'terms', {:params => solr_params}
|
28
|
+
result = []
|
29
|
+
hash = {}
|
30
|
+
(1...solr_response['terms'].length).step(2) { |ix|
|
31
|
+
solr_response['terms'][ix].each { |val|
|
32
|
+
result << val if val.is_a? String
|
33
|
+
}
|
34
|
+
}
|
35
|
+
send_data result.to_json, :disposition => 'inline', :type => 'text/plain'
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
## field_key_from(field_name) to reverse this method from HydraFedoraMetadataHelper
|
40
|
+
# def field_name_for(field_key)
|
41
|
+
# if field_key.kind_of?(Array)
|
42
|
+
# return OM::XML::Terminology.term_hierarchical_name(*field_key)
|
43
|
+
# else
|
44
|
+
# field_key.to_s
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
def field_key_from(field_name, terminology)
|
49
|
+
# this is a hack, but necessary until/unless OM generates names differently
|
50
|
+
candidates = field_name.split('__')
|
51
|
+
field_key = []
|
52
|
+
candidates.each_with_index { |candidate, ix|
|
53
|
+
if (candidates[ix + 1] and candidates[ix + 1].match(/\d+/))
|
54
|
+
field_key << {OM.destringify(candidate) => Integer(candidates.delete_at(ix + 1))}
|
55
|
+
else
|
56
|
+
field_key << OM.destringify(candidate)
|
57
|
+
end
|
58
|
+
}
|
59
|
+
logger.debug field_key.inspect
|
60
|
+
field_key
|
61
|
+
end
|
62
|
+
|
63
|
+
# ** largely copied from ActiveFedora::NokogiriDatastream.get_values **
|
64
|
+
def get_solr_name(term_pointer, dsClass)
|
65
|
+
term = dsClass.terminology.retrieve_term(*OM.pointers_to_flat_array(term_pointer, false))
|
66
|
+
names = []
|
67
|
+
if is_hierarchical_term_pointer?(*term_pointer)
|
68
|
+
bases = []
|
69
|
+
#add first item in term_pointer as start of bases
|
70
|
+
# then iterate through possible nodes that might exist
|
71
|
+
term_pointer.first.kind_of?(Hash) ? bases << term_pointer.first.keys.first : bases << term_pointer.first
|
72
|
+
for i in 1..(term_pointer.length-1)
|
73
|
+
#iterate in reverse so that we can modify the bases array while iterating
|
74
|
+
(bases.length-1).downto(0) do |j|
|
75
|
+
current_last = (term_pointer[i].kind_of?(Hash) ? term_pointer[i].keys.first : term_pointer[i])
|
76
|
+
if (term_pointer[i-1].kind_of?(Hash))
|
77
|
+
#just use index supplied instead of trying possibilities
|
78
|
+
index = term_pointer[i-1].values.first
|
79
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
|
80
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
81
|
+
bases.delete_at(j)
|
82
|
+
#insert the new solr name base if found
|
83
|
+
bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
|
84
|
+
else
|
85
|
+
#detect how many nodes exist
|
86
|
+
index = 0
|
87
|
+
current_base = bases[j]
|
88
|
+
bases.delete_at(j)
|
89
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
|
90
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
91
|
+
bases.insert(j,solr_name_base)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
bases.each do |base|
|
96
|
+
names << generate_solr_symbol(base.to_sym, term.data_type)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
#this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
|
100
|
+
generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
|
101
|
+
names << generate_solr_symbol(generic_field_name_base, term.data_type)
|
102
|
+
end
|
103
|
+
names
|
104
|
+
end
|
105
|
+
|
106
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
107
|
+
#@return true if the term_pointer contains an index
|
108
|
+
# ====Example:
|
109
|
+
# [:image, {:title_set=>1}, :title] return true
|
110
|
+
# [:image, :title_set, :title] return false
|
111
|
+
def is_hierarchical_term_pointer?(*term_pointer)
|
112
|
+
if term_pointer.length>1
|
113
|
+
term_pointer.each do |pointer|
|
114
|
+
if pointer.kind_of?(Hash)
|
115
|
+
return true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
return false
|
120
|
+
end
|
121
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
122
|
+
def generate_solr_symbol(base, data_type)
|
123
|
+
Solrizer::XML::TerminologyBasedSolrizer.default_field_mapper.solr_name(base.to_sym, data_type)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'cul_hydra'
|
2
|
+
require 'json'
|
3
|
+
require 'blacklight'
|
4
|
+
module Cul::Hydra::Controllers
|
5
|
+
module Terms
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
included do
|
8
|
+
include ::Blacklight::SearchHelper
|
9
|
+
#include MediaShelf::ActiveFedoraHelper
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
if params[:layout] == "false"
|
14
|
+
layout = false
|
15
|
+
end
|
16
|
+
if params[:term_id]
|
17
|
+
@solr_name = solr_name(params[:term_id])
|
18
|
+
else
|
19
|
+
@solr_name = params[:solr_name]
|
20
|
+
end
|
21
|
+
@terms = term_values
|
22
|
+
render :action=>params[:action], :layout=>layout
|
23
|
+
end
|
24
|
+
|
25
|
+
# this method should be overridden to use the appropriate terminology
|
26
|
+
def solr_name(term_id)
|
27
|
+
if term_id.nil?
|
28
|
+
raise "Cannot provide suggestions without a term name"
|
29
|
+
end
|
30
|
+
field_key = field_key_from(term_id, Cul::Hydra::Om::ModsDocument.terminology)
|
31
|
+
get_solr_name(field_key, Cul::Hydra::Om::ModsDocument)
|
32
|
+
end
|
33
|
+
def term_values
|
34
|
+
if @solr_name.nil?
|
35
|
+
logger.debug "no solr field name, return nil for term values"
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
stub = params[:term_value]
|
39
|
+
solr_params = {}
|
40
|
+
solr_params['wt'] = 'json'
|
41
|
+
solr_params['terms'] = 'true'
|
42
|
+
solr_params['terms.fl'] = @solr_name
|
43
|
+
if stub
|
44
|
+
solr_params['terms.lower'] = stub
|
45
|
+
solr_params['terms.lower.incl'] = false
|
46
|
+
solr_params['terms.prefix'] = stub
|
47
|
+
solr_params['terms.sort'] = 'index'
|
48
|
+
else
|
49
|
+
solr_params['terms.sort'] = params.fetch(:sort,'count')
|
50
|
+
solr_params['terms.limit'] = -1
|
51
|
+
end
|
52
|
+
solr_response = Blacklight.solr.get 'terms', {:params => solr_params}
|
53
|
+
result = []
|
54
|
+
hash = {}
|
55
|
+
(1...solr_response['terms'].length).step(2) { |ix|
|
56
|
+
_t = solr_response['terms'][ix]
|
57
|
+
(0..._t.length).step(2) { |jx|
|
58
|
+
result << [_t[jx], _t[jx + 1]]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return result
|
62
|
+
end
|
63
|
+
|
64
|
+
## field_key_from(field_name) to reverse this method from HydraFedoraMetadataHelper
|
65
|
+
# def field_name_for(field_key)
|
66
|
+
# if field_key.kind_of?(Array)
|
67
|
+
# return OM::XML::Terminology.term_hierarchical_name(*field_key)
|
68
|
+
# else
|
69
|
+
# field_key.to_s
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
|
73
|
+
def field_key_from(hier_field_name, t)
|
74
|
+
candidates = hier_field_name.split('_')
|
75
|
+
field_key = []
|
76
|
+
candidates.inject(field_key) { |ptrs, term|
|
77
|
+
if term =~ /\d+/
|
78
|
+
ptr = {ptrs.pop=>term.to_i}
|
79
|
+
else
|
80
|
+
ptr = (ptrs.empty? or ptrs.last.is_a? Hash) ? term.to_sym : (ptrs.pop.to_s + "_" + term).to_sym
|
81
|
+
end
|
82
|
+
ptrs.push ptr
|
83
|
+
}
|
84
|
+
return field_key if t.has_term? *field_key
|
85
|
+
# pointers are probably from ambiguous underscores
|
86
|
+
amb = field_key.dup
|
87
|
+
field_key = []
|
88
|
+
amb.each do |candidate|
|
89
|
+
key = (candidate.is_a? Hash) ? candidate.keys.first : candidate # no indexes should be included
|
90
|
+
parts = key.to_s.split('_')
|
91
|
+
ptrs = parts_to_terms(parts, t, field_key)
|
92
|
+
if ptrs.nil? or !t.has_term? *ptrs
|
93
|
+
raise "Couldn't generate pointer from term name going forward for \"" + hier_field_name + "\" (no matched term sequence)"
|
94
|
+
else
|
95
|
+
if candidate.is_a? Hash
|
96
|
+
ptr_key = ptrs.pop
|
97
|
+
ptrs.push({ptr_key => candidate[candidate.keys.first] })
|
98
|
+
end
|
99
|
+
field_key = ptrs
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return field_key if t.has_term? *field_key
|
103
|
+
raise "Couldn't generate pointer from term name going forward for \"" + hier_field_name + "\", tried " + field_key.inspect
|
104
|
+
end
|
105
|
+
|
106
|
+
def parts_to_terms(parts, t, prefix=[])
|
107
|
+
return nil if parts.length == 0 # this should be short-circuited in the loop below rather than recurring
|
108
|
+
if parts.length == 1
|
109
|
+
new_term_ptr = prefix.dup.push parts[0].to_sym
|
110
|
+
if t.has_term? *new_term_ptr
|
111
|
+
return new_term_ptr
|
112
|
+
else
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
results = []
|
118
|
+
parts.each_index do |ix|
|
119
|
+
term_ptr = prefix.dup.push parts[0...(parts.length - ix)].join('_').to_sym
|
120
|
+
|
121
|
+
if t.has_term? *term_ptr
|
122
|
+
case ix
|
123
|
+
when 0
|
124
|
+
results.push term_ptr
|
125
|
+
when 1
|
126
|
+
new_term_ptr = term_ptr.concat [parts.last.to_sym]
|
127
|
+
results.push new_term_ptr if t.has_term? *new_term_ptr
|
128
|
+
else
|
129
|
+
new_term_ptr = parts_to_terms(parts[parts.length - ix, ix], t, term_ptr)
|
130
|
+
results.push new_term_ptr if !new_term_ptr.nil?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
if results.length == 1
|
136
|
+
return results[0]
|
137
|
+
else
|
138
|
+
return nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# ** largely copied from ActiveFedora::NokogiriDatastream.get_values **
|
143
|
+
def get_solr_name(term_pointer, dsClass)
|
144
|
+
term = dsClass.terminology.retrieve_term(*OM.pointers_to_flat_array(term_pointer, false))
|
145
|
+
names = []
|
146
|
+
if is_hierarchical_term_pointer?(*term_pointer)
|
147
|
+
bases = []
|
148
|
+
#add first item in term_pointer as start of bases
|
149
|
+
# then iterate through possible nodes that might exist
|
150
|
+
term_pointer.first.kind_of?(Hash) ? bases << term_pointer.first.keys.first : bases << term_pointer.first
|
151
|
+
for i in 1..(term_pointer.length-1)
|
152
|
+
#iterate in reverse so that we can modify the bases array while iterating
|
153
|
+
(bases.length-1).downto(0) do |j|
|
154
|
+
current_last = (term_pointer[i].kind_of?(Hash) ? term_pointer[i].keys.first : term_pointer[i])
|
155
|
+
if (term_pointer[i-1].kind_of?(Hash))
|
156
|
+
#just use index supplied instead of trying possibilities
|
157
|
+
index = term_pointer[i-1].values.first
|
158
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
|
159
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
160
|
+
bases.delete_at(j)
|
161
|
+
#insert the new solr name base if found
|
162
|
+
bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
|
163
|
+
else
|
164
|
+
#detect how many nodes exist
|
165
|
+
index = 0
|
166
|
+
current_base = bases[j]
|
167
|
+
bases.delete_at(j)
|
168
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
|
169
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
170
|
+
bases.insert(j,solr_name_base)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
bases.each do |base|
|
175
|
+
names << generate_solr_symbol(base.to_sym, term.data_type)
|
176
|
+
end
|
177
|
+
else
|
178
|
+
#this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
|
179
|
+
generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
|
180
|
+
names << generate_solr_symbol(generic_field_name_base, term.data_type)
|
181
|
+
end
|
182
|
+
names
|
183
|
+
end
|
184
|
+
|
185
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
186
|
+
#@return true if the term_pointer contains an index
|
187
|
+
# ====Example:
|
188
|
+
# [:image, {:title_set=>1}, :title] return true
|
189
|
+
# [:image, :title_set, :title] return false
|
190
|
+
def is_hierarchical_term_pointer?(*term_pointer)
|
191
|
+
if term_pointer.length>1
|
192
|
+
term_pointer.each do |pointer|
|
193
|
+
if pointer.kind_of?(Hash)
|
194
|
+
return true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
return false
|
199
|
+
end
|
200
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
201
|
+
def generate_solr_symbol(base, data_type)
|
202
|
+
Solrizer::XML::TerminologyBasedSolrizer.default_field_mapper.solr_name(base.to_sym, data_type)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# lib/cul_hydra/engine.rb
|
3
|
+
require "cul_hydra"
|
4
|
+
require "rails"
|
5
|
+
|
6
|
+
module Cul::Hydra
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
isolate_namespace Cul::Hydra
|
9
|
+
|
10
|
+
config.mount_at = '/'
|
11
|
+
|
12
|
+
config.autoload_paths += %W(
|
13
|
+
#{config.root}/app/controllers/concerns
|
14
|
+
#{config.root}/app/models/concerns
|
15
|
+
)
|
16
|
+
|
17
|
+
config.generators do |g|
|
18
|
+
g.test_framework :rspec
|
19
|
+
g.integration_tool :rspec
|
20
|
+
end
|
21
|
+
|
22
|
+
# Make the rake tasks visible.
|
23
|
+
rake_tasks do
|
24
|
+
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..'))) do
|
25
|
+
Dir.glob(File.join('tasks', '*.rake')).each do |railtie|
|
26
|
+
#load railtie # Commenting this out for now because we appear to be loading rake tasks twice
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|