geo_concerns 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/geo_concerns/actors/file_actor.rb +25 -0
  3. data/app/actors/geo_concerns/actors/file_set_actor.rb +9 -0
  4. data/app/controllers/concerns/geo_concerns/file_sets_controller_behavior.rb +3 -2
  5. data/app/helpers/geo_concerns/bounding_box_helper.rb +26 -0
  6. data/app/helpers/geo_concerns/geo_works_helper.rb +22 -0
  7. data/app/models/concerns/geo_concerns/external_metadata_file_behavior.rb +1 -1
  8. data/app/models/concerns/geo_concerns/file_set/derivatives.rb +5 -5
  9. data/app/models/concerns/geo_concerns/file_set_metadata.rb +15 -0
  10. data/app/models/concerns/geo_concerns/geo_file_format_behavior.rb +4 -4
  11. data/app/models/concerns/geo_concerns/geo_file_set_behavior.rb +1 -0
  12. data/app/presenters/geo_concerns/geo_concerns_show_presenter.rb +10 -11
  13. data/app/presenters/geo_concerns/image_work_show_presenter.rb +2 -14
  14. data/app/presenters/geo_concerns/raster_work_show_presenter.rb +2 -14
  15. data/app/presenters/geo_concerns/vector_work_show_presenter.rb +1 -6
  16. data/app/renderers/geo_concerns/coverage_renderer.rb +36 -0
  17. data/app/schemas/geo_concerns/file_set_metadata_required.rb +5 -0
  18. data/app/views/curation_concerns/file_sets/_form.html.erb +1 -1
  19. data/app/views/curation_concerns/image_works/show.html.erb +2 -3
  20. data/app/views/curation_concerns/raster_works/show.html.erb +2 -3
  21. data/app/views/curation_concerns/vector_works/show.html.erb +2 -1
  22. data/app/views/geo_concerns/_related_external_metadata_files.html.erb +2 -2
  23. data/app/views/{curation_concerns/image_works/_related_image_files.html.erb → geo_concerns/_related_geo_files.html.erb} +5 -5
  24. data/app/views/{curation_concerns/image_works/_members.html.erb → geo_concerns/_related_geo_works.html.erb} +8 -6
  25. data/geo_concerns.gemspec +1 -1
  26. data/lib/generators/geo_concerns/install_generator.rb +2 -2
  27. data/lib/generators/geo_concerns/templates/actors/curation_concerns/actors/image_work_actor.rb +6 -0
  28. data/lib/generators/geo_concerns/templates/actors/curation_concerns/actors/raster_work_actor.rb +6 -0
  29. data/lib/generators/geo_concerns/templates/actors/curation_concerns/actors/vector_work_actor.rb +6 -0
  30. data/lib/generators/geo_concerns/templates/jobs/characterize_job.rb +4 -3
  31. data/lib/geo_concerns/version.rb +1 -1
  32. data/spec/actors/geo_concerns/{file_actor_spec.rb → actors/file_actor_spec.rb} +3 -3
  33. data/spec/factories/external_metadata_files.rb +2 -2
  34. data/spec/factories/image_files.rb +5 -5
  35. data/spec/factories/image_works.rb +4 -3
  36. data/spec/factories/raster_files.rb +3 -3
  37. data/spec/factories/raster_works.rb +7 -5
  38. data/spec/factories/vector_files.rb +3 -3
  39. data/spec/factories/vector_works.rb +5 -4
  40. data/spec/features/create_raster_work_spec.rb +1 -1
  41. data/spec/helpers/bounding_box_helper_spec.rb +2 -2
  42. data/spec/helpers/geo_works_helper_spec.rb +30 -0
  43. data/spec/models/concerns/basic_geo_metadata_spec.rb +1 -1
  44. data/spec/models/concerns/geo_concerns/file_set/derivatives_spec.rb +7 -7
  45. data/spec/models/concerns/geo_concerns/file_set/geo_file_format_behavior_spec.rb +5 -5
  46. data/spec/models/external_metadata_file_spec.rb +8 -8
  47. data/spec/models/image_file_spec.rb +3 -3
  48. data/spec/models/image_work_spec.rb +5 -5
  49. data/spec/models/raster_file_spec.rb +3 -3
  50. data/spec/models/raster_work_spec.rb +9 -9
  51. data/spec/models/vector_file_spec.rb +3 -3
  52. data/spec/models/vector_work_spec.rb +7 -7
  53. data/spec/presenters/geo_concerns_show_presenter_spec.rb +5 -15
  54. data/spec/presenters/image_work_show_presenter_spec.rb +14 -15
  55. data/spec/presenters/raster_work_show_presenter_spec.rb +13 -13
  56. data/spec/presenters/vector_work_show_presenter_spec.rb +10 -10
  57. data/spec/renderers/{coverage_renderer_spec.rb → geo_concerns/coverage_renderer_spec.rb} +1 -1
  58. metadata +24 -22
  59. data/app/actors/geo_concerns/file_actor.rb +0 -20
  60. data/app/actors/geo_concerns/file_set_actor.rb +0 -7
  61. data/app/helpers/bounding_box_helper.rb +0 -24
  62. data/app/renderers/coverage_renderer.rb +0 -34
  63. data/app/views/curation_concerns/raster_works/_members.html.erb +0 -30
  64. data/app/views/curation_concerns/raster_works/_related_raster_files.html.erb +0 -24
  65. data/app/views/curation_concerns/vector_works/_related_vector_files.html.erb +0 -24
  66. data/lib/generators/geo_concerns/templates/actors/curation_concerns/image_work_actor.rb +0 -4
  67. data/lib/generators/geo_concerns/templates/actors/curation_concerns/raster_work_actor.rb +0 -4
  68. data/lib/generators/geo_concerns/templates/actors/curation_concerns/vector_work_actor.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4be533d84cfd89f0199d8fed8ef426c0880856f9
