Module: Sipity

Defined in:
app/models/sipity.rb,
app/models/sipity/role.rb,
app/models/sipity/agent.rb,
app/models/sipity/entity.rb,
app/models/sipity/method.rb,
app/models/sipity/comment.rb,
app/models/sipity/workflow.rb,
app/models/sipity/notification.rb,
app/models/sipity/workflow_role.rb,
app/models/sipity/workflow_state.rb,
app/models/sipity/workflow_action.rb,
app/models/sipity/notifiable_context.rb,
app/models/sipity/workflow_state_action.rb,
app/models/sipity/notification_recipient.rb,
app/models/sipity/workflow_responsibility.rb,
app/models/sipity/entity_specific_responsibility.rb,
app/models/sipity/workflow_state_action_permission.rb

Overview

Sipity is a workflow/state engine.

This module and the classes namespaced within it provide a domain model and implementation for managing the movement of repository objects through a defined workflow. The workflows themselves are configured using JSON documents and loaded into the database/domain model as Workflow. Each workflow can be understood as finite sets of WorkflowState, WorkflowAction (transitions from state to state), and Role authorized to carry out each action.

Any uniquely identifiable object can be managed by a Workflow. Normally Hyrax uses workflows to handle the deposit process and maintenance lifecycle of repository objects at the level of the Work (within the Hydra Works model). Objects are represented within the Sipity engine's domain model by a Entity. Each object has at most one Entity, is governed by one Workflow, and in one WorkflowState at any given time.

Some use cases for Sipity workflows include:

  • Simple unmediated deposit with on-deposit notifications and actions;

  • Mediated deposit with one or more review steps;

  • Publication workflows requiring multiple levels of editorial approval and/or peer review;

  • Preservation processes involving post-deposit selection of objects for replication to external preservation platforms and/or required action in case of failed fixity checks;

  • Electronic Thesis & Dissertation submission processes involving (e.g.) student deposit, committee and/or departmental approval, centralized/ graduate school review, and a final graduation step.

Defined Under Namespace

Classes: Agent, Comment, ConversionError, Entity, EntitySpecificResponsibility, Method, NotifiableContext, Notification, NotificationRecipient, Role, StateError, Workflow, WorkflowAction, WorkflowResponsibility, WorkflowRole, WorkflowState, WorkflowStateAction, WorkflowStateActionPermission

Class Method Summary collapse

Class Method Details

.Agent(input, &block) ⇒ Sipity::Agent

Cast a given input (e.g. a ::User or Hyrax::Group to a Agent).

Parameters:

  • input (Object)

Returns:


42
43
44
45
46
47
48
49
# File 'app/models/sipity.rb', line 42

def Agent(input, &block) # rubocop:disable Naming/MethodName
  result = case input
           when Sipity::Agent
             input
           end

  handle_conversion(input, result, :to_sipity_agent, &block)
end

.Entity(input, &block) ⇒ Sipity::Entity

Cast an object to an Entity

rubocop:disable Naming/MethodName, Metrics/CyclomaticComplexity, Metrics/MethodLength

Parameters:

  • input (Object)

Returns:


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/sipity.rb', line 59

def Entity(input, &block)
  result = case input
           when Sipity::Entity
             input
           when URI::GID, GlobalID
             Entity.find_by(proxy_for_global_id: input.to_s)
           when SolrDocument
             Entity(input.to_model)
           when Draper::Decorator
             Entity(input.model)
           when Sipity::Comment
             Entity(input.entity)
           when Valkyrie::Resource
             Entity(Hyrax::GlobalID(input))
           else
             Entity(input.to_global_id) if input.respond_to?(:to_global_id)
           end

  handle_conversion(input, result, :to_sipity_entity, &block)
rescue URI::GID::MissingModelIdError
  Entity(nil)
end

.handle_conversion(input, result, method_name) ⇒ Object

Provides compatibility with the old `PowerConverter` conventions

Raises:


142
143
144
145
146
147
148
# File 'app/models/sipity.rb', line 142

def handle_conversion(input, result, method_name)
  result ||= input.try(method_name)
  return result unless result.nil?
  return yield if block_given?

  raise ConversionError.new(input) # rubocop:disable Style/RaiseArgs
end

.Role(input, &block) ⇒ Object

Cast an object to an Role


86
87
88
89
90
91
92
93
94
95
# File 'app/models/sipity.rb', line 86

def Role(input, &block) # rubocop:disable Naming/MethodName
  result = case input
           when Sipity::Role
             input
           when String, Symbol
             Sipity::Role.find_or_create_by(name: input)
           end

  handle_conversion(input, result, :to_sipity_role, &block)
end

.WorkflowAction(input, workflow, &block) ⇒ Object

Cast an object to a WorkflowAction in a given workflow


100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/sipity.rb', line 100

def WorkflowAction(input, workflow, &block) # rubocop:disable Naming/MethodName
  workflow_id = PowerConverter.convert_to_sipity_workflow_id(workflow)

  result = case input
           when WorkflowAction
             input if input.workflow_id == workflow_id
           when String, Symbol
             WorkflowAction.find_by(workflow_id: workflow_id, name: input.to_s)
           end

  handle_conversion(input, result, :to_sipity_action, &block)
end

.WorkflowState(input, workflow, &block) ⇒ Object

Cast an object to a WorkflowState in a given workflow


116
117
118
119
120
121
122
123
124
125
# File 'app/models/sipity.rb', line 116

def WorkflowState(input, workflow, &block) # rubocop:disable Naming/MethodName
  result = case input
           when Sipity::WorkflowState
             input
           when Symbol, String
             WorkflowState.find_by(workflow_id: workflow.id, name: input)
           end

  handle_conversion(input, result, :to_sipity_workflow_state, &block)
end