Ejemplo n.º 1
0
 public function __construct($options = array())
 {
     common_user_auth_Service::singleton()->startSession(new core_kernel_users_GenerisUser(new core_kernel_classes_Resource(TAO_INSTALLATOR)));
     $this->processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->localNS = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     $this->unserialize = isset($options['unserialize']) ? (int) $options['unserialize'] : 0;
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource processExecution
  * @param  array options
  * @return boolean
  */
 public function __construct(core_kernel_classes_Resource $processExecution, $options = array())
 {
     $returnValue = (bool) false;
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->activityExecutions = $processExecutionService->getExecutionHistory($processExecution);
     parent::__construct($this->activityExecutions, $options);
     return (bool) $returnValue;
 }
 /**
  * Short description of method getSubgridRows
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string rowId
  * @return array
  */
 public function getSubgridRows($rowId)
 {
     $returnValue = array();
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $processInstance = new core_kernel_classes_Resource($rowId);
     $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
     $returnValue = array_keys($currentActivityExecutions);
     return (array) $returnValue;
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     //validate ALL posted values:
     $processExecutionUri = urldecode($this->getRequestParameter('processExecutionUri'));
     if (!empty($processExecutionUri) && common_Utils::isUri($processExecutionUri)) {
         $this->processExecution = new core_kernel_classes_Resource($processExecutionUri);
     }
     $activityExecutionUri = urldecode($this->getRequestParameter('activityExecutionUri'));
     if (!empty($activityExecutionUri) && common_Utils::isUri($activityExecutionUri)) {
         $this->activityExecution = new core_kernel_classes_Resource($activityExecutionUri);
     }
     $this->setSuccess(false);
 }
 public function initProcessExecution($posted)
 {
     //set_time_limit(200);
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG);
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $processDefinitionUri = urldecode($posted['executionOf']);
     $processDefinition = new core_kernel_classes_Resource($processDefinitionUri);
     $processExecName = $posted["variables"][RDFS_LABEL];
     $processExecComment = 'Created in Processes server on ' . date(DATE_ISO8601);
     $processVariables = $posted["variables"];
     $newProcessExecution = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment, $processVariables);
     //create nonce to initial activity executions:
     foreach ($processExecutionService->getCurrentActivityExecutions($newProcessExecution) as $initialActivityExecution) {
         $activityExecutionService->createNonce($initialActivityExecution);
     }
     helpers_TimeOutHelper::reset();
     $param = array('processUri' => urlencode($newProcessExecution->getUri()));
     $this->redirect(tao_helpers_Uri::url('index', 'ProcessBrowser', null, $param));
 }
 public function __construct()
 {
     parent::__construct();
     $this->processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     //validate ALL posted values:
     $processExecutionUri = urldecode($this->getRequestParameter('processUri'));
     if (!empty($processExecutionUri) && common_Utils::isUri($processExecutionUri)) {
         $processExecution = new core_kernel_classes_Resource($processExecutionUri);
         //check that the process execution is not finished or closed here:
         if ($this->processExecutionService->isFinished($processExecution)) {
             common_Logger::w('Cannot browse a finished process execution');
             $this->redirectToMain();
         } else {
             $this->processExecution = $processExecution;
             $activityExecutionUri = urldecode($this->getRequestParameter('activityUri'));
             if (!empty($activityExecutionUri) && common_Utils::isUri($activityExecutionUri)) {
                 $activityExecution = new core_kernel_classes_Resource($activityExecutionUri);
                 $currentActivityExecutions = $this->processExecutionService->getCurrentActivityExecutions($this->processExecution);
                 //check if it is a current activity exec:
                 if (array_key_exists($activityExecutionUri, $currentActivityExecutions)) {
                     $this->activityExecution = $activityExecution;
                     //if ok, check the nonce:
                     $nc = $this->getRequestParameter('nc');
                     if ($this->activityExecutionService->checkNonce($this->activityExecution, $nc)) {
                         $this->activityExecutionNonce = true;
                     } else {
                         $this->activityExecutionNonce = false;
                     }
                 } else {
                     //the provided activity execution is no longer the current one (link may be outdated).
                     //the user is redirected to the current activity execution if allowed,
                     //or redirected to "main" if there are more than one allowed current activity execution or none
                     common_Logger::w('The provided activity execution is no longer the current one');
                     $this->autoRedirecting = true;
                 }
             }
         }
     }
 }
 /**
  * Short description of method getValue
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string rowId
  * @param  string columnId
  * @param  string data
  * @return mixed
  */
 public function getValue($rowId, $columnId, $data = null)
 {
     $returnValue = null;
     if (isset($this->data[$rowId])) {
         //return values:
         if (isset($this->data[$rowId][$columnId])) {
             $returnValue = $this->data[$rowId][$columnId];
         }
     } else {
         if (common_Utils::isUri($rowId)) {
             $excludedProperties = is_array($this->options) && isset($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array();
             $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
             $processInstance = new core_kernel_classes_Resource($rowId);
             $this->data[$rowId] = array();
             if (!in_array(RDFS_LABEL, $excludedProperties)) {
                 $this->data[$rowId][RDFS_LABEL] = $processInstance->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_STATUS, $excludedProperties)) {
                 $status = $processExecutionService->getStatus($processInstance);
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_STATUS] = is_null($status) ? 'n/a' : $status->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_EXECUTIONOF, $excludedProperties)) {
                 $executionOf = $processExecutionService->getExecutionOf($processInstance);
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_EXECUTIONOF] = is_null($executionOf) ? 'n/a' : $executionOf->getLabel();
             }
             if (!in_array(PROPERTY_PROCESSINSTANCES_TIME_STARTED, $excludedProperties)) {
                 $time = (string) $processInstance->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_TIME_STARTED));
                 $this->data[$rowId][PROPERTY_PROCESSINSTANCES_TIME_STARTED] = !empty($time) ? date('d-m-Y G:i:s', $time) : 'n/a';
             }
             //				if(!in_array(PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS, $excludedProperties)){
             //					$currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
             //					$this->data[$rowId][PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS] = new wfAuthoring_helpers_Monitoring_ActivityMonitoringGrid(array_keys($currentActivityExecutions));
             //				}
             if (isset($this->data[$rowId][$columnId])) {
                 $returnValue = $this->data[$rowId][$columnId];
             }
         }
     }
     return $returnValue;
 }
 public function run()
 {
     //set_time_limit(200);
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG);
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $processDefinitionUri = $this->getRequestParameter('processDefinition');
     $processDefinition = new core_kernel_classes_Resource($processDefinitionUri);
     if (!$this->hasRequestParameter('serviceCallId')) {
         throw new common_exception_Error('No serviceCallId on service call');
     }
     $serviceService = tao_models_classes_service_StateStorage::singleton();
     $userUri = common_session_SessionManager::getSession()->getUserUri();
     $processExecutionUri = is_null($userUri) ? null : $serviceService->get($userUri, $this->getRequestParameter('serviceCallId'));
     if (is_null($processExecutionUri)) {
         $processExecName = $processDefinition->getLabel();
         $processExecComment = 'Created in Processes server on ' . date(DATE_ISO8601);
         if (isset($_REQUEST['processVariables']) && !empty($_REQUEST['processVariables'])) {
             $processVariables = json_decode($_REQUEST['processVariables'], true);
             $processVariables = is_array($processVariables) ? $processVariables : array();
         } else {
             // none provided
             $processVariables = array();
         }
         $newProcessExecution = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment, $processVariables);
         $processExecutionUri = $newProcessExecution->getUri();
         $serviceService->set($userUri, $this->getRequestParameter('serviceCallId'), $processExecutionUri);
     }
     $processExecution = new core_kernel_classes_Resource($processExecutionUri);
     //create nonce to initial activity executions:
     foreach ($processExecutionService->getCurrentActivityExecutions($processExecution) as $initialActivityExecution) {
         $activityExecutionService->createNonce($initialActivityExecution);
     }
     helpers_TimeOutHelper::reset();
     $param = array('processUri' => urlencode($processExecution->getUri()), 'standalone' => 'true');
     $this->redirect(tao_helpers_Uri::url('index', null, null, $param));
 }
 /**
  * Test the sequential process execution:
  */
 public function testVirtualSequencialProcess()
 {
     error_reporting(E_ALL);
     try {
         $t_start = microtime(true);
         $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
         $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
         $activityExecutionService->cache = (bool) self::SERVICE_CACHE;
         $this->service = wfEngine_models_classes_ProcessExecutionService::singleton();
         //create a new process def
         $processDefinition = $authoringService->createProcess('ProcessForUnitTest', 'Unit test');
         $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
         //define activities and connectors
         $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
         $this->assertNotNull($activity1);
         $authoringService->setFirstActivity($processDefinition, $activity1);
         $connector1 = null;
         $connector1 = $authoringService->createConnector($activity1);
         $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector1);
         $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
         $this->assertNotNull($activity2);
         $connector2 = null;
         $connector2 = $authoringService->createConnector($activity2);
         $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector2);
         $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3');
         $this->assertNotNull($activity3);
         $connector3 = null;
         $connector3 = $authoringService->createConnector($activity3);
         $authoringService->setConnectorType($connector3, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector3);
         $activity4 = $authoringService->createSequenceActivity($connector3, null, 'activity4');
         $this->assertNotNull($activity4);
         $connector4 = null;
         $connector4 = $authoringService->createConnector($activity4);
         $authoringService->setConnectorType($connector4, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector4);
         $activity5 = $authoringService->createSequenceActivity($connector4, null, 'activity5');
         $this->assertNotNull($activity5);
         //run the process
         $processExecName = 'Test Process Execution';
         $processExecComment = 'created for processExecustionService test case by ' . __METHOD__;
         $processInstance = $this->service->createProcessExecution($processDefinition, $processExecName, $processExecComment);
         $this->assertEquals($processDefinition->getUri(), $this->service->getExecutionOf($processInstance)->getUri());
         $this->assertEquals($processDefinition->getUri(), $this->service->getExecutionOf($processInstance)->getUri());
         $this->assertTrue($this->service->checkStatus($processInstance, 'started'));
         $this->out(__METHOD__, true);
         $currentActivityExecutions = $this->service->getCurrentActivityExecutions($processInstance);
         $this->assertEquals(count($currentActivityExecutions), 1);
         $this->assertEquals(strpos(array_pop($currentActivityExecutions)->getLabel(), 'Execution of activity1'), 0);
         $this->out("<strong>Forward transitions:</strong>", true);
         $previousActivityExecution = null;
         //to test undoing the transitions
         $iterationNumber = 5;
         $i = 1;
         while ($i <= $iterationNumber) {
             if ($i < $iterationNumber) {
                 //try deleting a process that is not finished
                 $this->assertFalse($this->service->deleteProcessExecution($processInstance, true));
             }
             $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
             $this->assertEquals(count($activitieExecs), 1);
             $activityExecution = reset($activitieExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExecution);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             //init execution
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
             //transition to next activity
             $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
             //try undoing the transition:
             switch ($i) {
                 case 2:
                 case 4:
                     $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                     $this->assertEquals(count($activitieExecs), 1);
                     $activity = $activityExecutionService->getExecutionOf(reset($activitieExecs));
                     $this->assertTrue($activity->getLabel() == 'activity' . $i);
                     $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                     break;
                 case 3:
                     $history = $this->service->getExecutionHistory($processInstance);
                     $this->assertEquals(count($history), 5);
                     //activity 1, 2(closed), 2, 3 and 4
                     $this->assertFalse($this->service->undoForwardTransition($processInstance, new core_kernel_classes_Resource(reset($history))));
                     $this->assertNotNull($previousActivityExecution);
                     $this->assertFalse($this->service->undoForwardTransition($processInstance, $previousActivityExecution));
                     break;
             }
             if ($i < $iterationNumber) {
                 $this->assertTrue(count($transitionResult) > 0);
             } else {
                 $this->assertFalse(count($transitionResult) > 0);
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             $this->assertFalse($this->service->isPaused($processInstance));
             $previousActivityExecution = $activityExecution;
             $i++;
         }
         $this->assertTrue($this->service->isFinished($processInstance));
         $this->assertTrue($this->service->resume($processInstance));
         $this->out("<strong>Backward transitions:</strong>", true);
         $j = 0;
         while ($j < $iterationNumber) {
             $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
             $this->assertEquals(count($activitieExecs), 1);
             $activityExecution = reset($activitieExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExecution);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $index = $iterationNumber - $j;
             $this->assertEquals($activity->getLabel(), "activity{$index}");
             //init execution
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $transitionResult = $this->service->performBackwardTransition($processInstance, $activityExecution);
             $processStatus = $this->service->getStatus($processInstance);
             $this->assertNotNull($processStatus);
             $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             if ($j < $iterationNumber - 1) {
                 $this->assertTrue(count($transitionResult) > 0);
             } else {
                 $this->assertFalse($transitionResult);
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             $j++;
         }
         $this->out("<strong>Forward transitions again:</strong>", true);
         $previousActivityExecution = null;
         $i = 1;
         while ($i <= $iterationNumber) {
             if ($i < $iterationNumber) {
                 //try deleting a process that is not finished
                 $this->assertFalse($this->service->deleteProcessExecution($processInstance, true));
             }
             $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
             $this->assertEquals(count($activitieExecs), 1);
             $activityExecution = reset($activitieExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExecution);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             //init execution
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             if ($i == 1) {
                 $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             } else {
                 $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
             }
             //transition to next activity
             $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
             //try undoing the transition:
             switch ($i) {
                 case 2:
                 case 3:
                     $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                     $this->assertEquals(count($activitieExecs), 1);
                     $activity = $activityExecutionService->getExecutionOf(reset($activitieExecs));
                     $this->assertTrue($activity->getLabel() == 'activity' . $i);
                     $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                     break;
                 case 3:
                 case 4:
                     $history = $this->service->getExecutionHistory($processInstance);
                     $this->assertFalse($this->service->undoForwardTransition($processInstance, new core_kernel_classes_Resource(reset($history))));
                     $this->assertNotNull($previousActivityExecution);
                     $this->assertFalse($this->service->undoForwardTransition($processInstance, $previousActivityExecution));
                     break;
             }
             if ($i < $iterationNumber) {
                 $this->assertTrue(count($transitionResult) > 0);
             } else {
                 $this->assertFalse(count($transitionResult) > 0);
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             $this->assertFalse($this->service->isPaused($processInstance));
             $previousActivityExecution = $activityExecution;
             $i++;
         }
         $this->assertTrue($this->service->isFinished($processInstance));
         $t_end = microtime(true);
         $duration = $t_end - $t_start;
         $this->out('Elapsed time: ' . $duration . 's', true);
         //delete processdef:
         $this->assertTrue($authoringService->deleteProcess($processDefinition));
         //delete process execution:
         $this->assertTrue($processInstance->exists());
         $this->assertTrue($this->service->deleteProcessExecution($processInstance));
         $this->assertFalse($processInstance->exists());
         if (!is_null($this->currentUser)) {
             $this->userService->logout();
             $this->userService->removeUser($this->currentUser);
         }
     } catch (common_Exception $ce) {
         $this->fail($ce);
     }
 }
 /**
  * Test the notifications in a sequencial process
  */
 public function testNotificationsInProcess()
 {
     try {
         $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
         $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
         $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
         $roleService = wfEngine_models_classes_RoleService::singleton();
         //create a new process def
         $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
         $processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
         $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
         $aclModeRole = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE);
         $aclModeUser = new core_kernel_classes_Resource(INSTANCE_ACL_USER);
         $wfRole = new core_kernel_classes_Resource(INSTANCE_ROLE_WORKFLOW);
         $role1 = $roleService->addRole('Role 1', $wfRole);
         $role2 = $roleService->addRole('Role 2', $wfRole);
         $roleService->setRoleToUsers($role2, array($this->currentUser));
         //define activities and connectors
         $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
         $this->assertNotNull($activity1);
         $authoringService->setFirstActivity($processDefinition, $activity1);
         //activity is allowed to the created role
         $activityExecutionService->setAcl($activity1, $aclModeRole, $role2);
         $connector1 = null;
         $connector1 = $authoringService->createConnector($activity1);
         $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector1);
         $this->service->bindProperties($connector1, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_USER, PROPERTY_CONNECTORS_USER_NOTIFIED => $this->currentUser->getUri(), PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 1 notification to user ' . $this->currentUser->getLabel()));
         $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
         $this->assertNotNull($activity2);
         //2nd activity is allowed to create role
         $activityExecutionService->setAcl($activity2, $aclModeRole, $role2);
         $connector2 = null;
         $connector2 = $authoringService->createConnector($activity2);
         $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector2);
         $this->service->bindProperties($connector2, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_PREVIOUS, PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 2 notification to previous activity user ' . $this->currentUser->getLabel()));
         $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3');
         $this->assertNotNull($activity3);
         $connector3 = null;
         $connector3 = $authoringService->createConnector($activity3);
         $authoringService->setConnectorType($connector3, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector3);
         $this->service->bindProperties($connector3, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_NEXT, PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 3 notification to next activity user ' . $this->currentUser->getLabel()));
         $activity4 = $authoringService->createSequenceActivity($connector3, null, 'activity4');
         $this->assertNotNull($activity4);
         //allowed to the currentUser only
         $activityExecutionService->setAcl($activity4, $aclModeUser, $this->currentUser);
         $connector4 = null;
         $connector4 = $authoringService->createConnector($activity4);
         $authoringService->setConnectorType($connector4, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector4);
         $this->service->bindProperties($connector4, array(PROPERTY_CONNECTORS_NOTIFY => INSTANCE_NOTIFY_ROLE, PROPERTY_CONNECTORS_ROLE_NOTIFIED => $role2->getUri(), PROPERTY_CONNECTORS_NOTIFICATION_MESSAGE => 'Connector 4 notification to role user ' . $role2->getLabel()));
         $activity5 = $authoringService->createSequenceActivity($connector4, null, 'activity5');
         $this->assertNotNull($activity5);
         //run the process
         $processExecName = 'Test Process Execution';
         $processExecComment = 'created for Notification service test case by ' . __METHOD__;
         $proc = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment);
         $i = 1;
         while ($i <= 5) {
             $activityExecs = $processExecutionService->getAvailableCurrentActivityExecutions($proc, $this->currentUser);
             $this->assertEquals(count($activityExecs), 1);
             $activityExec = reset($activityExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExec);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             //init execution
             $activityExecution = $processExecutionService->initCurrentActivityExecution($proc, $activityExec, $this->currentUser);
             $this->assertIsA($activityExecution, "core_kernel_classes_Resource");
             //transition to nextactivity
             $transitionResult = $processExecutionService->performTransition($proc, $activityExecution);
             $this->assertFalse($processExecutionService->isPaused($proc));
             $i++;
         }
         $this->assertTrue($processExecutionService->isFinished($proc));
         //check the created notifications
         $notifications = array();
         $notificationProcessExecProp = new core_kernel_classes_Property(PROPERTY_NOTIFICATION_PROCESS_EXECUTION);
         $notificationToProp = new core_kernel_classes_Property(PROPERTY_NOTIFICATION_TO);
         $notificationsToSend = $this->service->getNotificationsToSend();
         $this->assertTrue(count($notificationsToSend) > 0);
         foreach ($this->service->getNotificationsToSend() as $notification) {
             $notificationProcess = $notification->getOnePropertyValue($notificationProcessExecProp);
             if (!is_null($notificationProcess)) {
                 if ($notificationProcess->getUri() == $proc->getUri()) {
                     $notifiedUser = $notification->getOnePropertyValue($notificationToProp);
                     $this->assertNotNull($notifiedUser);
                     $this->assertEquals($notifiedUser->getUri(), $this->currentUser->getUri());
                     $notifications[] = $notification;
                 }
             }
         }
         $notificationCount = count($notifications);
         $this->assertEquals($notificationCount, 4);
         //			$this->out("$notificationCount notifications to be sent");
         //			$this->assertTrue($this->service->sendNotifications(new tao_helpers_transfert_MailAdapter()));
         //			$this->out("All notifications sent");
         //delete notifications:
         foreach ($notifications as $notification) {
             $this->assertTrue($notification->delete());
         }
         $this->assertTrue($role2->delete());
         //delete process exec:
         $this->assertTrue($processExecutionService->deleteProcessExecution($proc));
         //delete processdef:
         $this->assertTrue($authoringService->deleteProcess($processDefinition));
         if (!is_null($this->currentUser)) {
             $this->userService->logout();
             $this->assertTrue($this->userService->removeUser($this->currentUser));
         }
     } catch (common_Exception $ce) {
         $this->fail($ce);
     }
 }
