Mixing a participant with fields in a condition

16 views
Skip to first unread message

Mario Camou

unread,
Jun 25, 2012, 6:28:37 AM6/25/12
to ruote
Hi,

I have an _if in a workflow where I need to check the values of a couple of fields and also call a participant. This would be the pseudocode:

if ( ! (f:slot.blocked or f:slot.status == BLOCKED) or check_permissions) do
  // whatever
end

Where slot.blocked and slot.status are workitem fields and check_permissions is a participant which gets some data from the workitem, accesses a REST service and returns true if the user is allowed to perform the action. What I currently have is this:

sequence do
  set 'v:blocked' => 'yes'

  _if '${f:slot.blocked} == true or ${f:slot.status} == BLOCKED' do
    _if do
      # Slot is blocked. Can the user open a blocked slot?
      check_permissions
        
      set 'v:blocked' => 'no'
    end

    # Implicit else (check_permissions): slot is blocked and user unauthorized
    set 'v:blocked' => 'no'
  end
       
  _if '${v:blocked} == yes' do
    // whatever
  end
end

This looks to me to be unnecessarily verbose. So, is there a way of combining variables and participant calls in an _if?

Thanks,
-Mario.


Mario Camou | Co-Founder
ma...@abstra.cc

Tanto este mensaje como todos los posibles documentos adjuntos al mismo, son confidenciales y están dirigidos exclusivamente a los destinatarios de los mismos. Por favor, si Usted no es uno de dichos destinatarios, notifíquenos este hecho y elimine el mensaje de su sistema. Queda prohibida la copia, difusión o revelación de su contenido a terceros sin el previo consentimiento por escrito de “ABSTRA CC FACTORIA SOFTWARE, S.A.”. En caso contrario, vulnerará la legislación vigente. Sus datos figuran en un fichero propiedad de "ABSTRA CC FACTORIA SOFTWARE, S.A.". Si desea acceder a sus datos, rectificarlos, cancelarlos u oponerse a su tratamiento, diríjase por escrito a "ABSTRA CC FACTORIA SOFTWARE, S.A.", C/ Boix y Morer, 6, 7 planta de Madrid, CP-28003.

Both this message and all possible documents attached to it, are confidential and are intended exclusively to recipients of them. Please, if you are not one of those recipients, notify us of this fact and delete the message from your system. Copying, dissemination or disclosure of their contents to third parties without the prior written consent of "ABSTRA CC FACTORIA SOFTWARE, S.A." is prohibited. Otherwise, you violate the legislation in force. Your data are contained in a file property of "ABSTRA CC FACTORIA SOFTWARE, S.A.". If you want to access your data, rectify them, cancel them or oppose its processing, submit in writing to "ABSTRA CC FACTORIA SOFTWARE, S.A.", C/ Boix y Morer, 6, 7 floor Madrid, CP-28003.

John Mettraux

unread,
Jun 25, 2012, 8:52:36 AM6/25/12
to openwfe...@googlegroups.com

On Mon, Jun 25, 2012 at 12:28:37PM +0200, Mario Camou wrote:
>
> I have an _if in a workflow where I need to check the values of a couple of
> fields and also call a participant. This would be the pseudocode:
>
> if ( ! (f:slot.blocked or f:slot.status == BLOCKED) or check_permissions) do
> // whatever
> end
>
> Where slot.blocked and slot.status are workitem fields and
> check_permissions is a participant which gets some data from the workitem,
> accesses a REST service and returns true if the user is allowed to perform
> the action. What I currently have is this:
>
> (snip)

Hello Mario,

I tend to do it this way:

---8<---
pdef = Ruote.define do

#set 'blocked' => false
set 'permitted' => false

check_status 'blocked'
check_permissions if '${blocked}'

# not blocked or permitted

_if 'not ${blocked} or ${permitted}' do
# do it
end
#
# or
#
do_it :if => 'not ${blocked} or ${permitted}'
end

class StatusChecker
include Ruote::LocalParticipant

def on_workitem

status_name = param_text()

workitem[status_name] =
workitem["slot.#{status_name}"] ||
workitem["slot.status"] == status_name

reply
end

def on_cancel

# nothing to do
end
end

class PermissionChecker
include Ruote::LocalParticipant

def on_workitem

workitem['permitted'] = do_that_rest_call

reply
end

def on_cancel

# nothing to do
end
end

ruote.register 'check_status', StatusChecker
ruote.register 'check_permissions', PermissionChecker
--->8---

I think it reads better than nested ifs. I try to reuse the participants for
status checking and permission checking across the process portfolio.


I hope it helps.

--
John Mettraux - http://lambda.io/jmettraux

Reply all
Reply to author
Forward
0 new messages