Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Allow ImageWorks to pull metadata from bibdata and display image in U…
Browse files Browse the repository at this point in the history
…niversal Viewer
  • Loading branch information
eliotjordan committed Mar 2, 2017
1 parent 703665a commit eecdcc1
Show file tree
Hide file tree
Showing 24 changed files with 3,968 additions and 57 deletions.
19 changes: 19 additions & 0 deletions app/controllers/hyrax/geo_works_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Hyrax::GeoWorksController < ApplicationController
include Hyrax::WorksControllerBehavior
include Hyrax::BreadcrumbsForWorks
include GeoWorks::GeoblacklightControllerBehavior
include Hyrax::GeoMessengerBehavior

private

def decorator
CompositeDecorator.new(NullDecorator)
end

def curation_concern
@decorated_concern ||=
begin
@curation_concern = decorator.new(@curation_concern)
end
end
end
7 changes: 3 additions & 4 deletions app/controllers/hyrax/image_works_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Hyrax::ImageWorksController < ApplicationController
include Hyrax::CurationConcernController
class Hyrax::ImageWorksController < Hyrax::GeoWorksController
include GeoWorks::ImageWorksControllerBehavior
include GeoWorks::GeoblacklightControllerBehavior
include Hyrax::GeoMessengerBehavior
include Hyrax::Manifest
include Hyrax::RemoteMetadata
self.curation_concern_type = ImageWork

def show_presenter
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/hyrax/raster_works_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class Hyrax::RasterWorksController < ApplicationController
include Hyrax::CurationConcernController
class Hyrax::RasterWorksController < Hyrax::GeoWorksController
include Hyrax::ParentContainer
include GeoWorks::RasterWorksControllerBehavior
include GeoWorks::GeoblacklightControllerBehavior
include Hyrax::GeoMessengerBehavior
self.curation_concern_type = RasterWork

Expand Down
5 changes: 1 addition & 4 deletions app/controllers/hyrax/vector_works_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
class Hyrax::VectorWorksController < ApplicationController
include Hyrax::WorksControllerBehavior
class Hyrax::VectorWorksController < Hyrax::GeoWorksController
include Hyrax::ParentContainer
include GeoWorks::VectorWorksControllerBehavior
include GeoWorks::GeoblacklightControllerBehavior
include Hyrax::GeoMessengerBehavior
self.curation_concern_type = VectorWork

def show_presenter
Expand Down
2 changes: 2 additions & 0 deletions app/forms/hyrax/image_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ImageWorkForm < ::Hyrax::GeoWorkForm
include ::GeoWorks::BasicGeoMetadataForm
include ::GeoWorks::ExternalMetadataFileForm
self.model_class = ::ImageWork
self.terms += [:viewing_direction, :viewing_hint]
self.required_fields = [:title, :source_metadata_identifier, :rights_statement, :coverage]

def secondary_terms
super - [:cartographic_projection]
Expand Down
50 changes: 50 additions & 0 deletions app/models/concerns/apply_remote_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ApplyRemoteMetadata
extend ActiveSupport::Concern

included do
validate :source_metadata_identifier_or_title

def apply_remote_metadata
if remote_data.source
self.source_metadata = remote_data.source.dup.try(:force_encoding, 'utf-8')
end
if remote_data.respond_to?(:jsonld)
self.source_jsonld = remote_data.jsonld.dup.try(:force_encoding, 'utf-8')
end
self.attributes = enumerable_to_single_valued_attributes(remote_data.attributes)
CompleteRecord.new(self).complete if workflow_state == 'complete' && identifier.present?
end

private

def enumerable_to_single_valued_attributes(attributes)
attributes.merge(attributes) do |key, value|
next unless value
single_valued_attributes.include?(key) ? value.first : value
end
end

def single_valued_attributes
attributes.map { |key, value| key unless value.is_a? Enumerable }.compact
end

def remote_data
@remote_data ||= remote_metadata_factory.retrieve(source_metadata_identifier)
end

def remote_metadata_factory
if RemoteRecord.bibdata?(source_metadata_identifier) == 0
JSONLDRecord::Factory.new(self.class)
else
RemoteRecord
end
end

