コード例 #1
0
 def assignWorkitem(self, instance_id, workitem_id, actor, REQUEST=None):
     """ Assign the specified workitem of the specified instance to the specified actor (string)"""
     instance, workitem, process, activity = self.getEnvironment(instance_id, workitem_id)
     if REQUEST:
         if [r for r in REQUEST.AUTHENTICATED_USER.getRolesInContext(self) if r in workitem.push_roles]:
             if instance.isActiveOrRunning() and not workitem.status == 'completed' and workitem.actor=='':
                 # check if actor is assignable to workitem's activity
                 workitem.assignTo(actor)
             else:
                 raise "WorkitemActionError","Wrong workitem enviroment"
     else:
         if instance.isActiveOrRunning() and not workitem.status == 'completed' and workitem.actor == '':
             workitem.assignTo(actor)
         else:
             raise "WorkitemActionError","Wrong workitem enviroment"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #2
0
 def completeWorkitem(self, instance_id, workitem_id, REQUEST=None):
     """ declares the completion of the specified workitem of the given instance """
     instance, workitem, process, activity = self.getEnvironment(instance_id, workitem_id)
     if REQUEST:
         actor = REQUEST.AUTHENTICATED_USER.getUserName()
     else:
         actor = 'Engine'
     if REQUEST:
         if not actor == workitem.actor:
             raise "WorkitemActionError","Invalid Workflow Actor"
     if instance.isActiveOrRunning():
         workitem_return_id = None
         if workitem.status in ('active', 'fallout'):
             workitem.setStatus('complete', actor=actor)
             if instance.getActiveWorkitems() == 0 and instance.status!='running':
                 instance.setStatus(status='running', actor=actor)
             if self.isEnd(workitem.process_id, workitem.activity_id):
                 subflow_workitem_id = self.getSubflowWorkitem(instance_id, workitem_id, workitem.process_id)
                 if subflow_workitem_id:
                     self.completeSubflow(instance_id, subflow_workitem_id)
                 else:
                     instance.setStatus(status='complete', actor=actor)
         if activity.isAutoFinish() and not process.end == activity.id and \
            not (activity.kind=='dummy' or activity.kind=='subflow'):
             self.forwardWorkitem(instance_id, workitem_id)
         if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
     else:
         raise "WorkitemActionError","Wrong workitem enviroment"
コード例 #3
0
 def unassignWorkitem(self, instance_id, workitem_id, REQUEST=None):
     """ Unassign the specified workitem """
     instance = getattr(self, instance_id)
     workitem = getattr(instance, str(workitem_id))
     if REQUEST:
         if not [r for r in REQUEST.AUTHENTICATED_USER.getRolesInContext(self) if r in workitem.push_roles]:
             raise "PermissionError","User don't have push role"
     if instance.isActiveOrRunning() and workitem.status != 'completed':
         getattr(instance, workitem_id).assignTo('')
     else:
         raise "WorkitemActionError","Wrong workitem enviroment"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #4
0
 def suspendInstance(self, instance_id=None, REQUEST=None):
     """ suspend a specified instance """
     instance = getattr(self, instance_id)
     if instance.isActiveOrRunning() or instance.status == 'initiated':
         if REQUEST:
             actor=REQUEST.AUTHENTICATED_USER.getUserName()
         else:
             actor='Engine'
         instance.old_status = instance.status
         instance.setStatus(status='suspended', actor=actor)
     else:
         raise "InstanceActionError","Instance in wrong status"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #5
0
 def resumeWorkitem(self, instance_id, workitem_id, REQUEST=None):
     """ declares the resumption of the specified workitem of the given instance """
     instance = getattr(self, instance_id)
     workitem = getattr(instance, str(workitem_id))
     if REQUEST:
         actor = REQUEST.AUTHENTICATED_USER.getUserName()
     else:
         actor = 'Engine'
     if REQUEST:
         if not actor == workitem.actor:
             raise "Invalid Workflow Actor"
     if instance.isActiveOrRunning() and workitem.status == 'suspended' and not workitem.blocked:
         workitem.setStatus('inactive', actor=actor)
     else:
         raise "WorkitemActionError","Wrong workitem enviroment"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #6