4
- data.tar.gz: 585d77df727e269c05768bd4faa1fdc87d874edc
3
+ metadata.gz: 5860cade4910404ebfc81e6d1dcb6524ab1b2a88
4
+ data.tar.gz: cb1f2d4920984de204a0d04b06593c9d804abe02
5
5
  SHA512:
6
- metadata.gz: c2a18e387eba255c23a475fbb9ab0064dc2d31e1ea7dd55f55f93df2be6b65780b8ef63b0b0ba486af162f11705439c63217e9efde0510d85e80eab08b583d0e
7
- data.tar.gz: 99721d9388d56b1afafd583161cb0f546ab1aceaac380346b504319c3c6c27a9154ab731f35fe28bad61fb240b45420ea9c1725a28cc0776ad966d25659124a4
6
+ metadata.gz: d04edc92c51d7de7f69fadec0b189e244a92586773715646efebb7076421301ff8c3ee97cd95fceeb1b9a903683968f51815e5120c4ce7d3b0d8058453cce79e
7
+ data.tar.gz: b17861f0bc73e579ab4cf38614988c6909c033bbc66a03215399e0f6b71a360068ec8a39a53a4fb854c831707af2f654c8d765e58ff3e0051cbf4c70621de53c
@@ -0,0 +1,25 @@
1
+ module GeoConcerns
2
+ module Actors
3
+ class FileActor < CurationConcerns::Actors::FileActor
4
+ def ingest_file(file)
5
+ working_file = copy_file_to_working_directory(file, file_set.id)
6
+ IngestFileJob.perform_later(file_set,
7
+ working_file,
8
+ mime_type(file),
9
+ user,
10
+ relation)
11
+ true
12
+ end
13
+
14
+ # Determines the correct mime type for a file. If the mime type is stored on
15
+ # the file_set (set in the view), then use that value. If not, use the file
16
+ # content type, if it exists.
17
+ # @param [File, ActionDigest::HTTP::UploadedFile] file to get mime type from
18
+ # @return [String] Mime type for the file
19
+ def mime_type(file)
20
+ return file_set.geo_mime_type if file_set.geo_mime_type
21
+ file.respond_to?(:content_type) ? file.content_type : nil || file_set.geo_mime_type
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module GeoConcerns
2
+ module Actors
3
+ class FileSetActor < CurationConcerns::Actors::FileSetActor
4
+ def file_actor_class
5
+ ::GeoConcerns::Actors::FileActor
6
+ end
7
+ end
8
+ end
9
+ end
@@ -3,17 +3,18 @@ module GeoConcerns
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  self.show_presenter = ::FileSetPresenter
6
+ self.form_class = CurationConcerns::Forms::FileSetEditForm
6
7
  end
