public function __construct()
 {
     parent::__construct();
     if (!$this->activityExecution->hasType(new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION))) {
         $this->activityExecution = null;
         $this->setErrorMessage(__('The resource is not an activity execution'));
     }
     $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
 }
 public function __construct()
 {
     //init services
     $this->activityService = wfEngine_models_classes_ActivityService::singleton();
     $this->processVariableService = wfEngine_models_classes_VariableService::singleton();
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $this->connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $this->processVariablesClass = new core_kernel_classes_Class(CLASS_PROCESSVARIABLES);
     $this->propertyIsSample = new core_kernel_classes_Property(PROPERTY_IS_SAMPLE);
 }
 /**
  * Short description of method getSubgridRows
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string rowId
  * @return array
  */
 public function getSubgridRows($rowId)
 {
     $returnValue = array();
     $activityExecution = new core_kernel_classes_Resource($rowId);
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $variables = $activityExecutionService->getVariables($activityExecution);
     foreach ($variables as $variableData) {
         $returnValue[$variableData['propertyUri']] = $variableData;
     }
     return (array) $returnValue;
 }
 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);
 }
 /**
  * Short description of method initGrid
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return boolean
  */
 public function initGrid()
 {
     $returnValue = (bool) false;
     if (is_array($this->data)) {
         parent::initGrid();
     } else {
         if ($this->data instanceof core_kernel_classes_Resource && $this->data->hasType(new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION))) {
             $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
             $variables = $activityExecutionService->getVariables($this->data);
             foreach ($variables as $variableData) {
                 $returnValue[$variableData['propertyUri']] = $variableData;
             }
         } else {
             throw new common_Exception('the data is not an array of variables, nor an activity execution resource');
         }
     }
     return (bool) $returnValue;
 }
 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;
                 }
             }
         }
     }
 }
 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 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);
     }
 }
 /**
  * Short description of method getUserActivityExecutionsStack
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource activityExecution
  * @param  Resource user
  * @return array
  */
 public function getUserActivityExecutionsStack(core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $user = null)
 {
     $returnValue = array();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     if (is_null($user)) {
         $user = $activityExecutionService->getActivityExecutionUser($activityExecution);
     }
     if (!is_null($user)) {
         $processExecution = $activityExecutionService->getRelatedProcessExecution($activityExecution);
         $activityDefinition = $activityExecutionService->getExecutionOf($activityExecution);
         $activityExecutionClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
         $activityExecutions = $activityExecutionClass->searchInstances(array(PROPERTY_ACTIVITY_EXECUTION_PROCESSEXECUTION => $processExecution->getUri(), PROPERTY_ACTIVITY_EXECUTION_ACTIVITY => $activityDefinition->getUri(), PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER => $user->getUri()), array('like' => false, 'recursive' => 0));
         $sortedArray = array();
         foreach ($activityExecutions as $activityExec) {
             $time = time();
             $sortKey = $time;
             //compare them
             while (isset($sortedArray[$sortKey])) {
                 $sortKey++;
             }
             $sortedArray[$sortKey] = array('resource' => $activityExec, 'time' => $time);
         }
         ksort($sortedArray);
         foreach ($sortedArray as $sortedData) {
             $returnValue[] = $sortedData;
         }
     }
     return (array) $returnValue;
 }
 /**
  * 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);
     }
 }
 /**
  * 
  * 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');
 }
 private function bashCheckAcl($activityExecution, $authorizedUsers, $unauthorizedUsers = array())
 {
     $currentUser = $this->currentUser;
     if (empty($unauthorizedUsers)) {
         $allLogins = array_keys($this->users);
         //all logins
         $unauthorizedUsers = array_diff($allLogins, $authorizedUsers);
     } else {
         $unauthorizedUsers = array_diff($unauthorizedUsers, $authorizedUsers);
     }
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $processInstance = $activityExecutionService->getRelatedProcessExecution($activityExecution);
     foreach ($unauthorizedUsers as $login) {
         $this->assertTrue($this->changeUser($login));
         $this->assertFalse($activityExecutionService->checkAcl($activityExecution, $this->currentUser, $processInstance));
     }
     foreach ($authorizedUsers as $login) {
         $this->assertTrue($this->changeUser($login));
         $this->assertTrue($activityExecutionService->checkAcl($activityExecution, $this->currentUser, $processInstance));
     }
     //relog initial user:
     $currentLogin = (string) $currentUser->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN));
     $this->assertTrue($this->changeUser($currentLogin));
 }
 /**
  * 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])) {
         if (isset($this->data[$rowId][$columnId])) {
             $returnValue = $this->data[$rowId][$columnId];
         }
     } else {
         if (common_Utils::isUri($rowId)) {
             $this->data[$rowId] = array();
             $activityExecution = new core_kernel_classes_Resource($rowId);
             $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
             $processVariableService = wfEngine_models_classes_VariableService::singleton();
             $unit = $processVariableService->get('unitUri', $activityExecution);
             $countryCode = (string) $processVariableService->get('countryCode', $activityExecution);
             $languageCode = (string) $processVariableService->get('languageCode', $activityExecution);
             if ($unit instanceof core_kernel_classes_Resource && !empty($countryCode) && !empty($languageCode)) {
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
                 //check if it is the translation activity or not:
                 $xliff = null;
                 $vff = null;
                 if ($activity->getLabel() == 'Translate') {
                     $xliffWorkingProperty = $this->getTranslationFileProperty('xliff_working', $countryCode, $languageCode);
                     if (!is_null($xliffWorkingProperty)) {
                         $xliff = $unit->getOnePropertyValue($xliffWorkingProperty);
                     }
                     $vffWorkingProperty = $this->getTranslationFileProperty('vff_working', $countryCode, $languageCode);
                     if (!is_null($vffWorkingProperty)) {
                         $vff = $unit->getOnePropertyValue($vffWorkingProperty);
                     }
                 } else {
                     $xliffProperty = $this->getTranslationFileProperty('xliff', $countryCode, $languageCode);
                     if (!is_null($xliffProperty)) {
                         $xliff = $unit->getOnePropertyValue($xliffProperty);
                     }
                     $vffProperty = $this->getTranslationFileProperty('vff', $countryCode, $languageCode);
                     if (!is_null($vffProperty)) {
                         $vff = $unit->getOnePropertyValue($vffProperty);
                     }
                 }
                 if ($xliff instanceof core_kernel_classes_Resource) {
                     $xliff = new core_kernel_versioning_File($xliff);
                     $this->data[$rowId]['xliff'] = $xliff->getUri();
                     $this->data[$rowId]['xliff_version'] = (string) $processVariableService->get('xliff', $activityExecution);
                 } else {
                     $this->data[$rowId]['xliff'] = 'n/a';
                     $this->data[$rowId]['xliff_version'] = 'n/a';
                 }
                 if ($vff instanceof core_kernel_classes_Resource) {
                     $vff = new core_kernel_versioning_File($vff);
                     $this->data[$rowId]['vff'] = $vff->getUri();
                     $this->data[$rowId]['vff_version'] = (string) $processVariableService->get('vff', $activityExecution);
                 } else {
                     $this->data[$rowId]['vff'] = 'n/a';
                     $this->data[$rowId]['vff_version'] = 'n/a';
                 }
             } else {
                 $this->data[$rowId] = array('xliff' => 'n/a', 'xliff_version' => 'n/a', 'vff' => 'n/a', 'vff_version' => 'n/a');
             }
             if (isset($this->data[$rowId][$columnId])) {
                 $returnValue = $this->data[$rowId][$columnId];
             }
         }
     }
     return $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 tokens into a parallel process
  */
 public function testVirtualParallelJoinProcess()
 {
     error_reporting(E_ALL);
     $t_start = microtime(true);
     //init services
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $processVariableService = wfEngine_models_classes_VariableService::singleton();
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $activityExecutionService->cache = (bool) self::SERVICE_CACHE;
     //process definition
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('PJ processForUnitTest_' . date(DATE_ISO8601), 'created for the unit test of process execution');
     $this->assertNotNull($processDefinition);
     /*
     		                +---------------+
     		                |  activity 0   |
     		                +-------+-------+
     		                        |
     		                    +---v---+
     		                    |  c 0  |   split
     		                    +--+-+--+
     		                       | |
     		          3  +---------+ +---------+  unit_var_12345678
     		             |                     |
     		     +-------v--------+    +-------v------+
     		     |   activity 1   |    |  activity 2  |
     		     +-------+--------+    +--------+-----+
     		             |                      |
     		             +--------+    +--------+
     		                   +--v----v--+
     		                   |   c 2    |    join
     		                   +----+-----+
     		                        |
     		                +-------v--------+
     		                |  activity 3    |
     		                +----------------+
     */
     //activities definitions
     $activity0 = $authoringService->createActivity($processDefinition, 'activity0');
     $this->assertNotNull($activity0);
     $connector0 = null;
     $authoringService->setFirstActivity($processDefinition, $activity0);
     $connector0 = $authoringService->createConnector($activity0);
     $connectorParallele = new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_PARALLEL);
     $authoringService->setConnectorType($connector0, $connectorParallele);
     $this->assertNotNull($connector0);
     $parallelActivity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($parallelActivity1);
     $roleRestrictedUser = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER);
     $activityService->setAcl($parallelActivity1, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector1 = null;
     $connector1 = $authoringService->createConnector($parallelActivity1);
     $this->assertNotNull($connector1);
     $parallelActivity2 = $authoringService->createActivity($processDefinition, 'activity2');
     $this->assertNotNull($parallelActivity2);
     $activityService->setAcl($parallelActivity2, $roleRestrictedUser, $this->testUserRole);
     //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work
     $connector2 = null;
     $connector2 = $authoringService->createConnector($parallelActivity2);
     $this->assertNotNull($connector2);
     //define parallel activities, first branch with constant cardinality value, while the second listens to a process variable:
     $parallelCount1 = 3;
     $parallelCount2 = 5;
     $parallelCount2_processVar_key = 'unit_var_' . time();
     $parallelCount2_processVar = $processVariableService->createProcessVariable('Var for unit test', $parallelCount2_processVar_key);
     $prallelActivitiesArray = array($parallelActivity1->getUri() => $parallelCount1, $parallelActivity2->getUri() => $parallelCount2_processVar);
     $result = $authoringService->setParallelActivities($connector0, $prallelActivitiesArray);
     $this->assertTrue($result);
     //set several split variables:
     $splitVariable1_key = 'unit_split_var1_' . time();
     $splitVariable1 = $processVariableService->createProcessVariable('Split Var1 for unit test', $splitVariable1_key);
     $splitVariable2_key = 'unit_split_var2_' . time();
     $splitVariable2 = $processVariableService->createProcessVariable('Split Var2 for unit test', $splitVariable2_key);
     $splitVariablesArray = array($parallelActivity1->getUri() => array($splitVariable1), $parallelActivity2->getUri() => array($splitVariable1, $splitVariable2));
     $connectorService = wfAuthoring_models_classes_ConnectorService::singleton();
     $connectorService->setSplitVariables($connector0, $splitVariablesArray);
     $prallelActivitiesArray[$parallelActivity2->getUri()] = $parallelCount2;
     $joinActivity = $authoringService->createActivity($processDefinition, 'activity3');
     //join parallel Activity 1 and 2 to "joinActivity"
     $connector1 = wfAuthoring_models_classes_ConnectorService::singleton()->createJoin(array($parallelActivity1, $parallelActivity2), $joinActivity);
     /*
     $authoringService->createJoinActivity($connector1, $joinActivity, '', $parallelActivity1);
     $authoringService->createJoinActivity($connector2, $joinActivity, '', $parallelActivity2);
     */
     //run the process
     $processExecName = 'Test Parallel Process Execution';
     $processExecComment = 'created for processExecustionService test case by ' . __METHOD__;
     $processInstance = $this->service->createProcessExecution($processDefinition, $processExecName, $processExecComment);
     $this->assertTrue($this->service->checkStatus($processInstance, 'started'));
     $this->out(__METHOD__, true);
     $this->out("<strong>Forward transitions:</strong>", true);
     $previousActivityExecution = null;
     $numberActivities = 2 + $parallelCount1 + $parallelCount2;
     $createdUsers = array();
     $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
     for ($i = 1; $i <= $numberActivities; $i++) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $countActivities = count($activitieExecs);
         $activity = null;
         $activityExecution = null;
         if ($countActivities > 1) {
             //select one of the available activities in the parallel branch:
             foreach ($activitieExecs as $activityExecUri => $activityExec) {
                 if (!$activityExecutionService->isFinished($activityExec)) {
                     $activityDefinition = $activityExecutionService->getExecutionOf($activityExec);
                     $activityUri = $activityDefinition->getUri();
                     if (isset($prallelActivitiesArray[$activityUri])) {
                         if ($prallelActivitiesArray[$activityUri] > 0) {
                             $prallelActivitiesArray[$activityUri]--;
                             $activityExecution = $activityExec;
                             $activity = $activityDefinition;
                             break;
                         }
                     }
                 }
             }
         } else {
             if ($countActivities == 1) {
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
             } else {
                 $this->fail('no current activity definition found for the iteration ' . $i);
             }
         }
         $this->out("<strong> Iteration {$i} :</strong>", true);
         $this->out("<strong>" . (is_null($activity) ? 'null' : $activity->getLabel()) . "</strong> (among {$countActivities})");
         //issue : no activity found for the last iteration...
         //init execution
         $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser);
         $this->assertNotNull($activityExecution);
         if ($i == 1) {
             //set value of the parallel thread:
             $processVariableService->push($parallelCount2_processVar_key, $parallelCount2);
             //set some values to the split variables:
             $values1 = array();
             for ($j = 1; $j <= $parallelCount1; $j++) {
                 $values1[] = 'A' . $j;
             }
             $values2 = array();
             for ($j = 1; $j <= $parallelCount2; $j++) {
                 $values2[] = 'B' . $j;
             }
             $processVariableService->push($splitVariable1_key, serialize($values1));
             $processVariableService->push($splitVariable2_key, serialize($values2));
         } else {
             //check dispatched value:
             //				$value1 = $processVariableService->get($splitVariable1_key);
             //				$value2 = $processVariableService->get($splitVariable2_key);
             //				var_dump($value1, $value2);
         }
         $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
         $this->assertNotNull($activityExecStatus);
         $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED);
         //transition to next activity
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $performed = $this->service->performTransition($processInstance, $activityExecution);
         if (!$performed) {
             $this->out('transition failed.');
         }
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
         //try undoing the transition:
         switch ($i) {
             case 1:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), 1);
                 $activityBis = $activityExecutionService->getExecutionOf(reset($activitieExecs));
                 $this->assertTrue($activity->getUri() == $activityBis->getUri());
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
             case 1 + $parallelCount1:
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $history = $this->service->getExecutionHistory($processInstance);
                 $this->assertEquals(count($history), 2 * ($parallelCount1 + $parallelCount2) + 1);
                 //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;
             case 1 + $parallelCount1 + $parallelCount2:
                 $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
                 $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
                 break;
         }
         $previousActivityExecution = $activityExecution;
         if ($this->service->isPaused($processInstance)) {
             //Login another user to execute parallel branch
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             list($usec, $sec) = explode(" ", microtime());
             $login = '******' . $i . '-' . $usec;
             $pass = '******';
             $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW, RDFS_LABEL => $login);
             if (!$this->userService->loginAvailable($login)) {
                 $this->fail('test login already taken');
             }
             $otherUser = $this->testUserClass->createInstanceWithProperties($userData);
             $createdUsers[$otherUser->getUri()] = $otherUser;
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}");
             }
         }
     }
     $this->assertTrue($this->service->isFinished($processInstance));
     $this->assertTrue($this->service->resume($processInstance));
     $this->out("<strong>Backward transitions:</strong>", true);
     //		var_dump($this->service->getAllActivityExecutions($processInstance));
     $j = 0;
     $iterationNumber = 2;
     while ($j < $iterationNumber) {
         $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
         $activityExecution = null;
         $activity = null;
         switch ($j) {
             case 0:
                 $this->assertEquals(count($activitieExecs), 1);
                 //check
                 $activityExecution = reset($activitieExecs);
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
                 break;
             case 1:
                 $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
                 //check
                 $activity = $parallelActivity2;
                 foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                     if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                         $activityExecution = $activityExec;
                     }
                 }
                 if (is_null($activityExecution)) {
                     $activity = $parallelActivity1;
                     foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) {
                         if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) {
                             $activityExecution = $activityExec;
                         }
                     }
                 }
                 $this->assertNotNull($activityExecution);
                 break;
         }
         $this->out("<strong>" . $activity->getLabel() . "</strong>", true);
         //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);
         $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
         $this->out("performing transition ...");
         //transition to next activity
         $transitionResult = $this->service->performBackwardTransition($processInstance, $activityExecution);
         if ($j == 0) {
             $this->assertTrue(count($transitionResult) > 0);
         } else {
             if ($j == $iterationNumber - 1) {
                 //var_dump($transitionResult);
                 $this->assertFalse($transitionResult);
             }
         }
         $processStatus = $this->service->getStatus($processInstance);
         $this->assertNotNull($processStatus);
         $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
         $this->out("process status: " . $processStatus->getLabel());
         $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_PAUSED);
         $j++;
     }
     $this->out("<strong>Forward transitions again:</strong>", true);
     $currentActivityExecutions = $this->service->getCurrentActivityExecutions($processInstance);
     $currentActivityExecutionsCount = count($currentActivityExecutions);
     $this->assertEquals($currentActivityExecutionsCount, $parallelCount1 + $parallelCount2);
     for ($i = 0; $i < $currentActivityExecutionsCount; $i++) {
         $currentActivityExecution = array_pop($currentActivityExecutions);
         $user = $activityExecutionService->getActivityExecutionUser($currentActivityExecution);
         $activityDefinition = $activityExecutionService->getExecutionOf($currentActivityExecution);
         $this->assertNotNull($user);
         $this->assertNotNull($activityDefinition);
         if (!is_null($user) && !is_null($activityDefinition)) {
             $this->userService->logout();
             $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true);
             $login = (string) $user->getUniquePropertyValue($loginProperty);
             $pass = '******';
             if ($this->userService->loginUser($login, $pass)) {
                 $this->currentUser = $this->userService->getCurrentUser();
                 $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"');
             } else {
                 $this->fail("unable to login user {$login}<br>");
             }
             $iterationNo = $i + 1;
             $this->out("<strong>Iteration {$iterationNo}: " . $activityDefinition->getLabel() . "</strong>", true);
             //execute activity:
             $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $currentActivityExecution, $this->currentUser);
             $this->assertNotNull($activityExecution);
             $activityExecStatus = $activityExecutionService->getStatus($activityExecution);
             $this->assertNotNull($activityExecStatus);
             $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED);
             //transition to next activity
             $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
             $this->out("performing transition ...");
             //transition to next activity
             $this->service->performTransition($processInstance, $activityExecution);
             $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
             $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
             //try undoing the transition:
             if ($i < $currentActivityExecutionsCount - 1) {
                 $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution));
             }
         }
     }
     //try undoing the transition:
     $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution));
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2);
     $transitionResult = $this->service->performTransition($processInstance, $activityExecution);
     $this->assertEquals(count($transitionResult), 1);
     $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance);
     $this->assertEquals(count($activitieExecs), 1);
     $activityExecution = reset($activitieExecs);
     $activity = $activityExecutionService->getExecutionOf($activityExecution);
     $this->assertEquals($activity->getUri(), $joinActivity->getUri());
     $this->out("<strong>Executing last activity: " . $activity->getLabel() . "</strong>", true);
     //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
     $this->out("current user: "******"' . $this->currentUser->getUri() . '"');
     $this->out("performing transition ...");
     //transition to next activity
     $this->service->performTransition($processInstance, $activityExecution);
     $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel());
     $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel());
     $this->assertTrue($this->service->isFinished($processInstance));
     $t_end = microtime(true);
     $duration = $t_end - $t_start;
     $this->out('Elapsed time: ' . $duration . 's', true);
     $this->out('deleting created resources:', true);
     //delete process exec:
     $this->assertTrue($this->service->deleteProcessExecution($processInstance));
     //delete processdef:
     $this->assertTrue($authoringService->deleteProcess($processDefinition));
     $parallelCount2_processVar->delete();
     //delete created users:
     foreach ($createdUsers as $createdUser) {
         $this->out('deleting ' . $createdUser->getLabel() . ' "' . $createdUser->getUri() . '"');
         $this->assertTrue($this->userService->removeUser($createdUser));
     }
     if (!is_null($this->currentUser)) {
         $this->userService->logout();
         $this->userService->removeUser($this->currentUser);
     }
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @return mixed
  */
 public function __construct()
 {
     parent::__construct();
     $this->instancesCache = array();
     $this->cache = true;
     $this->instanceProcessFinished = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_FINISHED);
     $this->instanceProcessResumed = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_RESUMED);
     $this->processInstancesClass = new core_kernel_classes_Class(CLASS_PROCESSINSTANCES);
     $this->processInstancesStatusProp = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_STATUS);
     $this->processInstancesExecutionOfProp = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_EXECUTIONOF);
     $this->processInstancesCurrentActivityExecutionsProp = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS);
     $this->processInstancesActivityExecutionsProp = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_ACTIVITYEXECUTIONS);
     $this->processVariablesCodeProp = new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE);
     $this->activityExecutionsClass = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
     $this->activityExecutionsProcessExecutionProp = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_PROCESSEXECUTION);
     $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
 }
 /**
  * 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 {
         //			'PROPERTY_ACTIVITY_EXECUTION_CTX_RECOVERY' => NS_WFENGINE . '#PropertyActivityExecutionsContextRecovery',
         //			'PROPERTY_ACTIVITY_EXECUTION_VARIABLES' => NS_WFENGINE .'#PropertyActivityExecutionsHasVariables',
         //			'PROPERTY_ACTIVITY_EXECUTION_PREVIOUS' => NS_WFENGINE .'#PropertyActivityExecutionsPreviousActivityExecutions',
         //			'PROPERTY_ACTIVITY_EXECUTION_FOLLOWING' => NS_WFENGINE .'#PropertyActivityExecutionsFollowingActivityExecutions',
         //			'PROPERTY_ACTIVITY_EXECUTION_NONCE' => NS_WFENGINE . '#PropertyActivityExecutionsNonce',
         if (common_Utils::isUri($rowId)) {
             $excludedProperties = $this->excludedProperties;
             $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
             $activityExecution = new core_kernel_classes_Resource($rowId);
             $status = $activityExecutionService->getStatus($activityExecution);
             $this->data[$rowId] = array();
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_ACTIVITY, $excludedProperties)) {
                 $activityExecutionOf = $activityExecutionService->getExecutionOf($activityExecution);
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_ACTIVITY] = $activityExecutionOf->getLabel();
             }
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_STATUS, $excludedProperties)) {
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_STATUS] = is_null($status) ? null : $status->getLabel();
             }
             $timeProperties = array(PROPERTY_ACTIVITY_EXECUTION_TIME_CREATED, PROPERTY_ACTIVITY_EXECUTION_TIME_STARTED, PROPERTY_ACTIVITY_EXECUTION_TIME_LASTACCESS);
             foreach ($timeProperties as $timeProperty) {
                 if (!in_array($timeProperty, $excludedProperties)) {
                     $time = (string) $activityExecution->getOnePropertyValue(new core_kernel_classes_Property($timeProperty));
                     $this->data[$rowId][$timeProperty] = !empty($time) ? date('d-m-Y G:i:s', $time) : 'n/a';
                 }
             }
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER, $excludedProperties)) {
                 $user = $activityExecutionService->getActivityExecutionUser($activityExecution);
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER] = is_null($user) ? 'n/a' : $user->getLabel();
             }
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_ACL_MODE, $excludedProperties)) {
                 $aclMode = $activityExecutionService->getAclMode($activityExecution);
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_ACL_MODE] = is_null($aclMode) ? 'n/a' : $aclMode->getLabel();
             }
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_RESTRICTED_USER, $excludedProperties)) {
                 $restricedRole = $activityExecutionService->getRestrictedRole($activityExecution);
                 $restrictedTo = !is_null($restricedRole) ? $restricedRole : $activityExecutionService->getRestrictedUser($activityExecution);
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_RESTRICTED_USER] = is_null($restrictedTo) ? 'n/a' : $restrictedTo->getLabel();
             }
             if (!in_array(PROPERTY_ACTIVITY_EXECUTION_PROCESSEXECUTION, $excludedProperties)) {
                 $processExecution = $activityExecutionService->getRelatedProcessExecution($activityExecution);
                 $this->data[$rowId][PROPERTY_ACTIVITY_EXECUTION_PROCESSEXECUTION] = is_null($processExecution) ? 'n/a' : $processExecution->getUri();
             }
             if (!in_array('runnable', $excludedProperties)) {
                 $runnable = false;
                 $crtUser = wfEngine_models_classes_UserService::singleton()->getCurrentUser();
                 if (!is_null($crtUser)) {
                     /**
                      * @todo the null status should not exist
                      * @see Sam when a change will occur
                      */
                     $runnable = is_null($status) || $status->getUri() != INSTANCE_PROCESSSTATUS_FINISHED && $status->getUri() != INSTANCE_PROCESSSTATUS_CLOSED && $status->getUri() != INSTANCE_PROCESSSTATUS_STOPPED && $activityExecutionService->checkAcl($activityExecution, $crtUser);
                 }
                 $this->data[$rowId]['runnable'] = $runnable;
             }
             if (isset($this->data[$rowId][$columnId])) {
                 $returnValue = $this->data[$rowId][$columnId];
             }
         }
     }
     return $returnValue;
 }
 protected function checkAccessControl($activityExecution)
 {
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     $aclMode = $activityExecutionService->getAclMode($activityExecution);
     $restricedRole = $activityExecutionService->getRestrictedRole($activityExecution);
     $restrictedTo = !is_null($restricedRole) ? $restricedRole : $activityExecutionService->getRestrictedUser($activityExecution);
     $this->assertNotNull($aclMode);
     if (is_null($restrictedTo)) {
         $activity = $activityExecutionService->getExecutionOf($activityExecution);
         $this->fail("cannot get the restricted user or role for the activity execution {$activityExecution->getUri()} of the activity {$activity->getLabel()} ({$activity->getUri()} ");
     }
     $this->out("ACL mode: {$aclMode->getLabel()}; restricted to {$restrictedTo->getLabel()}", true);
 }
 /**
  * Short description of method createNotification
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource connector
  * @param  Resource user
  * @param  Resource activityExecution
  * @param  Resource processExecution
  * @return core_kernel_classes_Resource
  */
 public function createNotification(core_kernel_classes_Resource $connector, core_kernel_classes_Resource $user, core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $processExecution = null)
 {
     $returnValue = null;
     $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton();
     if (is_null($processExecution)) {
         $processExecution = $activityExecutionService->getRelatedProcessExecution($activityExecution);
     }
     $notification = $this->notificationClass->createInstance();
     $notification->setPropertyValue($this->notificationToProp, $user);
     $notification->setPropertyValue($this->notificationProcessExecProp, $processExecution);
     $notification->setPropertyValue($this->notificationConnectorProp, $connector);
     $notification->setPropertyValue($this->notificationSentProp, GENERIS_FALSE);
     $notification->setPropertyValue($this->notificationDateProp, date("Y-m-d H:i:s"));
     //get the message content from the connector
     $content = (string) $connector->getOnePropertyValue($this->connectorNotificationProp);
     if (strlen(trim($content)) > 0) {
         $matches = array();
         $expr = "/{{((http|https|file|ftp):\\/\\/[\\/.A-Za-z0-9_-]+#[A-Za-z0-9]+)}}/";
         if (preg_match_all($expr, $content, $matches)) {
             if (isset($matches[1])) {
                 $termUris = $matches[1];
                 $activity = $activityExecutionService->getExecutionOf($activityExecution);
                 foreach ($termUris as $termUri) {
                     $term = new core_kernel_rules_Term($termUri);
                     $replacement = $term->evaluate(array(VAR_PROCESS_INSTANCE => $processExecution->getUri(), VAR_ACTIVITY_INSTANCE => $activityExecution->getUri(), VAR_ACTIVITY_DEFINITION => $activity->getUri(), VAR_CURRENT_USER => $user->getUri()));
                     if ($replacement instanceof core_kernel_classes_Resource && $replacement->getUri() == INSTANCE_TERM_IS_NULL) {
                         $replacement = '';
                     }
                     $content = str_replace('{{' . $termUri . '}}', $replacement, $content);
                 }
             }
         }
     }
     if (empty($content)) {
         throw new common_Exception('empty notification message');
     }
     $notification->setPropertyValue($this->notificationMessageProp, $content);
     $returnValue = $notification;
     return $returnValue;
 }