0
    def forwardWorkitem(self, instance_id, workitem_id, path=None, REQUEST=None):
        """ instructs openflow to forward the specified workitem """
        instance, workitem, process, activity = self.getEnvironment(instance_id, workitem_id)
        if REQUEST:
            if not REQUEST.AUTHENTICATED_USER.getUserName() == workitem.actor:
                raise "WorkitemActionError","Invalid Workflow Actor"
        destinations = self.getDestinations(instance_id, workitem_id, path)
        new_workitems = []
        if instance.isActiveOrRunning() and \
          (workitem.status == 'complete' and not workitem.forwarded) and \
          not self.isEnd(workitem.process_id, workitem.activity_id):
            activity_to_id_list = map(lambda x : x['activity_to_id'], destinations)
            workitem.addEvent('forwarded to '+ reduce(lambda x, y : x+', '+y, activity_to_id_list))
            workitem_to_id_list = []
            for d in destinations:
                w = instance.getJoiningWorkitem(workitem_id, self)
                if w:
                    w.unblock()
                    workitem_to_id_list.append(w.id)
                else:
                    process_id = d['process_to_id']
                    activity_id = d['activity_to_id']
                    push_roles = getattr(getattr(self,process_id),activity_id).getPushRoles()
                    pull_roles = getattr(getattr(self,process_id),activity_id).getPullRoles()
                    w = instance.addWorkitem(process_id,
                                             activity_id,
                                             d['blocked_init'],
                                             push_roles,
                                             pull_roles)
                    workitem_to_id_list.append(w.id)
                if w.blocked == 0:
                    new_workitems.append(w.id)
                    w.addEvent('arrival from ' + workitem.activity_id)
            # indented with for

            self.linkWorkitems(instance_id, workitem_id, workitem_to_id_list)
        elif (workitem.status == 'complete' and not workitem.forwarded) and \
             self.isEnd(workitem.process_id, workitem.activity_id):
            pass
        else:
            msg=" wid: "+workitem.id+" act_id: "+workitem.activity_id
            msg=msg+" status:"+workitem.status+" forwarded:"+str(workitem.forwarded)
            raise "WorkitemActionError","Wrong workitem enviroment"+msg
        for w in new_workitems:
            self.manageWorkitemCreation(instance_id, w)
        workitem.forwarded=1
        if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #7
0
 def getUserActionsOnInstance(self, instance_id, REQUEST=None):
     """ Return the actions that user can do on the instance (filtered on permissions only)"""
     instance = getattr(self, instance_id)
     actions = {}
     absolute_url = self.absolute_url()
     parameters = '?instance_id=%s'%(instance_id)
     if REQUEST:
         if instance.status == 'initiated':
             actions['Activate'] = absolute_url+'/startInstance'+parameters
         if instance.isActiveOrRunning() or instance.status == 'initiated':
             actions['Suspend'] = absolute_url+'/suspendInstance'+parameters
         if instance.status == 'suspended':
             actions['Resume'] = absolute_url+'/resumeInstance'+parameters
         if instance.status=='complete' or instance.status=='terminate':
             actions['Delete'] = absolute_url+"/deleteInstance?inst_ids:list=%s"%(instance_id)
         if instance.status != 'complete':
             actions['Terminate'] = absolute_url+'/terminateInstance'+parameters
     return actions
コード例 #8
0
 def inactivateWorkitem(self, instance_id, workitem_id, REQUEST=None):
     """ declares the inactivation of the specified workitem of the given instance """
     instance = getattr(self, instance_id)
     workitem = getattr(instance, str(workitem_id))
     if REQUEST:
         actor=REQUEST.AUTHENTICATED_USER.getUserName()
     else:
         actor='Engine'
     if REQUEST:
         if not (actor == workitem.actor or \
            REQUEST.AUTHENTICATED_USER.has_permission('Manage OpenFlow', self)):
             raise "WorkitemActionError","Invalid actor"
     if instance.isActiveOrRunning() and workitem.status == 'active' and not workitem.blocked:
         workitem.setStatus('inactive', actor=actor)
         if instance.getActiveWorkitems() == 0 and instance.status!='running':
             instance.setStatus(status='running', actor=actor)
     else:
         raise "WorkitemActionError","Wrong workitem enviroment"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #9
0
 def activateWorkitem(self, instance_id, workitem_id, actor=None, REQUEST=None):
     """ declares the activation of the specified workitem of the given instance """
     instance = getattr(self, instance_id)
     workitem = getattr(instance, str(workitem_id))
     if REQUEST:
         action_actor=REQUEST.AUTHENTICATED_USER.getUserName()
         if not [r for r in REQUEST.AUTHENTICATED_USER.getRolesInContext(self) if r in workitem.pull_roles]:
             raise "PermissionError","User don't have pull role"
     else:
         action_actor='Engine'
     if instance.isActiveOrRunning() and workitem.status == 'inactive' and not workitem.blocked:
         if actor is not None and workitem.actor == '':
             self.assignWorkitem(instance_id, workitem_id, actor)
         workitem.setStatus('active', actor=action_actor)
         if instance.status!='active':
           instance.setStatus(status='active', actor=action_actor)
     else:
         raise "WorkitemActionError","Wrong workitem enviroment"
     if REQUEST: REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