7
8
 
8
9
  # inject mime_type into permitted params
9
10
  def file_set_params
10
11
  super.tap do |permitted_params|
11
- permitted_params[:mime_type] = params[:file_set][:mime_type]
12
+ permitted_params[:geo_mime_type] = params[:file_set][:geo_mime_type]
12
13
  end
13
14
  end
14
15
 
15
16
  def actor
16
- @actor ||= GeoConcerns::FileSetActor.new(@file_set, current_user)
17
+ @actor ||= GeoConcerns::Actors::FileSetActor.new(@file_set, current_user)
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,26 @@
1
+ module GeoConcerns
2
+ module BoundingBoxHelper
3
+ ##
4
+ # Builds HTML string for bounding box selector tool.
5
+ # Calls boundingBoxSelector javascript function and
6
+ # passes the id of the location input element that it binds to.
7
+ # @param [Symbol] name of property that holds bounding box string
8
+ # @return[String]
9
+ def bbox(property)
10
+ %(
11
+ <div id='bbox'></div>
12
+ <script>
13
+ boundingBoxSelector({inputId: #{bbox_input_id(property)}});
14
+ </script>
15
+ ).html_safe
16
+ end
17
+
18
+ ##
19
+ # Returns id of location input that is bound to bbox selector.
20
+ # @param [Symbol] name of property that holds bounding box string
21
+ # @return[String] id of location input element
22
+ def bbox_input_id(property)
23
+ "#{curation_concern.class.name.underscore}_#{property}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module GeoConcerns
2
+ module GeoWorksHelper
3
+ # Returns human readable name of child geo work type.
4
+ # @param [GeoConcernsShowPresenter] geo work show presenter
5
+ # @return[String]
6
+ def child_geo_works_type(presenter)
7
+ case presenter.class.to_s
8
+ when 'GeoConcerns::ImageWorkShowPresenter'
9
+ 'Raster'
10
+ when 'GeoConcerns::RasterWorkShowPresenter'
11
+ 'Vector'
12
+ end
13
+ end
14
+
15
+ # Returns human readable name of geo work type.
16
+ # @param [GeoConcernsShowPresenter] geo work show presenter
17
+ # @return[String]
18
+ def geo_work_type(presenter)
19
+ presenter.human_readable_type.sub('Work', '')
20
+ end
21
+ end
22
+ end
@@ -25,7 +25,7 @@ module GeoConcerns
25
25
  end
26
26
 
27
27
  def schema
28
- (MetadataFormatService.label(mime_type) || '').parameterize('_')
28
+ (MetadataFormatService.label(geo_mime_type) || '').parameterize('_')
29
29
  end
30
30
  end
31
31
  end
@@ -4,7 +4,7 @@ module GeoConcerns
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def create_derivatives(filename)
7
- case mime_type
7
+ case geo_mime_type
8
8
  when *ImageFormatService.select_options.map(&:last)
9
9
  image_derivatives(filename)
10
10
  when *RasterFormatService.select_options.map(&:last)
@@ -26,11 +26,11 @@ module GeoConcerns
26
26
 
27
27
  def raster_derivatives(filename)
28
28
  GeoConcerns::Runners::RasterDerivatives
29
- .create(filename, outputs: [{ input_format: mime_type,
29
+ .create(filename, outputs: [{ input_format: geo_mime_type,
30
30
  label: :display_raster,
31
31
  format: 'tif',
32
32
  url: derivative_url('display_raster') },
33
- { input_format: mime_type,
33
+ { input_format: geo_mime_type,
34
34
  label: :thumbnail,
35
35
  format: 'jpg',
36
36
  size: '200x150',
@@ -39,11 +39,11 @@ module GeoConcerns
39
39
 
40
40
  def vector_derivatives(filename)
41
41
  GeoConcerns::Runners::VectorDerivatives
42
- .create(filename, outputs: [{ input_format: mime_type,
42
+ .create(filename, outputs: [{ input_format: geo_mime_type,
43
43
  label: :display_vector,
44
44
  format: 'zip',
45
45
  url: derivative_url('display_vector') },
46
- { input_format: mime_type,
46
+ { input_format: geo_mime_type,
47
47
  label: :thumbnail,
48
48
  format: 'jpg',
49
49
  size: '200x150',
@@ -0,0 +1,15 @@
1
+ module GeoConcerns
2
+ # Attributes and methods for basic geospatial metadata used by Works
3
+ module FileSetMetadata
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ apply_schema ::GeoConcerns::FileSetMetadataRequired,
8
+ ActiveFedora::SchemaIndexingStrategy.new(
9
+ ActiveFedora::Indexers::GlobalIndexer.new(
10
+ [:stored_searchable, :symbol]
11
+ )
12
+ )
13
+ end
14
+ end
15
+ end
@@ -3,19 +3,19 @@ module GeoConcerns
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def image_file?
6
- ImageFormatService.include?(mime_type)
6
+ ImageFormatService.include?(geo_mime_type)
7
7
  end
8
8
 
9
9
  def raster_file?
10
- RasterFormatService.include?(mime_type)
10
+ RasterFormatService.include?(geo_mime_type)
11
11
  end
12
12
 
13
13
  def vector_file?
14
- VectorFormatService.include?(mime_type)
14
+ VectorFormatService.include?(geo_mime_type)
15
15
  end
16
16
 
17
17
  def external_metadata_file?
18
- MetadataFormatService.include?(mime_type)
18
+ MetadataFormatService.include?(geo_mime_type)
19
19
  end
20
20
 
21
21
  def geo_file_format?
@@ -6,6 +6,7 @@ module GeoConcerns
6
6
  include ::GeoConcerns::RasterFileBehavior
7
7
  include ::GeoConcerns::VectorFileBehavior
8
8
  include ::GeoConcerns::ExternalMetadataFileBehavior
9
+ include ::GeoConcerns::FileSetMetadata
9
10
  include ::GeoConcerns::FileSet::Derivatives
10
11
  end
11
12
  end
@@ -2,26 +2,25 @@ module GeoConcerns
2
2
  class GeoConcernsShowPresenter < CurationConcerns::WorkShowPresenter
3
3
  delegate :has?, :first, to: :solr_document
4
4
  delegate :spatial, :temporal, :issued, :coverage, :provenance, to: :solr_document
5
+ class_attribute :file_format_service
5
6
 
6
- def members(presenter)
7
- # TODO: member ids appear twice in member_ids_ssim.
8
- # Figure out why instead of removing duplicates.
9
- ids = solr_document.fetch('member_ids_ssim', [])
10
- CurationConcerns::PresenterFactory.build_presenters(ids.uniq,
11
- presenter,
12
- current_ability)
7
+ def geo_file_set_presenters
8
+ # filter for geo file sets
9
+ file_set_presenters.select do |member|
10
+ file_format_service.include? member.solr_document[:geo_mime_type_tesim][0]
11
+ end
13
12
  end
14
13
 
15
- def external_metadata_file_formats_presenters
14
+ def external_metadata_file_set_presenters
16
15
  # filter for external metadata files
17
- members(::FileSetPresenter).select do |member|
18
- MetadataFormatService.include? member.solr_document[:mime_type_ssi]
16
+ file_set_presenters.select do |member|
17
+ MetadataFormatService.include? member.solr_document[:geo_mime_type_tesim][0]
19
18
  end
20
19
  end
21
20
 
22
21
  def attribute_to_html(field, options = {})
23
22
  if field == :coverage
24
- ::CoverageRenderer.new(field, send(field), options).render
23
+ GeoConcerns::CoverageRenderer.new(field, send(field), options).render
25
24
  else
26
25
  super field, options
27
26
  end
@@ -1,18 +1,6 @@
1
1
  module GeoConcerns
2
2
  class ImageWorkShowPresenter < GeoConcernsShowPresenter
3
- def raster_work_presenters
4
- # filter for raster works
5
- members(::GeoConcerns::RasterWorkShowPresenter).select do |member|
6
- format = member.solr_document[:has_model_ssim]
7
- format ? format.first == 'RasterWork' : false
8
- end
9
- end
10
-
11
- def image_file_presenters
12
- # filter for image files
13
- members(::FileSetPresenter).select do |member|
14
- ImageFormatService.include? member.solr_document[:mime_type_ssi]
15
- end
16
- end
3
+ self.work_presenter_class = ::GeoConcerns::RasterWorkShowPresenter
4
+ self.file_format_service = ImageFormatService
17
5
  end
18
6
  end
@@ -1,18 +1,6 @@
1
1
  module GeoConcerns
2
2
  class RasterWorkShowPresenter < GeoConcernsShowPresenter
3
- def vector_work_presenters
4
- # filter for vector works
5
- members(::GeoConcerns::VectorWorkShowPresenter).select do |member|
6
- format = member.solr_document[:has_model_ssim]
7
- format ? format.first == 'VectorWork' : false
8
- end
9
- end
10
-
11
- def raster_file_presenters
12
- # filter for raster files
13
- members(::FileSetPresenter).select do |member|
14
- RasterFormatService.include? member.solr_document[:mime_type_ssi]
15
- end
16
- end
3
+ self.work_presenter_class = ::GeoConcerns::VectorWorkShowPresenter
4
+ self.file_format_service = RasterFormatService
17
5
  end
18
6
  end
@@ -1,10 +1,5 @@
1
1
  module GeoConcerns
2
2
  class VectorWorkShowPresenter < GeoConcernsShowPresenter
3
- def vector_file_presenters
4
- # filter for vector files
5
- members(::FileSetPresenter).select do |member|
6
- VectorFormatService.include? member.solr_document[:mime_type_ssi]
7
- end
8
- end
3
+ self.file_format_service = VectorFormatService
9
4
  end
10
5
  end
@@ -0,0 +1,36 @@
1
+ module GeoConcerns
2
+ class CoverageRenderer < CurationConcerns::Renderers::AttributeRenderer
3
+ def render
4
+ coverage = values.first if values
5
+ return '' unless coverage
6
+ markup(coverage).html_safe
7
+ end
8
+
9
+ private
10
+
11
+ def markup(coverage)
12
+ markup = ''
13
+ markup << %(<tr><th>#{label}</th>\n<td id='accordion'><ul class='tabular'>)
14
+ markup << value(coverage)
15
+ markup << toggle_button
16
+ markup << map(coverage)
17
+ markup << %(</ul></td></tr>)
18
+ markup
19
+ end
20
+
21
+ def value(coverage)
22
+ attributes = microdata_object_attributes(field).merge(class: "attribute #{field}")
23
+ %(<li#{html_attributes(attributes)}>#{attribute_value_to_html(coverage.to_s)})
24
+ end
25
+
26
+ def toggle_button
27
+ %( <a data-toggle='collapse' data-parent='accordion' href='#bbox' class='btn btn-default'>
28
+ Toggle Map</a>)
29
+ end
30
+
31
+ def map(coverage)
32
+ %(<div id='bbox' class='collapse in'></div>
33
+ <script>boundingBoxSelector({coverage: '#{coverage}', readonly: true});</script>)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module GeoConcerns
2
+ class FileSetMetadataRequired < ActiveTriples::Schema
3
+ property :geo_mime_type, predicate: RDF::Vocab::EBUCore.hasMimeType, multiple: false
4
+ end
5
+ end
@@ -24,7 +24,7 @@
24
24
  VectorFormatService.select_options
25
25
  end %>
26
26
  <% if select_options %>
27
- <%= f.input(:mime_type, as: :select, collection: select_options,
27
+ <%= f.input(:geo_mime_type, as: :select, collection: select_options,
28
28
  input_html: { class: 'form-control' }, label: 'Type') %>
29
29
  <% end %>
30
30
  <%= f.input :files, as: :multifile %>
@@ -9,9 +9,8 @@
9
9
  <%= render 'representative_media', presenter: @presenter %>
10
10
  <%= render 'geo_concerns/attributes', presenter: @presenter %>
11
11
 
12
- <%= render 'related_image_files', presenter: @presenter %>
12
+ <%= render 'geo_concerns/related_geo_files', presenter: @presenter %>
13
13
  <%= render 'geo_concerns/related_external_metadata_files', presenter: @presenter %>
14
-
15
- <%= render 'members', presenter: @presenter %>
14
+ <%= render 'geo_concerns/related_geo_works', presenter: @presenter %>
16
15
 
17
16
  <%= render "show_actions", collector: collector, editor: editor%>
@@ -9,9 +9,8 @@
9
9
  <%= render 'representative_media', presenter: @presenter %>
10
10
  <%= render 'geo_concerns/attributes', presenter: @presenter %>
11
11
 
12
- <%= render 'related_raster_files', presenter: @presenter %>
12
+ <%= render 'geo_concerns/related_geo_files', presenter: @presenter %>
13
13
  <%= render 'geo_concerns/related_external_metadata_files', presenter: @presenter %>
14
-
15
- <%= render 'members', presenter: @presenter %>
14
+ <%= render 'geo_concerns/related_geo_works', presenter: @presenter %>
16
15
 
17
16
  <%= render "show_actions", collector: collector, editor: editor%>
@@ -9,7 +9,8 @@
9
9
  <%= render 'representative_media', presenter: @presenter %>
10
10
  <%= render 'geo_concerns/attributes', presenter: @presenter %>
11
11
 
12
- <%= render 'related_vector_files', presenter: @presenter %>
12
+ <%= render 'geo_concerns/related_geo_files', presenter: @presenter %>
13
13
  <%= render 'geo_concerns/related_external_metadata_files', presenter: @presenter %>
14
+ <%= render 'geo_concerns/related_geo_works', presenter: @presenter %>
14
15
 
15
16
  <%= render "show_actions", collector: collector, editor: editor%>
@@ -1,4 +1,4 @@
1
- <% if presenter.external_metadata_file_formats_presenters.present? %>
1
+ <% if presenter.external_metadata_file_set_presenters.present? %>
2
2
  <div class="panel panel-default related_files">
3
3
  <div class="panel-heading">
4
4
  <h2>Metadata Files</h2>
@@ -14,7 +14,7 @@
14
14
  </tr>
15
15
  </thead>
16
16
  <tbody>
17
- <%= render partial: 'member', collection: presenter.external_metadata_file_formats_presenters %>
17
+ <%= render partial: 'member', collection: presenter.external_metadata_file_set_presenters %>
18
18
  </tbody>
19
19
  </table>
20
20
  </div>
@@ -1,7 +1,7 @@
1
- <% if presenter.image_file_presenters.present? %>
1
+ <% if presenter.geo_file_set_presenters.present? %>
2
2
  <div class="panel panel-default related_files">
3
3
  <div class="panel-heading">
4
- <h2>Image File</h2>
4
+ <h2><%= geo_work_type(presenter) %> File</h2>
5
5
  </div>
6
6
  <table class="table table-striped">
7
7
  <thead>
@@ -14,11 +14,11 @@
14
14
  </tr>
15
15
  </thead>
16
16
  <tbody>
17
- <%= render partial: 'member', collection: @presenter.image_file_presenters %>
17
+ <%= render partial: 'member', collection: @presenter.geo_file_set_presenters %>
18
18
  </tbody>
19
19
  </table>
20
20
  </div>
21
21
  <% elsif can? :edit, presenter.id %>
22
- <h2>Image File</h2>
23
- <p class="center"><em>This <%= presenter.human_readable_type %> doesn't have an image file associated with it. You can add one using the "Attach a File" button below.</em></p>
22
+ <h2><%= geo_work_type(presenter) %> File</h2>
23
+ <p class="center"><em>This <%= presenter.human_readable_type %> doesn't have an <%= geo_work_type(presenter).downcase %> file associated with it.</em></p>
24
24
  <% end %>