module CurationConcerns class WorkShowPresenter include ModelProxy include PresentsAttributes attr_accessor :solr_document, :current_ability, :request class_attribute :collection_presenter_class # modify this attribute to use an alternate presenter class for the collections self.collection_presenter_class = CollectionPresenter # Methods used by blacklight helpers delegate :has?, :first, :fetch, :export_formats, :export_as, to: :solr_document # @param [SolrDocument] solr_document # @param [Ability] current_ability # @param [ActionDispatch::Request] request the http request context def initialize(solr_document, current_ability, request = nil) @solr_document = solr_document @current_ability = current_ability @request = request end def page_title title.first end # CurationConcern methods delegate :stringify_keys, :human_readable_type, :collection?, :representative_id, :to_s, to: :solr_document # Metadata Methods delegate :title, :date_created, :date_modified, :date_uploaded, :description, :creator, :contributor, :subject, :publisher, :language, :embargo_release_date, :lease_expiration_date, :rights, :source, :thumbnail_id, :representative_id, to: :solr_document def workflow @workflow ||= WorkflowPresenter.new(solr_document, current_ability) end def inspect_work @inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability) end # @return FileSetPresenter presenter for the representative FileSets def representative_presenter return nil if representative_id.blank? @representative_presenter ||= begin result = member_presenters([representative_id]).first if result.respond_to?(:representative_presenter) result.representative_presenter else result end end end # @return [Array] presenters for the collections that this work is a member of def collection_presenters PresenterFactory.build_presenters(in_collection_ids, collection_presenter_class, *presenter_factory_arguments) end def link_name current_ability.can?(:read, id) ? to_s : 'File' end def export_as_nt graph.dump(:ntriples) end def export_as_jsonld graph.dump(:jsonld, standard_prefixes: true) end def export_as_ttl graph.dump(:ttl) end delegate :member_presenters, :file_set_presenters, :work_presenters, to: :member_presenter_factory private def presenter_factory_arguments [current_ability, request] end # @return [Array] ids of the collections that this work is a member of def in_collection_ids ActiveFedora::SolrService.query("{!field f=member_ids_ssim}#{id}", fl: ActiveFedora.id_field) .map { |x| x.fetch(ActiveFedora.id_field) } end def member_presenter_factory MemberPresenterFactory.new(solr_document, current_ability, request) end def graph GraphExporter.new(solr_document, request).fetch end end end