コード例 #10
0
    def getUserActionsOnWorkitem(self, instance_id, workitem_id, REQUEST=None):
        """ Return the actions that user can do on the workitem (filtered on permissions only)"""
        instance, workitem, process, activity = self.getEnvironment(instance_id, workitem_id)
        actions = {} # { action_name:action_url, ...}
        absolute_url = self.absolute_url()
        parameters = '?instance_id=%s&workitem_id=%s'%(instance_id, workitem_id)
        user_name = REQUEST.AUTHENTICATED_USER.getUserName()
        if REQUEST and instance.isActiveOrRunning():
            #Actions that require pull and use openflow permissions
            if [r for r in REQUEST.AUTHENTICATED_USER.getRolesInContext(self) if r in workitem.pull_roles]:
                #selfAssignWorkitem
                if workitem.status=='inactive' and workitem.actor=='':
                    actions['Self Assign'] = absolute_url+'/selfAssignWorkitem'+parameters
                #suspendWorkitem
                if workitem.status=='inactive' and workitem.actor==user_name and not workitem.blocked:
                    actions['Suspend'] = absolute_url+'/suspendWorkitem'+parameters
                #resumeWorkitem
                if workitem.status=='suspended' and workitem.actor==user_name:
                    actions['Resume'] = absolute_url+'/resumeWorkitem'+parameters
                #falloutWorkitem
                if (workitem.status=='inactive' or workitem.status=='active') \
                   and workitem.actor==user_name\
                   and not workitem.blocked:
                    actions['Fallout'] = absolute_url+'/falloutWorkitem'+parameters
                #Call Application        getUrlApplicationWithParameters
                if workitem.status in ['inactive','active'] \
                   and activity.kind!='subflow'\
                   and not workitem.blocked:
                    actions['Call Application'] = absolute_url+'/'+self.getApplicationUrlWithParameters(instance_id,workitem_id)
            #Actions that require push and use openflow permissions
            if [r for r in REQUEST.AUTHENTICATED_USER.getRolesInContext(self) if r in workitem.push_roles]:
                #assignWorkitem
                if workitem.status=='inactive' and workitem.actor=='':
                    suppl_parameters = '&process_id=%s&activity_id=%s'%(workitem.process_id, workitem.activity_id)
                    if self.id=='portal_openflow':
                        actions['Assign'] = self.aq_parent.absolute_url()+'/pushWorkitem'+parameters+suppl_parameters
                    else:
                        actions['Assign'] = absolute_url+'/manage_pushWorkitem'+parameters+suppl_parameters
                #unassignWorkitem
                if workitem.status=='inactive' and workitem.actor:
                    actions['Unassign'] = absolute_url+'/unassignWorkitem'+parameters
                #falloutWorkitem
                if workitem.status in ['inactive','active']\
                   and not workitem.blocked:
                    actions['Fallout'] = absolute_url+'/falloutWorkitem'+parameters
                #fallinWorkitem
                if workitem.status=='fallout':
                    if self.id=='portal_openflow':
                        actions['Fallin'] = self.aq_parent.absolute_url()+'/chooseFallin'+parameters
                    else:
                        actions['Fallin'] = absolute_url+'/manage_chooseFallin'+parameters
                #endFallinWorkitem
                if workitem.status=='fallout':
                    actions['End Fallin'] = absolute_url+'/endFallinWorkitem'+parameters
            #Actions that require manage openflow permissions
            if REQUEST.AUTHENTICATED_USER.has_permission('Manage OpenFlow', self):
                #activateWorkitem
                if workitem.status=='inactive' and not workitem.blocked:
                    actions['Activate'] = absolute_url+'/activateWorkitem'+parameters
                #completeWorkitem
                if workitem.status=='active':
                    actions['Complete'] = absolute_url+'/completeWorkitem'+parameters
                #forwardWorkitem
                if workitem.status=='complete' and not workitem.forwarded:
                    actions['Forward'] = absolute_url+'/forwardWorkitem'+parameters
                #inactivateWorkitem
                if workitem.status=='active':
                    actions['Inactive'] = absolute_url+'/inactivateWorkitem'+parameters
            #Actions that require user to be workitem's actor
            if workitem.actor==REQUEST.AUTHENTICATED_USER.getUserName():
                #inactivateWorkitem
                if workitem.status=='active':
                    actions['Inactive'] = absolute_url+'/inactivateWorkitem'+parameters
                #Call Application        getUrlApplicationWithParameters
                if workitem.status in ['inactive','active'] \
                   and activity.kind!='subflow'\
                   and not workitem.blocked:
                    actions['Call Application'] = absolute_url+'/'+self.getApplicationUrlWithParameters(instance_id,workitem_id)

        return actions