Sha256: 381a24eeb3940611ab38f618f2a752a54c2020d325614f07cd0c751f703fc9f5

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

module CurationConcerns
  module IndexesWorkflow
    STORED_BOOL = Solrizer::Descriptor.new(:boolean, :stored, :indexed)
    # Adds thumbnail indexing to the solr document
    def generate_solr_document
      super.tap do |solr_doc|
        index_suppressed(solr_doc)
        index_workflow_fields(solr_doc)
      end
    end

    # Write the suppressed status into the solr_document
    # @params [Hash] solr_document the solr document to add the field to
    def index_suppressed(solr_document)
      solr_document[suppressed_field] = object.suppressed?
    end

    # Write the workflow roles and state so one can see where the document moves to next
    # @params [Hash] solr_document the solr document to add the field to
    def index_workflow_fields(solr_document)
      return unless object.persisted?
      entity = PowerConverter.convert_to_sipity_entity(object)
      return if entity.nil?
      solr_document[workflow_role_field] = workflow_roles(entity).map { |role| "#{entity.workflow.name}-#{role}" }
      solr_document[workflow_state_name_field] = entity.workflow_state.name if entity.workflow_state
    end

    def workflow_state_name_field
      @workflow_state_name_field ||= Solrizer.solr_name('workflow_state_name', :symbol)
    end

    def workflow_role_field
      @workflow_role_field ||= Solrizer.solr_name('actionable_workflow_roles', :symbol)
    end

    def workflow_roles(entity)
      CurationConcerns::Workflow::PermissionQuery.scope_roles_associated_with_the_given_entity(entity: entity)
    end

    def suppressed_field
      @suppressed_field ||= Solrizer.solr_name('suppressed', STORED_BOOL)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.7 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-2.0.0 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-2.0.0.rc2 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.6 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.5 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.4 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.3 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.2 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-2.0.0.rc1 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.1 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.0 app/indexers/curation_concerns/indexes_workflow.rb
curation_concerns-1.7.0.beta1 app/indexers/curation_concerns/indexes_workflow.rb