# Validate that either the source_metadata_identifier or the title is set.
def source_metadata_identifier_or_title
return if source_metadata_identifier.present? || title.present?
errors.add(:title, "You must provide a source metadata id or a title")
errors.add(:source_metadata_identifier, "You must provide a source metadata id or a title")
end
end
end
34 changes: 0 additions & 34 deletions app/models/concerns/common_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,8 @@ module CommonMetadata
ActiveFedora::Indexers::GlobalIndexer.new([:stored_searchable, :symbol])
)

validate :source_metadata_identifier_or_title
validates_with RightsStatementValidator
validates_with ViewingDirectionValidator
validates_with ViewingHintValidator

def apply_remote_metadata
if remote_data.source
self.source_metadata = remote_data.source.dup.try(:force_encoding, 'utf-8')
end
if remote_data.respond_to?(:jsonld)
self.source_jsonld = remote_data.jsonld.dup.try(:force_encoding, 'utf-8')
end
self.attributes = remote_data.attributes

CompleteRecord.new(self).complete if workflow_state == 'complete' && identifier.present?
end

private

def remote_data
@remote_data ||= remote_metadata_factory.retrieve(source_metadata_identifier)
end

def remote_metadata_factory
if RemoteRecord.bibdata?(source_metadata_identifier) == 0
JSONLDRecord::Factory.new(self.class)
else
RemoteRecord
end
end

# Validate that either the source_metadata_identifier or the title is set.
def source_metadata_identifier_or_title
return if source_metadata_identifier.present? || title.present?
errors.add(:title, "You must provide a source metadata id or a title")
errors.add(:source_metadata_identifier, "You must provide a source metadata id or a title")
end
end
end
1 change: 1 addition & 0 deletions app/models/image_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ImageWork < ActiveFedora::Base
include ::GeoWorks::BasicGeoMetadata
include ::GeoMetadata
include ::StateBehavior
include ::ApplyRemoteMetadata
self.valid_child_concerns = [RasterWork]

# Use local indexer
Expand Down
1 change: 1 addition & 0 deletions app/models/multi_volume_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class MultiVolumeWork < ActiveFedora::Base
include ::Hyrax::WorkBehavior
include ::Hyrax::BasicMetadata
include ::CommonMetadata
include ::ApplyRemoteMetadata
include ::StateBehavior
include ::StructuralMetadata
include ::HasPendingUploads
Expand Down
1 change: 1 addition & 0 deletions app/models/scanned_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ScannedResource < ActiveFedora::Base
include ::Hyrax::WorkBehavior
include ::Hyrax::BasicMetadata
include ::CommonMetadata
include ::ApplyRemoteMetadata
include ::StateBehavior
include ::StructuralMetadata
include ::HasPendingUploads
Expand Down
1 change: 1 addition & 0 deletions app/presenters/image_work_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class ImageWorkShowPresenter < GeoWorks::ImageWorkShowPresenter
include PlumAttributes
delegate :viewing_hint, :viewing_direction, :logical_order, :logical_order_object, :ocr_language, to: :solr_document
end
2 changes: 0 additions & 2 deletions app/presenters/vector_work_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
class VectorWorkShowPresenter < GeoWorks::VectorWorkShowPresenter
include PlumAttributes

# self.file_format_service = GeoConcerns::VectorFormatService
end
1 change: 1 addition & 0 deletions app/schemas/geo_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class GeoSchema < ActiveTriples::Schema
property :source_metadata, predicate: ::PULTerms.source_metadata, multiple: false
property :holding_location, predicate: ::RDF::Vocab::Bibframe.heldBy, multiple: false
property :ocr_language, predicate: ::PULTerms.ocr_language
property :source_jsonld, predicate: ::PULTerms.source_jsonld, multiple: false
end
9 changes: 7 additions & 2 deletions app/services/plum_derivatives_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def create_derivatives(filename)
filename,
outputs: [
label: 'intermediate_file',
recipe: recipe,
service: {
datastream: 'intermediate_file',
recipe: :default
datastream: 'intermediate_file'
},
url: derivative_url('intermediate_file')
]
Expand Down Expand Up @@ -45,4 +45,9 @@ def valid?
def derivative_path_factory
PairtreeDerivativePath
end

