/**
  * initialize a test method
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     error_reporting(E_ALL);
     $this->userPassword = '******';
     if (is_null($this->userService)) {
         $this->userService = wfEngine_models_classes_UserService::singleton();
     }
 }
 public static function buildCurrentUserForView()
 {
     $wfUserService = wfEngine_models_classes_UserService::singleton();
     $currentUser = $wfUserService->getCurrentUser();
     // username.
     $data['username'] = (string) $currentUser->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN));
     // user roles.
     $data['roles'] = array();
     $roles = $wfUserService->getUserRoles($currentUser);
     foreach ($roles as $role) {
         $data['roles'][] = array('uri' => $role->getUri(), 'label' => $role->getLabel());
     }
     return $data;
 }
 /**
  * initialize a test method
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     error_reporting(E_ALL);
     if (is_null($this->userService)) {
         $this->userService = wfEngine_models_classes_UserService::singleton();
     }
     $login = '******';
     $pass = '******';
     $langResource = tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG);
     $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => $langResource, PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_FIRSTNAME => 'Sammy', PROPERTY_USER_LASTNAME => 'Norville Rogers', PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW);
     if (!$this->userService->loginAvailable($login)) {
         $this->fail('test login already taken');
     }
     $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER);
     $this->currentUser = $userClass->createInstanceWithProperties($userData);
     $this->assertTrue($this->userService->loginUser($login, $pass));
     $this->service = wfEngine_models_classes_NotificationService::singleton();
 }
 /**
  * initialize a test method
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     if (is_null($this->userService)) {
         $this->userService = wfEngine_models_classes_UserService::singleton();
     }
     list($usec, $sec) = explode(" ", microtime());
     $login = '******';
     $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);
     $this->testUserClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER);
     $this->testUserRole = new core_kernel_classes_Resource(INSTANCE_ROLE_WORKFLOW);
     if (!$this->userService->loginAvailable($login)) {
         $this->fail('test login already taken');
     }
     $this->currentUser = $this->testUserClass->createInstanceWithProperties($userData);
     if ($this->userService->loginUser($login, $pass)) {
         $this->currentUser = $this->userService->getCurrentUser();
         $this->currentUser0 = $this->currentUser;
     }
     $this->service = wfEngine_models_classes_ProcessExecutionService::singleton();
     $this->service->cache = (bool) self::SERVICE_CACHE;
 }
 public function testGetCallUrl()
 {
     //create unique process variables for this unit test only:
     $variableService = wfEngine_models_classes_VariableService::singleton();
     $myProcessVarCode1 = 'myProcessVarCode1' . time();
     $myProcessVarCode2 = 'myProcessVarCode2' . time();
     $myProcessVar1 = $variableService->getProcessVariable($myProcessVarCode1, true);
     $myProcessVar2 = $variableService->getProcessVariable($myProcessVarCode2, true);
     $parameterNames = array('param1' . time(), 'param2' . time(), 'param3' . time(), 'param4' . time());
     $inputParameters = array($parameterNames[0] => $myProcessVar1, $parameterNames[1] => '^' . $myProcessVarCode2, $parameterNames[2] => 'myConstantValue', $parameterNames[3] => null);
     $serviceUrl = 'http://www.myWebSite.com/myServiceScript.php';
     $serviceDefinition1 = $this->authoringService->createServiceDefinition('myServiceDefinition', $serviceUrl, $inputParameters);
     $this->assertNotNull($serviceDefinition1);
     $service1 = $this->authoringService->createInteractiveService($this->activity);
     $this->assertTrue($this->service->isInteractiveService($service1));
     $this->assertTrue($this->authoringService->setCallOfServiceDefinition($service1, $serviceDefinition1));
     //check call url
     $callUrl = $this->service->getCallUrl($service1);
     $this->assertEquals($callUrl, 'http://www.myWebSite.com/myServiceScript.php?');
     //assign actual params:
     for ($i = 1; $i <= 4; $i++) {
         $formalParam = $this->authoringService->getFormalParameter($parameterNames[$i - 1]);
         $this->assertNotNull($formalParam);
         if (!is_null($formalParam) && $formalParam instanceof core_kernel_classes_Resource) {
             $defaultProcessVar = $formalParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE));
             if (!is_null($defaultProcessVar)) {
                 $this->assertTrue($this->authoringService->setActualParameter($service1, $formalParam, $defaultProcessVar->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE));
             } else {
                 $this->assertTrue($this->authoringService->setActualParameter($service1, $formalParam, 'value' . $i));
             }
         }
     }
     //a no-orthodox way to create a valid activity execution :
     $userService = wfEngine_models_classes_UserService::singleton();
     $currentUser = new core_kernel_classes_Resource(LOCAL_NAMESPACE . '#unitTestUser');
     $this->assertNotNull($currentUser);
     $classActivityExecution = new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION);
     $activityExec1 = $classActivityExecution->createInstance('activity exec for interactive service test case');
     $activityExec1->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_CURRENT_USER), $currentUser->getUri());
     $procVarValue1 = 'procVarValue1';
     $procVarValue2 = 'procVarValue2';
     $activityExec1->setPropertyValue(new core_kernel_classes_Property($myProcessVar1->getUri()), $procVarValue1);
     $activityExec1->setPropertyValue(new core_kernel_classes_Property($myProcessVar2->getUri()), $procVarValue2);
     //check call url again
     $callUrl = $this->service->getCallUrl($service1);
     $this->assertEquals(strlen($callUrl), strlen('http://www.myWebSite.com/myServiceScript.php?' . $parameterNames[0] . '=&' . $parameterNames[1] . '=&' . $parameterNames[2] . '=&' . $parameterNames[3] . '=&'));
     //and again:
     $callUrl = $this->service->getCallUrl($service1, $activityExec1);
     $this->assertEquals(strlen($callUrl), strlen('http://www.myWebSite.com/myServiceScript.php?' . $parameterNames[0] . '=procVarValue1&' . $parameterNames[1] . '=procVarValue2&' . $parameterNames[2] . '=value3&' . $parameterNames[3] . '=value4&'));
     $this->assertTrue(strpos($callUrl, $procVarValue1));
     $this->assertTrue(strpos($callUrl, $procVarValue2));
     $this->assertTrue(strpos($callUrl, $parameterNames[2] . '=value3'));
     $this->assertTrue(strpos($callUrl, $parameterNames[3] . '=value4'));
     //delete all created resources:
     $myProcessVar1->delete();
     $myProcessVar2->delete();
     $serviceDefinition1->delete();
     $activityExec1->delete();
     $service1->delete();
     for ($i = 0; $i < 4; $i++) {
         $formalParam = $this->authoringService->getFormalParameter($parameterNames[$i]);
         $this->assertNotNull($formalParam);
         if (!is_null($formalParam) && $formalParam instanceof core_kernel_classes_Resource) {
             $this->assertTrue($formalParam->delete());
         }
     }
 }
 /**
  * Short description of method performTransition
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  Resource processExecution
  * @param  Resource activityExecution
  * @return mixed
  */
 public function performTransition(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $activityExecution)
 {
     $returnValue = null;
     $session = PHPSession::singleton();
     $session->setAttribute("activityExecutionUri", $activityExecution->getUri());
     //check if the transition is possible, e.g. process is not finished
     if ($this->isFinished($processExecution)) {
         return false;
     }
     //init the services
     $activityDefinitionService = wfEngine_models_classes_ActivityService::singleton();
     $connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $userService = wfEngine_models_classes_UserService::singleton();
     $notificationService = wfEngine_models_classes_NotificationService::singleton();
     $currentUser = $userService->getCurrentUser();
     //set the activity execution of the current user as finished:
     if ($activityExecution->exists()) {
         $this->activityExecutionService->finish($activityExecution);
     } else {
         throw new Exception("cannot find the activity execution of the current activity {$activityBeforeTransition->getUri()} in perform transition");
     }
     $activityBeforeTransition = $this->activityExecutionService->getExecutionOf($activityExecution);
     $nextConnector = $activityDefinitionService->getUniqueNextConnector($activityBeforeTransition);
     if (wfEngine_models_classes_ActivityCardinalityService::singleton()->isCardinality($nextConnector)) {
         $nextConnector = wfEngine_models_classes_ActivityCardinalityService::singleton()->getDestination($nextConnector);
     }
     $newActivities = array();
     if (!is_null($nextConnector)) {
         $newActivities = $this->getNewActivities($processExecution, $activityExecution, $nextConnector);
     } else {
         //final activity:
         $this->finish($processExecution);
         return array();
     }
     if ($newActivities === false) {
         //means that the process must be paused before transition: transition condition not fullfilled
         $this->pause($processExecution);
         return false;
     }
     // The actual transition starts here:
     $newActivityExecutions = array();
     if (!is_null($nextConnector)) {
         //trigger the forward transition:
         $newActivityExecutions = $this->activityExecutionService->moveForward($activityExecution, $nextConnector, $newActivities, $processExecution);
         //trigger the notifications
         $notificationService->trigger($nextConnector, $activityExecution, $processExecution);
     }
     //transition done from here: now get the following activities:
     //if the connector is not a parallel one, let the user continue in his current branch and prevent the pause:
     $uniqueNextActivityExecution = null;
     if (!is_null($nextConnector)) {
         if ($connectorService->getType($nextConnector)->getUri() != INSTANCE_TYPEOFCONNECTORS_PARALLEL) {
             if (count($newActivityExecutions) == 1) {
                 //TODO: could do a double check here: if($newActivities[0] is one of the activty found in the current tokens):
                 if ($this->activityExecutionService->checkAcl(reset($newActivityExecutions), $currentUser, $processExecution)) {
                     $uniqueNextActivityExecution = reset($newActivityExecutions);
                 }
             }
         }
     }
     $setPause = true;
     $authorizedActivityExecutions = array();
     if (!count($newActivities) || $activityDefinitionService->isFinal($activityBeforeTransition)) {
         //there is no following activity so the process ends here:
         $this->finish($processExecution);
         return array();
     } elseif (!is_null($uniqueNextActivityExecution)) {
         //we are certain that the next activity would be for the user so return it:
         $authorizedActivityExecutions[$uniqueNextActivityExecution->getUri()] = $uniqueNextActivityExecution;
         $setPause = false;
     } else {
         foreach ($newActivityExecutions as $activityExecutionAfterTransition) {
             //check if the current user is allowed to execute the activity
             if ($this->activityExecutionService->checkAcl($activityExecutionAfterTransition, $currentUser, $processExecution)) {
                 $authorizedActivityExecutions[$activityExecutionAfterTransition->getUri()] = $activityExecutionAfterTransition;
                 $setPause = false;
             } else {
                 continue;
             }
         }
     }
     $returnValue = array();
     //finish actions on the authorized acitivty definitions
     foreach ($authorizedActivityExecutions as $uri => $activityExecutionAfterTransition) {
         // Last but not least ... is the next activity a machine activity ?
         // if yes, we perform the transition.
         /*
          * @todo to be tested
          */
         $activityAfterTransition = $this->activityExecutionService->getExecutionOf($activityExecutionAfterTransition);
         if ($activityDefinitionService->isHidden($activityAfterTransition)) {
             //required to create an activity execution here with:
             $currentUser = $userService->getCurrentUser();
             if (is_null($currentUser)) {
                 throw new wfEngine_models_classes_ProcessExecutionException("No current user found!");
             }
             $activityExecutionResource = $this->initCurrentActivityExecution($processExecution, $activityExecutionAfterTransition, $currentUser, true);
             //force execution of the ghost actiivty
             //service not executed? use curl request?
             if (!is_null($activityExecutionResource)) {
                 $followingActivityExecutions = $this->performTransition($processExecution, $activityExecutionResource);
                 if (is_array($followingActivityExecutions)) {
                     foreach ($followingActivityExecutions as $followingActivityExec) {
                         $returnValue[$followingActivityExec->getUri()] = $followingActivityExec;
                     }
                 }
             } else {
                 throw new wfEngine_models_classes_ProcessExecutionException('the activity execution cannot be created for the hidden activity');
             }
         } else {
             $returnValue[$uri] = $activityExecutionAfterTransition;
         }
     }
     if ($setPause) {
         $this->pause($processExecution);
     } else {
         if (!$this->isFinished($processExecution)) {
             $this->resume($processExecution);
         }
     }
     return $returnValue;
 }
 public function index()
 {
     if (is_null($this->processExecution)) {
         common_Logger::w('ProcessBrowser invoked without processExecution');
         $this->redirectToMain();
         return;
     }
     if ($this->autoRedirecting) {
         $this->autoredirectToIndex();
         return;
     }
     /*
      * @todo: clean usage
      * known use of Session::setAttribute("processUri") in:
      * - taoDelivery_actions_ItemDelivery::runner()
      * - tao_actions_Api::createAuthEnvironment()
      */
     $this->setSessionAttribute("processUri", $this->processExecution->getUri());
     //user data for browser view
     $userViewData = wfEngine_helpers_UsersHelper::buildCurrentUserForView();
     $this->setData('userViewData', $userViewData);
     $browserViewData = array();
     // general data for browser view.
     //init services:
     $userService = wfEngine_models_classes_UserService::singleton();
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $interactiveServiceService = wfEngine_models_classes_InteractiveServiceService::singleton();
     //get current user:
     $currentUser = $userService->getCurrentUser();
     if (is_null($currentUser)) {
         throw new wfEngine_models_classes_ProcessExecutionException("No current user found!");
     }
     //get activity execution from currently available process definitions:
     $currentlyAvailableActivityExecutions = $this->processExecutionService->getAvailableCurrentActivityExecutions($this->processExecution, $currentUser, true);
     $activityExecution = null;
     if (count($currentlyAvailableActivityExecutions) == 0) {
         common_Logger::w('No available current activity exec found: no permission or issue in process execution');
         $this->pause();
         return;
     } else {
         if (!is_null($this->activityExecution) && $this->activityExecution instanceof core_kernel_classes_Resource) {
             foreach ($currentlyAvailableActivityExecutions as $availableActivityExec) {
                 if ($availableActivityExec->getUri() == $this->activityExecution->getUri()) {
                     $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, $this->activityExecution, $currentUser);
                     break;
                 }
             }
             if (is_null($activityExecution)) {
                 //invalid choice of activity execution:
                 $this->activityExecution = null;
                 //					$invalidActivity = new core_kernel_classes_Resource($activityUri);
                 //					throw new wfEngine_models_classes_ProcessExecutionException("invalid choice of activity definition in process browser {$invalidActivity->getLabel()} ({$invalidActivity->getUri()}). \n<br/> The link may be outdated.");
                 $this->autoredirectToIndex();
                 return;
             }
         } else {
             if (count($currentlyAvailableActivityExecutions) == 1) {
                 $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, reset($currentlyAvailableActivityExecutions), $currentUser);
                 if (is_null($activityExecution)) {
                     throw new wfEngine_models_classes_ProcessExecutionException('cannot initiate the activity execution of the unique next activity definition');
                 }
             } else {
                 //count > 1:
                 //parallel branch, ask the user to select activity to execute:
                 common_Logger::i('Ask the user to select activity');
                 $this->pause();
                 return;
             }
         }
     }
     if (!is_null($activityExecution)) {
         $this->activityExecution = $activityExecution;
         $browserViewData[''] = $this->processExecution->getUri();
         $browserViewData['activityExecutionUri'] = $activityExecution->getUri();
         $this->activityExecutionService->createNonce($this->activityExecution);
         $browserViewData['activityExecutionNonce'] = $this->activityExecutionService->getNonce($activityExecution);
         //get interactive services (call of services):
         $activityDefinition = $this->activityExecutionService->getExecutionOf($activityExecution);
         $interactiveServices = $activityService->getInteractiveServices($activityDefinition);
         $services = array();
         foreach ($interactiveServices as $interactiveService) {
             $serviceCallModel = tao_models_classes_service_ServiceCall::fromResource($interactiveService);
             $vars = $serviceCallModel->getRequiredVariables();
             $parameters = array();
             foreach ($vars as $variable) {
                 $key = (string) $variable->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE));
                 $value = $activityExecution->getOnePropertyValue(new core_kernel_classes_Property($variable));
                 if ($value instanceof core_kernel_classes_Resource) {
                     $parameters[$key] = $value->getUri();
                 } elseif ($value instanceof core_kernel_classes_Literal) {
                     $parameters[$key] = (string) $value;
                 }
             }
             $serviceCallId = $activityExecution->getUri() . (count($interactiveServices) == 1 ? '' : $interactiveService->getUri());
             $jsServiceApi = tao_helpers_ServiceJavascripts::getServiceApi($serviceCallModel, $serviceCallId, $parameters);
             $services[] = array('style' => $interactiveServiceService->getStyle($interactiveService), 'api' => $jsServiceApi);
         }
         $this->setData('services', $services);
         //set activity control:
         $controls = $activityService->getControls($activityDefinition);
         $browserViewData['controls'] = array('backward' => isset($controls[INSTANCE_CONTROL_BACKWARD]) ? (bool) $controls[INSTANCE_CONTROL_BACKWARD] : false, 'forward' => isset($controls[INSTANCE_CONTROL_FORWARD]) ? (bool) $controls[INSTANCE_CONTROL_FORWARD] : false);
         // If paused, resume it:
         if ($this->processExecutionService->isFinished($this->processExecution)) {
             $this->processExecutionService->resume($this->processExecution);
         }
         //get process definition:
         $processDefinition = $this->processExecutionService->getExecutionOf($this->processExecution);
         // Browser view main data.
         $browserViewData['processLabel'] = $processDefinition->getLabel();
         $browserViewData['processExecutionLabel'] = $this->processExecution->getLabel();
         $browserViewData['activityLabel'] = $activityDefinition->getLabel();
         $browserViewData['processUri'] = $this->processExecution->getUri();
         $browserViewData['active_Resource'] = "'" . $activityDefinition->getUri() . "'";
         $browserViewData['isInteractiveService'] = true;
         $this->setData('browserViewData', $browserViewData);
         $this->setData('activity', $activityDefinition);
         /* <DEBUG> :populate the debug widget */
         if (DEBUG_MODE) {
             $this->setData('debugWidget', DEBUG_MODE);
             $servicesResources = array();
             foreach ($services as $service) {
                 $servicesResource = $service;
                 $servicesResource['input'] = $interactiveServiceService->getInputValues($interactiveService, $activityExecution);
                 $servicesResource['output'] = $interactiveServiceService->getOutputValues($interactiveService, $activityExecution);
                 $servicesResources[] = $servicesResource;
             }
             $variableService = wfEngine_models_classes_VariableService::singleton();
             $this->setData('debugData', array('Activity' => $activityDefinition, 'ActivityExecution' => $activityExecution, 'CurrentActivities' => $currentlyAvailableActivityExecutions, 'Services' => $servicesResources, 'VariableStack' => $variableService->getAll()));
         }
         /* </DEBUG> */
         $this->setData('activityExecutionUri', $browserViewData['activityExecutionUri']);
         $this->setData('processUri', $browserViewData['processUri']);
         $this->setData('activityExecutionNonce', $browserViewData['activityExecutionNonce']);
         $this->setData('client_config_url', $this->getClientConfigUrl());
         $this->setView('process_browser.tpl');
     }
 }
 /**
  * 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;
 }
 /**
  * 
  * 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');
 }