Ejemplo n.º 11
0
 /**
  * 
  * Main page of wfEngine containning 2 sections : 
  *  - Processes Execution in progress or just started
  *  - Processes Definition user may instanciate
  * 
  * @return void
  */
 public function index()
 {
     //init required services
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $processDefinitionService = wfEngine_models_classes_ProcessDefinitionService::singleton();
     $userService = wfEngine_models_classes_UserService::singleton();
     //get current user:
     $currentUser = $userService->getCurrentUser();
     //init variable that save data to be used in the view
     $processViewData = array();
     $userViewData = wfEngine_helpers_UsersHelper::buildCurrentUserForView();
     $this->setData('userViewData', $userViewData);
     //list of available process executions:
     $processInstancesClass = new core_kernel_classes_Class(CLASS_PROCESSINSTANCES);
     $processExecutions = $processInstancesClass->getInstances();
     foreach ($processExecutions as $processExecution) {
         if (!is_null($processExecution) && $processExecution instanceof core_kernel_classes_Resource) {
             try {
                 $processDefinition = $processExecutionService->getExecutionOf($processExecution);
             } catch (wfEngine_models_classes_ProcessExecutionException $e) {
                 $processDefinition = null;
                 $processExecutionService->deleteProcessExecution($processExecution);
                 continue;
             }
             $processStatus = $processExecutionService->getStatus($processExecution);
             if (is_null($processStatus) || !$processStatus instanceof core_kernel_classes_Resource) {
                 continue;
             }
             $currentActivities = array();
             // Bypass ACL Check if possible...
             if ($processStatus->getUri() == INSTANCE_PROCESSSTATUS_FINISHED) {
                 $processViewData[] = array('type' => $processDefinition->getLabel(), 'label' => $processExecution->getLabel(), 'uri' => $processExecution->getUri(), 'activities' => array(array('label' => '', 'uri' => '', 'may_participate' => false, 'finished' => true, 'allowed' => true)), 'status' => $processStatus);
                 continue;
             } else {
                 $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processExecution);
                 foreach ($currentActivityExecutions as $uri => $currentActivityExecution) {
                     $isAllowed = $activityExecutionService->checkAcl($currentActivityExecution, $currentUser, $processExecution);
                     $activityExecFinishedByUser = false;
                     $assignedUser = $activityExecutionService->getActivityExecutionUser($currentActivityExecution);
                     if (!is_null($assignedUser) && $assignedUser->getUri() == $currentUser->getUri()) {
                         $activityExecFinishedByUser = $activityExecutionService->isFinished($currentActivityExecution);
                     }
                     $currentActivity = $activityExecutionService->getExecutionOf($currentActivityExecution);
                     $currentActivities[] = array('label' => $currentActivity->getLabel(), 'uri' => $uri, 'may_participate' => $processStatus->getUri() != INSTANCE_PROCESSSTATUS_FINISHED && $isAllowed, 'finished' => $processStatus->getUri() == INSTANCE_PROCESSSTATUS_FINISHED, 'allowed' => $isAllowed, 'activityEnded' => $activityExecFinishedByUser);
                 }
                 $processViewData[] = array('type' => $processDefinition->getLabel(), 'label' => $processExecution->getLabel(), 'uri' => $processExecution->getUri(), 'activities' => $currentActivities, 'status' => $processStatus);
             }
         }
     }
     //list of available process definitions:
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $availableProcessDefinitions = $processDefinitionClass->getInstances();
     //filter process that can be initialized by the current user (2nd check...)
     $authorizedProcessDefinitions = array();
     foreach ($availableProcessDefinitions as $processDefinition) {
         if ($processDefinitionService->checkAcl($processDefinition, $currentUser)) {
             $authorizedProcessDefinitions[] = $processDefinition;
         }
     }
     $this->setData('availableProcessDefinition', $authorizedProcessDefinitions);
     $this->setData('processViewData', $processViewData);
     $this->setView('main.tpl');
 }
 public function testDeleteCreatedResources()
 {
     if (isset($this->config['delete']) && $this->config['delete'] === false) {
         $this->out('Skip resources deletion');
         return;
     }
     if (!empty($this->properties)) {
         foreach ($this->properties as $prop) {
             $this->assertTrue($prop->delete());
         }
     }
     if (!is_null($this->itemClass)) {
         $this->itemClass->delete();
     }
     if (!empty($this->units)) {
         foreach ($this->units as $unit) {
             $this->assertTrue($unit->delete());
         }
     }
     if (!empty($this->files)) {
         foreach ($this->files as $file) {
             $this->assertTrue($file->delete());
         }
     }
     if (!empty($this->users)) {
         foreach ($this->users as $user) {
             $this->assertTrue($user->delete());
         }
     }
     if (!empty($this->roles)) {
         foreach ($this->roles as $role) {
             $this->assertTrue($role->delete());
         }
     }
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     foreach ($this->processExecutions as $processInstance) {
         if ($processInstance instanceof core_kernel_classes_Resource) {
             $this->assertTrue($processInstance->exists());
             $this->assertTrue($processExecutionService->deleteProcessExecution($processInstance));
             $this->assertFalse($processInstance->exists());
         }
     }
     foreach ($this->processDefinition as $process) {
         if ($process instanceof core_kernel_classes_Resource) {
             $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
             $this->assertTrue($authoringService->deleteProcess($process));
             $this->assertFalse($process->exists());
         }
     }
     if (!empty($this->vars)) {
         foreach ($this->vars as $code => $variable) {
             $deleted = $variable->delete();
             $this->assertTrue($deleted);
             if (!$deleted) {
                 var_dump($code);
             }
         }
     }
 }
 /**
  * Short description of method moveBackward
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource activityExecution
  * @param  Resource processExecution
  * @param  array revertOptions
  * @return array
  */
 public function moveBackward(core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $processExecution, $revertOptions = array())
 {
     $returnValue = array();
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     //fill options:
     $revert = isset($revertOptions['revert']) ? (bool) $revertOptions['revert'] : true;
     $newVariables = isset($revertOptions['newVariables']) && is_array($revertOptions['newVariables']) ? $revertOptions['newVariables'] : array();
     $notResumed = isset($revertOptions['notResumed']) && is_array($revertOptions['notResumeds']) ? $revertOptions['notResumed'] : array();
     //check if the previous connector is not parallel:
     $previousActivityExecutions = array();
     $previous = $activityExecution->getPropertyValues($this->activityExecutionPreviousProperty);
     $count = count($previous);
     for ($i = 0; $i < $count; $i++) {
         if (common_Utils::isUri($previous[$i])) {
             $prevousActivityExecution = new core_kernel_classes_Resource($previous[$i]);
             if (count($prevousActivityExecution->getPropertyValues($this->activityExecutionFollowingProperty)) == 1) {
                 $previousActivityExecutions[$prevousActivityExecution->getUri()] = $prevousActivityExecution;
             } else {
                 return false;
                 //forbidden to go backward of a parallel connector
             }
         }
     }
     if (!empty($previousActivityExecutions)) {
         //set the process' current activity executions:
         $processExecutionService->removeCurrentActivityExecutions($processExecution, array($activityExecution));
         //not performance efficient:
         //			$activityExecution->delete();
         //			$processExecution->removePropertyValues(
         //				new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_ACTIVITYEXECUTIONS),
         //				array(
         //					'like' => false,
         //					'pattern' => array()
         //				));
         //instead, set the current activity execution as closed (i.e. invalidate the path):
         $this->setStatus($activityExecution, 'closed');
         foreach ($previousActivityExecutions as $previousActivityExecution) {
             $previousActivityExecution->removePropertyValues($this->activityExecutionFollowingProperty);
             //manage the additional option to full revert (default behaviour), full merge or partial merge (i.e. redifine some process variable values)
             if (!$revert) {
                 $overwritingVariables = array();
                 if (isset($newVariables[$previousActivityExecution->getUri()])) {
                     $overwritingVariables = $newVariables[$previousActivityExecution->getUri()];
                 }
                 $this->mergeActivityExecutionVariables($previousActivityExecution, array($activityExecution), $processExecution, $overwritingVariables);
             }
             //change the status of the activity executions to 'paused' by default or nothing if not required (parallel branch):
             if (!isset($notResumed[$previousActivityExecution->getUri()])) {
                 $this->setStatus($previousActivityExecution, 'paused');
             }
         }
         if ($processExecutionService->setCurrentActivityExecutions($processExecution, $previousActivityExecutions)) {
             $returnValue = $previousActivityExecutions;
         }
     }
     return (array) $returnValue;
 }
 private function runProcess($processDefinition, $expectedSteps)
 {
     $user = $this->createUser('timmy');
     $this->changeUser('timmy');
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     $processInstance = $processExecutionService->createProcessExecution($processDefinition, $processDefinition->getLabel() . ' instance', '');
     $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
     $steps = 0;
     while (count($currentActivityExecutions) > 0) {
         $steps++;
         $current = array_shift($currentActivityExecutions);
         $transitionResult = $processExecutionService->performTransition($processInstance, $current);
         if ($transitionResult !== false) {
             foreach ($transitionResult as $executed) {
                 $this->assertTrue($executed->hasType(new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION)));
             }
         }
         $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
         foreach ($currentActivityExecutions as $key => $exec) {
             $status = wfEngine_models_classes_ActivityExecutionService::singleton()->getStatus($exec);
             if (!is_null($status) && $status->getUri() == INSTANCE_PROCESSSTATUS_FINISHED) {
                 unset($currentActivityExecutions[$key]);
             }
         }
     }
     $this->assertEquals($steps, $expectedSteps);
     $processExecutionService->deleteProcessExecution($processInstance);
     $user->delete();
     $this->logoutUser();
 }
 /**
  * Test the sequential process execution:
  */
 public function testVirtualSequencialProcess()
 {
     error_reporting(E_ALL);
     try {
         $roleService = wfEngine_models_classes_RoleService::singleton();
         $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
         $activityService = wfEngine_models_classes_ActivityService::singleton();
         $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
         $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
         $processVariableService = wfEngine_models_classes_VariableService::singleton();
         //TEST PLAN :
         //INSTANCE_ACL_ROLE, $roleA
         //INSTANCE_ACL_ROLE_RESTRICTED_USER, $roleB
         //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB (assigned dynamically via process var $role_processVar in activity1)
         //INSTANCE_ACL_USER, $user2	(assigned dynamically via process var $user_processVar in activity2)
         //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB (assigned dynamically via process var $role_processVar in activity1)
         //INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY, $roleA
         //create roles and users:
         $wfRole = new core_kernel_classes_Resource(INSTANCE_ROLE_WORKFLOW);
         $roleA = $roleService->addRole('ACLTestCaseRoleA', $wfRole);
         $roleB = $roleService->addRole('ACLTestCaseRoleB', $wfRole);
         $roleC = $roleService->addRole('ACLTestCaseRoleC', $wfRole);
         list($usec, $sec) = explode(" ", microtime());
         $users = array();
         $users[0] = $usec;
         for ($i = 1; $i <= 6; $i++) {
             $users[] = 'ACLTestCaseUser' . $i . '-' . $usec;
         }
         $user1 = $this->createUser($users[1]);
         $user1->setLabel($users[1]);
         $user2 = $this->createUser($users[2]);
         $user2->setLabel($users[2]);
         $user3 = $this->createUser($users[3]);
         $user3->setLabel($users[3]);
         $user4 = $this->createUser($users[4]);
         $user4->setLabel($users[4]);
         $user5 = $this->createUser($users[5]);
         $user5->setLabel($users[5]);
         $user6 = $this->createUser($users[6]);
         $user6->setLabel($users[6]);
         $roleService->setRoleToUsers($roleA, array($user1->getUri(), $user2->getUri(), $user3->getUri()));
         $roleService->setRoleToUsers($roleB, array($user4->getUri(), $user5->getUri()));
         $roleService->setRoleToUsers($roleC, array($user6->getUri()));
         //create some process variables:
         $user_processVar_key = 'unit_var_user_' . time();
         $user_processVar = $processVariableService->createProcessVariable('Proc Var for user assignation', $user_processVar_key);
         $role_processVar_key = 'unit_var_role_' . time();
         $role_processVar = $processVariableService->createProcessVariable('Proc Var for role assignation', $role_processVar_key);
         //create a new process def
         $processDefinition = $authoringService->createProcess('ProcessForUnitTest', 'Unit test');
         $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
         //define activities and connectors
         //activity 1:
         $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
         $this->assertNotNull($activity1);
         $authoringService->setFirstActivity($processDefinition, $activity1);
         $activityService->setAcl($activity1, new core_kernel_classes_Resource(INSTANCE_ACL_ROLE), $roleA);
         $connector1 = $authoringService->createConnector($activity1);
         $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector1);
         //activity 2:
         $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
         $this->assertNotNull($activity2);
         $activityService->setAcl($activity2, new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER), $roleB);
         $connector2 = $authoringService->createConnector($activity2);
         $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector2);
         //activity 3:
         $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3');
         $this->assertNotNull($activity3);
         $activityService->setAcl($activity3, new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED), $role_processVar);
         $connector3 = $authoringService->createConnector($activity3);
         $authoringService->setConnectorType($connector3, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector3);
         //activity 4:
         $activity4 = $authoringService->createSequenceActivity($connector3, null, 'activity4');
         $this->assertNotNull($activity4);
         $activityService->setAcl($activity4, new core_kernel_classes_Resource(INSTANCE_ACL_USER), $user_processVar);
         $connector4 = $authoringService->createConnector($activity4);
         $authoringService->setConnectorType($connector4, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector4);
         //activity 5:
         $activity5 = $authoringService->createSequenceActivity($connector4, null, 'activity5');
         $this->assertNotNull($activity5);
         $activityService->setAcl($activity5, new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED), $role_processVar);
         $connector5 = $authoringService->createConnector($activity5);
         $authoringService->setConnectorType($connector5, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
         $this->assertNotNull($connector5);
         //activity 6:
         $activity6 = $authoringService->createSequenceActivity($connector5, null, 'activity6');
         $this->assertNotNull($activity6);
         $activityService->setAcl($activity6, new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY), $roleA);
         //run the process
         $processExecName = 'Test Process Execution';
         $processExecComment = 'created for processExecustionService test case by ' . __METHOD__;
         $processInstance = $processExecutionService->createProcessExecution($processDefinition, $processExecName, $processExecComment);
         $this->assertEquals($processDefinition->getUri(), $processExecutionService->getExecutionOf($processInstance)->getUri());
         $this->assertEquals($processDefinition->getUri(), $processExecutionService->getExecutionOf($processInstance)->getUri());
         $this->assertTrue($processExecutionService->checkStatus($processInstance, 'started'));
         $this->out(__METHOD__, true);
         $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
         $this->assertEquals(count($currentActivityExecutions), 1);
         $this->assertEquals(strpos(array_pop($currentActivityExecutions)->getLabel(), 'Execution of activity1'), 0);
         $this->out("<strong>Forward transitions:</strong>", true);
         $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
         $iterationNumber = 6;
         $i = 1;
         while ($i <= $iterationNumber) {
             if ($i < $iterationNumber) {
                 //try deleting a process that is not finished
                 $this->assertFalse($processExecutionService->deleteProcessExecution($processInstance, true));
             }
             $activities = $processExecutionService->getAvailableCurrentActivityDefinitions($processInstance, $this->currentUser);
             $this->assertEquals(count($activities), 1);
             $activity = array_shift($activities);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             $this->out("current user : "******"' . $this->currentUser->getUri() . '"', true);
             $activityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance);
             $activityExecution = reset($activityExecutions);
             $this->checkAccessControl($activityExecution);
             //check ACL:
             switch ($i) {
                 case 1:
                     //INSTANCE_ACL_ROLE, $roleA:
                     $this->checkAclRole($users, $activityExecution, $processInstance);
                     $processVariableService->push($role_processVar_key, $roleB->getUri());
                     break;
                 case 2:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER, $roleB:
                     $this->checkAclRoleRestrictedUser($users, $activityExecution, $processInstance);
                     $processVariableService->push($user_processVar_key, $user2->getUri());
                     break;
                 case 3:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB
                     $this->assertTrue($this->changeUser($users[5]));
                     $this->assertTrue($activityExecutionService->checkAcl($activityExecution, $this->currentUser, $processInstance));
                     $this->assertNotNull($processExecutionService->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser));
                     $this->checkAclRoleRestrictedUserInherited($users, $activityExecution, $processInstance);
                     break;
                 case 4:
                     //INSTANCE_ACL_USER, $user2:
                     $this->checkAclUser($users, $activityExecution, $processInstance);
                     break;
                 case 5:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB:
                     //only user5 can access it normally:
                     $this->checkUser5($users, $activityExecution, $processInstance);
                     break;
                 case 6:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY, $roleA:
                     //only the user of $roleA that executed (the initial acivity belongs to user2:
                     $this->checkAclRoleRestrictedUserDelivery($users, $activityExecution, $processInstance);
                     break;
             }
             //init execution
             $activityExecution = $processExecutionService->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $transitionResult = $processExecutionService->performTransition($processInstance, $activityExecution);
             switch ($i) {
                 case 1:
                 case 3:
                 case 4:
                 case 5:
                     $this->assertFalse(count($transitionResult) > 0);
                     $this->assertTrue($processExecutionService->isPaused($processInstance));
                     break;
                 case 2:
                     $this->assertTrue(count($transitionResult) > 0);
                     $this->assertFalse($processExecutionService->isPaused($processInstance));
                     break;
                 case 6:
                     $this->assertFalse(count($transitionResult) > 0);
                     $this->assertTrue($processExecutionService->isFinished($processInstance));
                     break;
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $processExecutionService->getStatus($processInstance)->getLabel());
             $i++;
         }
         $this->assertTrue($processExecutionService->isFinished($processInstance));
         $this->assertTrue($processExecutionService->resume($processInstance));
         $this->out("<strong>Backward transitions:</strong>", true);
         $j = 0;
         while ($j < $iterationNumber) {
             $activitieExecs = $processExecutionService->getCurrentActivityExecutions($processInstance);
             $this->assertEquals(count($activitieExecs), 1);
             $activityExecution = reset($activitieExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExecution);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $index = $iterationNumber - $j;
             $this->assertEquals($activity->getLabel(), "activity{$index}");
             $this->out("current user : "******"' . $this->currentUser->getUri() . '"', true);
             $this->checkAccessControl($activityExecution);
             //check ACL:
             switch ($index) {
                 case 1:
                     //INSTANCE_ACL_ROLE, $roleA:
                     $this->checkAclRole($users, $activityExecution, $processInstance);
                     break;
                 case 2:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER, $roleB:
                     $this->checkAclRoleRestrictedUser($users, $activityExecution, $processInstance);
                     break;
                 case 3:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB
                     $this->checkAclRoleRestrictedUserInherited($users, $activityExecution, $processInstance);
                     break;
                 case 4:
                     //INSTANCE_ACL_USER, $user2:
                     $this->checkAclUser($users, $activityExecution, $processInstance);
                     break;
                 case 5:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB:
                     //only user5 can access it normally:
                     $this->checkUser5($users, $activityExecution, $processInstance);
                     break;
                 case 6:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY, $roleA:
                     //only the user of $roleA that executed (the initial acivity belongs to user2:
                     $this->checkAclRoleRestrictedUserDelivery($users, $activityExecution, $processInstance);
                     break;
             }
             //init execution
             $activityExecution = $processExecutionService->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $transitionResult = $processExecutionService->performBackwardTransition($processInstance, $activityExecution);
             $processStatus = $processExecutionService->getStatus($processInstance);
             $this->assertNotNull($processStatus);
             $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             if ($j < $iterationNumber - 1) {
                 $this->assertTrue(count($transitionResult) > 0);
             } else {
                 $this->assertFalse($transitionResult);
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $processExecutionService->getStatus($processInstance)->getLabel());
             $j++;
         }
         $this->out("<strong>Forward transitions again:</strong>", true);
         $i = 1;
         while ($i <= $iterationNumber) {
             if ($i < $iterationNumber) {
                 //try deleting a process that is not finished
                 $this->assertFalse($processExecutionService->deleteProcessExecution($processInstance, true));
             }
             $activitieExecs = $processExecutionService->getCurrentActivityExecutions($processInstance);
             $this->assertEquals(count($activitieExecs), 1);
             $activityExecution = reset($activitieExecs);
             $activity = $activityExecutionService->getExecutionOf($activityExecution);
             $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
             $this->assertTrue($activity->getLabel() == 'activity' . $i);
             $this->checkAccessControl($activityExecution);
             //check ACL:
             switch ($i) {
                 case 1:
                     //INSTANCE_ACL_ROLE, $roleA:
                     $this->checkAclRole($users, $activityExecution, $processInstance);
                     //TODO:to be modified after "back"
                     $processVariableService->push($role_processVar_key, $roleB->getUri());
                     break;
                 case 2:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER, $roleB:
                     $this->checkAclRoleRestrictedUser($users, $activityExecution, $processInstance);
                     //TODO:to be modified after "back"
                     $processVariableService->push($user_processVar_key, $user2->getUri());
                     break;
                 case 3:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB
                     $this->checkAclRoleRestrictedUserInherited($users, $activityExecution, $processInstance);
                     break;
                 case 4:
                     //INSTANCE_ACL_USER, $user2:
                     $this->checkAclUser($users, $activityExecution, $processInstance);
                     break;
                 case 5:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED, $roleB:
                     //only user5 can access it normally:
                     $this->checkUser5($users, $activityExecution, $processInstance);
                     break;
                 case 6:
                     //INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY, $roleA:
                     //only the user of $roleA that executed (the initial acivity belongs to user2:
                     $this->checkAclRoleRestrictedUserDelivery($users, $activityExecution, $processInstance);
                     break;
             }
             //init execution
             $activityExecution = $processExecutionService->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             //transition to next activity
             $transitionResult = $processExecutionService->performTransition($processInstance, $activityExecution);
             switch ($i) {
                 case 1:
                 case 3:
                 case 4:
                 case 5:
                     $this->assertFalse(count($transitionResult) > 0);
                     $this->assertTrue($processExecutionService->isPaused($processInstance));
                     break;
                 case 2:
                     $this->assertTrue(count($transitionResult) > 0);
                     $this->assertFalse($processExecutionService->isPaused($processInstance));
                     break;
                 case 6:
                     $this->assertFalse(count($transitionResult) > 0);
                     $this->assertTrue($processExecutionService->isFinished($processInstance));
                     break;
             }
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $processExecutionService->getStatus($processInstance)->getLabel());
             $i++;
         }
         $this->assertTrue($processExecutionService->isFinished($processInstance));
         //delete processdef:
         $this->assertTrue($authoringService->deleteProcess($processDefinition));
         //delete process execution:
         $this->assertTrue($processInstance->exists());
         $this->assertTrue($processExecutionService->deleteProcessExecution($processInstance));
         $this->assertFalse($processInstance->exists());
         if (!is_null($this->currentUser)) {
             $this->userService->logout();
             $this->userService->removeUser($this->currentUser);
         }
         $roleA->delete();
         $roleB->delete();
         $roleC->delete();
         $user1->delete();
         $user2->delete();
         $user3->delete();
         $user4->delete();
         $user5->delete();
         $user6->delete();
         $user_processVar->delete();
         $role_processVar->delete();
     } catch (common_Exception $ce) {
         $this->fail($ce);
     }
 }
 /**
  * Short description of method trigger
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource connector
  * @param  Resource activityExecution
  * @param  Resource processExecution
  * @return int
  */
 public function trigger(core_kernel_classes_Resource $connector, core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $processExecution = null)
 {
     $returnValue = (int) 0;
     if (!is_null($connector) && !is_null($activityExecution)) {
         //initialize properties
         $connectorUserNotifiedProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_USER_NOTIFIED);
         $connectorRoleNotifiedProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_ROLE_NOTIFIED);
         $connectorNextActivitiesProp = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
         $activityExecutionUserProp = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER);
         $activityAclModeProp = new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ACL_MODE);
         $activityAclUserProp = new core_kernel_classes_Property(PROPERTY_ACTIVITIES_RESTRICTED_USER);
         $activityAclRoleProp = new core_kernel_classes_Property(PROPERTY_ACTIVITIES_RESTRICTED_ROLE);
         $connectorService = wfEngine_models_classes_ConnectorService::singleton();
         $transitionRuleService = wfEngine_models_classes_TransitionRuleService::singleton();
         $roleService = wfEngine_models_classes_RoleService::singleton();
         $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
         $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
         if (is_null($processExecution)) {
             $processExecution = $activityExecutionService->getRelatedProcessExecution($activityExecution);
         }
         $users = array();
         //get the notifications mode defined for that connector
         $notifyModes = $connector->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CONNECTORS_NOTIFY));
         foreach ($notifyModes->getIterator() as $notify) {
             $nextActivities = array();
             //get the users regarding the notification mode
             switch ($notify->getUri()) {
                 //users directly defined
                 case INSTANCE_NOTIFY_USER:
                     foreach ($connector->getPropertyValues($connectorUserNotifiedProp) as $userUri) {
                         if (!in_array($userUri, $users)) {
                             $users[] = $userUri;
                         }
                     }
                     break;
                     //users from roles directly defined
                 //users from roles directly defined
                 case INSTANCE_NOTIFY_ROLE:
                     foreach ($connector->getPropertyValues($connectorRoleNotifiedProp) as $roleUri) {
                         foreach ($roleService->getUsers(new core_kernel_classes_Resource($roleUri)) as $userUri) {
                             if (!in_array($userUri, $users)) {
                                 $users[] = $userUri;
                             }
                         }
                     }
                     break;
                     //get the users who have executed the previous activity
                 //get the users who have executed the previous activity
                 case INSTANCE_NOTIFY_PREVIOUS:
                     $previousActivities = array();
                     $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
                     foreach ($connectorService->getPreviousActivities($connector) as $prevActivity) {
                         if ($cardinalityService->isCardinality($prevActivity)) {
                             $previousActivities[] = $cardinalityService->getSource($prevActivity)->getUri();
                         } else {
                             $previousActivities[] = $prevActivity->getUri();
                         }
                     }
                     $activity = $activityExecutionService->getExecutionOf($activityExecution);
                     //check activity execution against connector
                     if (in_array($activity->getUri(), $previousActivities)) {
                         $activityExecutionUser = $activityExecutionService->getActivityExecutionUser($activityExecution);
                         if (!is_null($activityExecutionUser)) {
                             if (!in_array($activityExecutionUser->getUri(), $users)) {
                                 $users[] = $activityExecutionUser->getUri();
                             }
                         }
                     }
                     break;
                     //get the users
                 //get the users
                 case INSTANCE_NOTIFY_THEN:
                     if ($connectorService->getType($connector)->getUri() == INSTANCE_TYPEOFCONNECTORS_CONDITIONAL) {
                         $transitionRule = $connectorService->getTransitionRule($connector);
                         if ($transitionRule instanceof core_kernel_classes_Resource) {
                             $then = $transitionRuleService->getThenActivity($transitionRule);
                             if ($then instanceof core_kernel_classes_Resource) {
                                 $nextActivities[] = $then->getUri();
                             }
                         }
                     } else {
                         //wrong connector type!
                         break;
                     }
                     //do not break, continue to the INSTANCE_NOTIFY_NEXT case
                 case INSTANCE_NOTIFY_ELSE:
                     if (empty($nextActivities)) {
                         if ($connectorService->getType($connector)->getUri() == INSTANCE_TYPEOFCONNECTORS_CONDITIONAL) {
                             $transitionRule = $connectorService->getTransitionRule($connector);
                             if ($transitionRule instanceof core_kernel_classes_Resource) {
                                 $else = $transitionRuleService->getElseActivity($transitionRule);
                                 if ($else instanceof core_kernel_classes_Resource) {
                                     $nextActivities[] = $else->getUri();
                                 }
                             }
                         } else {
                             //wrong connector type!
                             break;
                         }
                     }
                     //do not break, continue to the INSTANCE_NOTIFY_NEXT case
                 case INSTANCE_NOTIFY_NEXT:
                     if (empty($nextActivities)) {
                         $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
                         foreach ($connectorService->getNextActivities($connector) as $nextActivity) {
                             if ($cardinalityService->isCardinality($nextActivity)) {
                                 $nextActivities[] = $cardinalityService->getDestination($nextActivity)->getUri();
                             } else {
                                 $nextActivities[] = $nextActivity->getUri();
                             }
                         }
                     }
                     $nextActivityExecutions = $activityExecutionService->getFollowing($activityExecution);
                     foreach ($nextActivityExecutions as $activityExec) {
                         $activity = $activityExecutionService->getExecutionOf($activityExec);
                         if (!in_array($activity->getUri(), $nextActivities)) {
                             //invalid activity exec
                             continue;
                         }
                         //check if it is among the next activity of the connector:
                         $mode = $activityExecutionService->getAclMode($activityExec);
                         if ($mode instanceof core_kernel_classes_Resource) {
                             switch ($mode->getUri()) {
                                 case INSTANCE_ACL_USER:
                                     $restrictedUser = $activityExecutionService->getRestrictedUser($activityExec);
                                     //@TODO: implemente multiple restricted users?
                                     if (!is_null($restrictedUser)) {
                                         if (!in_array($restrictedUser->getUri(), $users)) {
                                             $users[] = $restrictedUser->getUri();
                                         }
                                     }
                                     break;
                                 case INSTANCE_ACL_ROLE:
                                 case INSTANCE_ACL_ROLE_RESTRICTED_USER:
                                 case INSTANCE_ACL_ROLE_RESTRICTED_USER_INHERITED:
                                     $restrictedRole = $activityExecutionService->getRestrictedRole($activityExec);
                                     //@TODO: implemente multiple restricted roles?
                                     if (!is_null($restrictedRole)) {
                                         foreach ($roleService->getUsers($restrictedRole) as $userUri) {
                                             if (!in_array($userUri, $users)) {
                                                 $users[] = $userUri;
                                             }
                                         }
                                     }
                                     break;
                             }
                         }
                     }
                     break;
             }
         }
         //build notification message for every user here:
         foreach ($users as $userUri) {
             if ($this->createNotification($connector, new core_kernel_classes_Resource($userUri), $activityExecution, $processExecution)) {
                 //get message from connector:
                 //replace SPX in message bodies
                 $returnValue++;
             }
         }
     }
     return (int) $returnValue;
 }