# Because of issues with tiffs, scanned maps need a seperate recipe
def recipe
file_set.geo_mime_type && file_set.geo_mime_type == "image/tiff" ? :geo : :default
end
end
1 change: 1 addition & 0 deletions app/values/pairtree_derivative_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def path_prefix
def geo_path_prefix
return unless @object.respond_to?(:geo_mime_type)
return if @object.geo_mime_type.nil? || @object.geo_mime_type.empty?
return if @object.geo_mime_type == "image/tiff"
Pathname.new(Plum.config[:geo_derivatives_path]).join(pair_path)
end

Expand Down
5 changes: 0 additions & 5 deletions app/views/hyrax/image_works/_file_actions.html.erb

This file was deleted.

19 changes: 19 additions & 0 deletions app/views/hyrax/image_works/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% if collector || editor %>
<div class="form-actions">
<% if editor %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, @presenter]), class: 'btn btn-default' %>
<div class="btn-group">
<button class="btn btn-default btn-small dropdown-toggle" data-toggle="dropdown" href="#"> Attach File <span class="caret"></span></button>
<ul class="dropdown-menu">
<li>
<%= link_to "Attach Image", main_app.new_hyrax_file_set_path(@presenter, type: 'image-data') %>
</li>
<li>
<%= link_to "Attach Metadata", main_app.new_hyrax_file_set_path(@presenter, type: 'metadata') %>
</li>
</ul>
</div>
<% end %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, @presenter], class: 'btn btn-danger pull-right', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %>
</div>
<% end %>
23 changes: 23 additions & 0 deletions app/views/hyrax/image_works/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% provide :page_title, @presenter.page_title %>
<% provide :page_header do %>
<%= render "hyrax/base/title_header" %>
<% if @parent_presenter %>
<ul class="breadcrumb">
<li><%= link_to @parent_presenter, polymorphic_path([main_app, @parent_presenter]) %></li>
<li class="active"><%= @presenter.human_readable_type %></li>
</ul>
<% else %>
<span class="human_readable_type">(<%= @presenter.human_readable_type %>)</span>
<% end %>
<% end %>
<% collector = can?(:collect, @presenter.id) %>
<% editor = can?(:edit, @presenter.id) %>
<%= render 'representative_media', presenter: @presenter %>
<%= render 'geo_works/metadata', presenter: @presenter %>
<%= render 'geo_works/relationships', presenter: @presenter %>
<%= render 'geo_works/related/geo_files', presenter: @presenter %>
<%= render 'geo_works/related/external_metadata_files', presenter: @presenter %>
<%= render 'workflow_actions', presenter: @presenter if @presenter.workflow.actions.present? %>
<%= render "show_actions", collector: collector, editor: editor%>
32 changes: 32 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ defaults: &defaults
ORGgen_plt=yes
ORGtparts=R
Stiles=\{1024,1024\}
geo_color: >
-no_palette
-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
-jp2_space sRGB
-double_buffering 10
-num_threads 1
-no_weights
Clevels=6
Clayers=8
Cblk=\{64,64\}
Cuse_sop=yes
Cuse_eph=yes
Corder=RPCL
ORGgen_plt=yes
ORGtparts=R
Stiles=\{1024,1024\}
geo_gray: >
-no_palette
-rate 2.4,1.48331273,.91673033,.56657224,.35016049,.21641118,.13374944,.08266171
-jp2_space sLUM
-double_buffering 10
-num_threads 1
-no_weights
Clevels=6
Clayers=8
Cblk=\{64,64\}
Cuse_sop=yes
Cuse_eph=yes
Corder=RPCL
ORGgen_plt=yes
ORGtparts=R
Stiles=\{1024,1024\}
events:
server: 'amqp://localhost:5672'
exchange: 'plum_events'
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
post :browse_everything_files
end
end
resources :image_works, only: [] do
member do
get :manifest, defaults: { format: :json }
end
end
resources :file_sets, only: [] do
member do
post :derivatives
Expand Down
Loading

0 comments on commit eecdcc1

Please sign in to comment.