private function replaceItemRunner(core_kernel_classes_Resource $workflow, $directory)
 {
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     // foreach activity in workflow
     foreach (wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($workflow) as $activity) {
         foreach (wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($activity) as $service) {
             $serviceDefinition = $service->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION));
             if ($serviceDefinition->getUri() == self::OLD_ITEMRUNNER_SERVICE) {
                 $this->out('to replace: ' . $service->getLabel());
                 // retrieve item
                 $item = $this->getItem($service);
                 // create service
                 $itemDirectory = $this->createNamedSubDirectory($directory, $activity);
                 $newService = $this->compileItem($item, $itemDirectory);
                 $newService->setLabel($service->getLabel());
                 $activity->removePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $service);
                 //delete its related properties
                 $deleted = $authoringService->deleteActualParameters($service);
                 //delete call of service itself
                 $deleted = $service->delete(true);
                 $activity->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $newService);
             }
         }
         $this->out('done activity: ' . $activity->getLabel());
     }
 }
 /**
  * constructor: initialize the service and the default data
  * @return Groups
  */
 public function __construct()
 {
     parent::__construct();
     //the service is initialized by default
     $this->service = wfAuthoring_models_classes_wfAuthoringService::singleton();
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->defaultData();
 }
 /**
  * Builds a simple Diagram of the Process
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return string
  */
 public static function buildDiagramData(core_kernel_classes_Resource $process)
 {
     $returnValue = (string) '';
     common_Logger::i("Building diagram for " . $process->getLabel());
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activityService = wfEngine_models_classes_ActivityService::singleton();
     $connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $activityCardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
     $activities = $authoringService->getActivitiesByProcess($process);
     $todo = array();
     foreach ($activities as $activity) {
         if ($activityService->isInitial($activity)) {
             $todo[] = $activity;
         }
     }
     $currentLevel = 0;
     $diagram = new wfAuthoring_models_classes_ProcessDiagram();
     $done = array();
     while (!empty($todo)) {
         $nextLevel = array();
         $posOnLevel = 0;
         foreach ($todo as $item) {
             $next = array();
             if ($activityService->isActivity($item)) {
                 // add this activity
                 $diagram->addActivity($item, 54 + 200 * $posOnLevel + 10 * $currentLevel, 35 + 80 * $currentLevel);
                 $next = array_merge($next, $activityService->getNextConnectors($item));
                 common_Logger::d('Activity added ' . $item->getUri());
             } elseif ($connectorService->isConnector($item)) {
                 // add this connector
                 $diagram->addConnector($item, 100 + 200 * $posOnLevel + 10 * $currentLevel, 40 + 80 * $currentLevel);
                 $next = array_merge($next, $connectorService->getNextActivities($item));
             } else {
                 common_Logger::w('unexpected ressource in process ' . $item->getUri());
             }
             //replace cardinalities
             foreach ($next as $key => $destination) {
                 if ($activityCardinalityService->isCardinality($destination)) {
                     // not represented on diagram
                     $next[$key] = $activityCardinalityService->getDestination($destination);
                 }
             }
             //add arrows
             foreach ($next as $destination) {
                 $diagram->addArrow($item, $destination);
             }
             $posOnLevel++;
             $nextLevel = array_merge($nextLevel, $next);
         }
         $done = array_merge($done, $todo);
         $todo = array_diff($nextLevel, $done);
         $currentLevel++;
     }
     $returnValue = $diagram->toJSON();
     return (string) $returnValue;
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('process of Checker UnitTest', 'created for the unit test of process cloner');
     if ($processDefinition instanceof core_kernel_classes_Resource) {
         $this->proc = $processDefinition;
     }
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('processForUnitTest', 'created for the unit test of process definition service');
     if ($processDefinition instanceof core_kernel_classes_Resource) {
         $this->processDefinition = $processDefinition;
     } else {
         $this->fail('fail to create a process definition resource');
     }
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->service = wfEngine_models_classes_ProcessDefinitionService::singleton();
 }
 protected function flattenProcessActivity(core_kernel_classes_Resource $activity)
 {
     $this->initCloningVariables();
     $services = wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($activity);
     // only replace single-service activities, with the service process runner
     if (count($services) == 1) {
         $serviceCall = current($services);
         $serviceDefinition = $serviceCall->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION));
         if ($serviceDefinition->getUri() == INSTANCE_SERVICE_PROCESSRUNNER) {
             // found a wfEngine call, extract processDefnition
             $subProcess = $this->getSubProcess($serviceCall);
             if (empty($subProcess)) {
                 throw new common_exception_InconsistentData('Missing process uri in service call ' . $serviceCall->getUri());
             }
             // @todo test the process first
             // @todo clone sub process
             common_Logger::w('Should have cloned subprocess ' . $subProcess);
             $segment = $this->cloneProcessSegment($subProcess);
             $inActivity = $segment['in'];
             $firstout = current($segment['out']);
             //allow first acitvity only if the parent is
             if (!wfAuthoring_models_classes_ActivityService::singleton()->isInitial($activity)) {
                 $inActivity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_FALSE);
             }
             $this->addClonedActivity($inActivity, $activity, $firstout);
             $propProcessActivities = new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES);
             foreach ($this->getClonedActivities() as $activityClone) {
                 $this->processDefinition->setPropertyValue($propProcessActivities, $activityClone->getUri());
             }
             //get the previous connector if exists and clone it
             $allConnectors = wfAuthoring_models_classes_ProcessService::singleton()->getConnectorsByActivity($activity);
             $connectors = array_merge($allConnectors['next'], $allConnectors['prev']);
             foreach ($connectors as $connector) {
                 //trick to reference previous and following connector: connector_prev -> activity_subprocess[activity1, activity2, etc.] -> connector_follow
                 $this->addClonedConnector($connector, $connector);
             }
             //glue segment:
             $glue = array_merge(array($activity), $allConnectors['prev']);
             foreach ($glue as $fragment) {
                 $this->linkClonedStep($fragment);
             }
             //delete all activity:
             $activity->delete(true);
             //recursive call:
             foreach ($this->getClonedActivities() as $activityClone) {
                 $this->flattenProcessActivity($activityClone);
             }
         }
     }
 }
 /**
  * tests initialization
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $this->processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
     //define activities and connectors
     $activity = $this->authoringService->createActivity($this->processDefinition, 'activity for interactive service unit test');
     if ($activity instanceof core_kernel_classes_Resource) {
         $this->activity = $activity;
     } else {
         $this->fail('fail to create a process definition resource');
     }
     $this->service = wfEngine_models_classes_InteractiveServiceService::singleton();
 }
 /**
  * returns an array with the defined default values for the
  * service definition's parameters
  * 
  * @param core_kernel_classes_Resource $serviceDefinition
  */
 public function setDefaultParameters(core_kernel_classes_Resource $serviceCall)
 {
     $serviceDefinition = $this->getServiceDefinition($serviceCall);
     $processService = wfAuthoring_models_classes_ProcessService::singleton();
     $processService->deleteActualParameters($serviceCall);
     $defaultConstProp = new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTCONSTANTVALUE);
     $params = $serviceDefinition->getPropertyValues(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN));
     foreach ($params as $paramUri) {
         $param = new core_kernel_classes_Resource($paramUri);
         $default = $param->getOnePropertyValue($defaultConstProp);
         if (!is_null($default)) {
             $processService->setActualParameter($serviceCall, $param, $default, PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_CONSTANTVALUE);
         }
     }
     $defaultVariableProp = new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_DEFAULTPROCESSVARIABLE);
     $params = $serviceDefinition->getPropertyValues(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN));
     foreach ($params as $paramUri) {
         $param = new core_kernel_classes_Resource($paramUri);
         $default = $param->getOnePropertyValue($defaultVariableProp);
         if (!is_null($default)) {
             $processService->setActualParameter($serviceCall, $param, $default, PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE);
         }
     }
 }
 public function testSplitJoinVariable()
 {
     $process = wfAuthoring_models_classes_ProcessService::singleton()->createProcess('test process for ' . __FUNCTION__);
     $activityAuthoring = wfAuthoring_models_classes_ActivityService::singleton();
     $webservice = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAODelivery.rdf#ServiceWebService');
     $activity = array();
     for ($i = 1; $i <= 3; $i++) {
         $activity[$i] = $activityAuthoring->createFromServiceDefinition($process, $webservice, array());
     }
     wfAuthoring_models_classes_ProcessService::singleton()->setFirstActivity($process, $activity[1]);
     $c1 = $this->service->createSplit($activity[1], array($activity[2]));
     $c2 = $this->service->createJoin(array($activity[2]), $activity[3]);
     $this->service->setSplitCardinality($c1, array($activity[2]->getUri() => '3'));
     $this->service->setJoinCardinality($c2, array($activity[2]->getUri() => '3'));
     $this->runProcess($process, 5);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($process);
 }
 public function testVirtualProcess()
 {
     $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS);
     $processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test');
     $this->assertIsA($processDefinition, 'core_kernel_classes_Resource');
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     //define activities and connectors
     $activity1 = $authoringService->createActivity($processDefinition, 'activity1');
     $this->assertNotNull($activity1);
     $authoringService->setFirstActivity($processDefinition, $activity1);
     //check first activity
     $this->assertTrue($this->service->isActivity($activity1));
     $this->assertTrue($this->service->isInitial($activity1));
     $connector1 = $authoringService->createConnector($activity1);
     $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE));
     $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2');
     $this->assertNotNull($activity2);
     $this->assertTrue($this->service->isActivity($activity2));
     $this->assertFalse($this->service->isFinal($activity1));
     $this->assertFalse($this->service->isInitial($activity2));
     $this->assertTrue($this->service->isFinal($activity2));
     $activity1->delete(true);
     $connector1->delete(true);
     $activity2->delete(true);
     $processDefinition->delete(true);
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return mixed
  */
 public function __construct(core_kernel_classes_Resource $process)
 {
     $this->process = $process;
     $this->activityService = wfEngine_models_classes_ActivityService::singleton();
     $this->connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     parent::__construct();
 }
 /**
  * Short description of method delete
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @return boolean
  */
 public function delete(core_kernel_classes_Resource $connector)
 {
     $returnValue = (bool) false;
     $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
     if (!$this->isConnector($connector)) {
         // throw new Exception("the resource in the parameter is not a connector: {$connector->getLabel()} ({$connector->getUri()})");
         return $returnValue;
     }
     //get the type of connector:
     $connectorType = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE));
     if (!is_null($connectorType) && $connectorType instanceof core_kernel_classes_Resource) {
         if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_CONDITIONAL) {
             //delete the related rule:
             $relatedRule = $this->getTransitionRule($connector);
             if (!is_null($relatedRule)) {
                 $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
                 $processAuthoringService->deleteRule($relatedRule);
             }
         }
     }
     //delete cardinality resources if exists in previous activities:
     foreach ($this->getPreviousActivities($connector) as $prevActivity) {
         if ($cardinalityService->isCardinality($prevActivity)) {
             $prevActivity->delete();
             //delete the cardinality resource
         }
     }
     //manage the connection to the following activities
     $activityRef = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE))->getUri();
     foreach ($this->getNextActivities($connector) as $nextActivity) {
         $activity = null;
         if ($cardinalityService->isCardinality($nextActivity)) {
             try {
                 $activity = $cardinalityService->getDestination($nextActivity);
             } catch (Exception $e) {
                 //the actiivty could be null if the reference have been removed...
             }
             $nextActivity->delete();
             //delete the cardinality resource
         } else {
             $activity = $nextActivity;
         }
         if (!is_null($activity) && $this->isConnector($activity)) {
             $nextActivityRef = $activity->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE))->getUri();
             if ($nextActivityRef == $activityRef) {
                 $this->delete($activity);
                 //delete following connectors only if they have the same activity reference
             }
         }
     }
     //delete connector itself:
     $returnValue = $connector->delete(true);
     return (bool) $returnValue;
 }
 /**
  * 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);
     }
 }
 public function testFlatten()
 {
     // single
     $process1 = $this->createLinearProcess();
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($process1);
     $this->assertEquals(count($arr), 1);
     $startP1 = current($arr);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getFinalSteps($process1);
     $this->assertEquals(count($arr), 1);
     $endP1 = current($arr);
     $super1 = $this->createLinearSuperProcess(array($process1));
     $flattener = new wfAuthoring_models_classes_ProcessFlattener($super1);
     $flattener->flatten();
     $activities = $super1->getPropertyValues(new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES));
     $this->assertEquals(count($activities), 3);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($super1);
     $this->assertEquals(count($arr), 1);
     $start = current($arr);
     $final = $this->assertProcessPartCorresponds($start, $startP1);
     $arr = wfEngine_models_classes_StepService::singleton()->getNextSteps($final);
     $this->assertTrue(empty($arr));
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($super1);
     //recursiv
     $super1 = $this->createLinearSuperProcess(array($process1));
     $super2 = $this->createLinearSuperProcess(array($super1));
     $flattener = new wfAuthoring_models_classes_ProcessFlattener($super2);
     $flattener->flatten();
     $activities = $super2->getPropertyValues(new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES));
     $this->assertEquals(count($activities), 3);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($super2);
     $this->assertEquals(count($arr), 1);
     $start = current($arr);
     $final = $this->assertProcessPartCorresponds($start, $startP1);
     $arr = wfEngine_models_classes_StepService::singleton()->getNextSteps($final);
     $this->assertTrue(empty($arr));
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($super1);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($super2);
     // multiple
     $process2 = $this->createLinearProcess();
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($process2);
     $this->assertEquals(count($arr), 1);
     $startP2 = current($arr);
     $process3 = $this->createLinearProcess();
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($process3);
     $this->assertEquals(count($arr), 1);
     $startP3 = current($arr);
     $super3 = $this->createLinearSuperProcess(array($process1, $process2, $process3));
     $flattener = new wfAuthoring_models_classes_ProcessFlattener($super3);
     $flattener->flatten();
     $activities = $super3->getPropertyValues(new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES));
     $this->assertEquals(count($activities), 9);
     $arr = wfAuthoring_models_classes_ProcessService::singleton()->getInitialSteps($super3);
     $this->assertEquals(count($arr), 1);
     $start = current($arr);
     $last = $this->assertProcessPartCorresponds($start, $startP1);
     $start = $this->advanceTwo($last);
     $last = $this->assertProcessPartCorresponds($start, $startP2);
     $start = $this->advanceTwo($last);
     $final = $this->assertProcessPartCorresponds($start, $startP3);
     $arr = wfEngine_models_classes_StepService::singleton()->getNextSteps($final);
     $this->assertTrue(empty($arr));
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($super3);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($process1);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($process2);
     wfAuthoring_models_classes_ProcessService::singleton()->deleteProcess($process3);
 }
 public static function deleteProcesses()
 {
     $returnValue = false;
     $classProcess = new core_kernel_classes_Class(CLASS_PROCESS);
     $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
     self::$processes = array_merge(self::$processes, $classProcess->searchInstances(array(PROPERTY_IS_SAMPLE => GENERIS_TRUE), array('like' => false, 'recursive' => false)));
     foreach (self::$processes as $processUri => $process) {
         if ($process instanceof core_kernel_classes_Resource && $process->exists()) {
             $returnValue = $processAuthoringService->deleteProcess($process);
         }
         unset(self::$processes[$processUri]);
     }
     return $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);
     }
 }
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string cloneLabel
  */
 public function __construct($cloneLabel = '')
 {
     $this->cloneLabel = $cloneLabel;
     $this->authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $this->activityService = wfEngine_models_classes_ActivityService::singleton();
     $this->connectorService = wfEngine_models_classes_ConnectorService::singleton();
     $this->initCloningVariables();
 }
 public static function nextActivityElements(core_kernel_classes_Resource $connector, $type, $allowCreation = true, $includeConnectors = true, $optionsWidget = 'Combobox')
 {
     $returnValue = array();
     $authorizedOptionsWidget = array('Combobox', 'Checkbox');
     if (!in_array($optionsWidget, $authorizedOptionsWidget)) {
         throw new Exception('Wrong type of widget');
         return $returnValue;
     }
     $idPrefix = '';
     $nextActivity = null;
     $propTransitionRule = new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE);
     $propNextActivities = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     //find the next activity if available
     switch (strtolower($type)) {
         case 'next':
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $activity) {
                 if ($activity instanceof core_kernel_classes_Resource) {
                     $nextActivity = $activity;
                     //we take the last one...(note: there should be only one though)
                 }
             }
             $idPrefix = 'next';
             break;
         case 'then':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN))->getIterator() as $then) {
                         if ($then instanceof core_kernel_classes_Resource) {
                             $nextActivity = $then;
                         }
                     }
                 }
             }
             $idPrefix = 'then';
             break;
         case 'else':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE))->getIterator() as $else) {
                         if ($else instanceof core_kernel_classes_Resource) {
                             $nextActivity = $else;
                         }
                     }
                 }
             }
             $idPrefix = 'else';
             break;
         case 'parallel':
             $nextActivity = array();
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $cardinality) {
                 if ($cardinality instanceof core_kernel_classes_Resource) {
                     $nextActivity[] = $cardinality;
                 }
             }
             $idPrefix = 'parallel';
             break;
         case 'join':
             // should only have one following activity
             $nextActivity = $connector->getOnePropertyValue($propNextActivities);
             $idPrefix = $type;
             break;
         default:
             throw new Exception("unknown type for the next activity");
     }
     $activityOptions = array();
     $connectorOptions = array();
     if ($allowCreation) {
         //create the activity label element (used only in case of new activity craetion)
         $elementActivityLabel = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityLabel", 'Textbox');
         $elementActivityLabel->setDescription(__('Label'));
         //add the "creating" option
         $activityOptions["newActivity"] = __("create new activity");
         $connectorOptions["newConnector"] = __("create new connector");
     }
     //the activity associated to the connector:
     $referencedActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE));
     //mandatory property value, initiated at the connector creation
     if ($referencedActivity instanceof core_kernel_classes_Resource) {
         $processDefClass = new core_kernel_classes_Class(CLASS_PROCESS);
         $processes = $processDefClass->searchInstances(array(PROPERTY_PROCESS_ACTIVITIES => $referencedActivity->getUri()), array('like' => false));
         if (count($processes) > 0) {
             $process = array_shift($processes);
             if (!empty($process)) {
                 //get list of activities and connectors for the current process:
                 $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
                 $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
                 $activities = $processAuthoringService->getActivitiesByProcess($process);
                 foreach ($activities as $activityTemp) {
                     //include activities options:
                     $encodedUri = tao_helpers_Uri::encode($activityTemp->getUri());
                     $activityOptions[$encodedUri] = $activityTemp->getLabel();
                     if (strtolower($type) == 'parallel') {
                         $elementHidden = tao_helpers_form_FormFactory::getElement("{$encodedUri}_num_hidden", 'Hidden');
                         $returnValue[$idPrefix . '_' . $activityTemp->getUri()] = $elementHidden;
                     }
                     //include connectors options:
                     if ($includeConnectors) {
                         $connectors = $connectorClass->searchInstances(array(PROPERTY_CONNECTORS_ACTIVITYREFERENCE => $activityTemp->getUri()), array('like' => false));
                         foreach ($connectors as $connectorTemp) {
                             if ($connector->getUri() != $connectorTemp->getUri()) {
                                 $connectorOptions[tao_helpers_Uri::encode($connectorTemp->getUri())] = $connectorTemp->getLabel();
                             }
                         }
                     }
                 }
             }
         }
     }
     //create the description element
     $elementDescription = tao_helpers_form_FormFactory::getElement($idPrefix, 'Free');
     $elementDescription->setValue(strtoupper($type) . ' :');
     //create the activity select element:
     $elementActivities = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityUri", $optionsWidget);
     $elementActivities->setDescription(__('Activity'));
     $elementActivities->setOptions($activityOptions);
     $elementChoice = null;
     $elementConnectors = null;
     if ($includeConnectors) {
         //the default radio button to select between the 3 possibilities:
         $elementChoice = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityOrConnector", 'Radiobox');
         $elementChoice->setDescription(__('Activity or Connector'));
         $options = array("activity" => __("Activity"), "connector" => __("Connector"));
         $elementChoice->setOptions($options);
         //create the connector select element:
         $elementConnectors = tao_helpers_form_FormFactory::getElement($idPrefix . "_connectorUri", $optionsWidget);
         $elementConnectors->setDescription(__('Connector'));
         $elementConnectors->setOptions($connectorOptions);
     }
     if (!empty($nextActivity)) {
         if (is_array($nextActivity) && $optionsWidget == 'Checkbox') {
             if (strtolower($type) == 'parallel') {
                 $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
                 foreach ($nextActivity as $cardinality) {
                     $activity = $cardinalityService->getDestination($cardinality);
                     $number = $cardinalityService->getCardinality($cardinality);
                     if (isset($returnValue[$idPrefix . '_' . $activity->getUri()])) {
                         $returnValue[$idPrefix . '_' . $activity->getUri()]->setValue($number instanceof core_kernel_classes_Resource ? tao_helpers_Uri::encode($number->getUri()) : intval($number));
                     }
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             } else {
                 foreach ($nextActivity as $activity) {
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             }
         } elseif ($nextActivity instanceof core_kernel_classes_Resource) {
             $aService = wfEngine_models_classes_ActivityService::singleton();
             if ($aService->isActivity($nextActivity)) {
                 if ($includeConnectors) {
                     $elementChoice->setValue("activity");
                 }
                 $elementActivities->setValue($nextActivity->getUri());
                 //no need for tao_helpers_Uri::encode
             }
             $conmectorService = wfEngine_models_classes_ConnectorService::singleton();
             if ($conmectorService->isConnector($nextActivity) && $includeConnectors) {
                 $elementChoice->setValue("connector");
                 $elementConnectors->setValue($nextActivity->getUri());
             }
         }
     }
     //put all elements in the return value:
     $returnValue[$idPrefix . '_description'] = $elementDescription;
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_choice'] = $elementChoice;
     }
     $returnValue[$idPrefix . '_activities'] = $elementActivities;
     if ($allowCreation) {
         $returnValue[$idPrefix . '_label'] = $elementActivityLabel;
     }
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_connectors'] = $elementConnectors;
     }
     return $returnValue;
 }
 /**
  * Short description of method setTestItems
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param
  *            Resource test
  * @param
  *            array items
  * @return boolean
  */
 public function setTestItems(core_kernel_classes_Resource $test, $items)
 {
     $returnValue = (bool) false;
     $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
     // get the current process:
     $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP));
     // get formal param associated to the 3 required service input parameters:
     $itemUriParam = new core_kernel_classes_Resource(INSTANCE_FORMALPARAM_ITEMURI);
     // delete all related activities:
     $activities = $authoringService->getAllActivities($process);
     foreach ($activities as $activity) {
         if (!$authoringService->deleteActivity($activity)) {
             throw new common_exception_Error('Unable to delete Activity ' . $activity->getUri());
         }
     }
     // create the list of activities and interactive services and items plus their appropriate property values:
     $previousActivity = null;
     $connectorService = wfAuthoring_models_classes_ConnectorService::singleton();
     foreach ($items as $item) {
         if (!$item instanceof core_kernel_classes_Resource) {
             throw new common_Exception("An item provided to " . __FUNCTION__ . " is not a resource but " . gettype($item));
         }
         // create an activity
         $activity = null;
         $activity = $authoringService->createActivity($process, "item: {$item->getLabel()}");
         // set property value visible to true
         $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISHIDDEN), GENERIS_FALSE);
         // set ACL mode to role user restricted with role=subject
         $extManager = common_ext_ExtensionsManager::singleton();
         $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ACL_MODE), INSTANCE_ACL_ROLE_RESTRICTED_USER_DELIVERY);
         $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_RESTRICTED_ROLE), INSTANCE_ROLE_DELIVERY);
         // get the item runner service definition: must exists!
         $itemRunnerServiceDefinition = new core_kernel_classes_Resource(INSTANCE_ITEMCONTAINER_SERVICE);
         if (!$itemRunnerServiceDefinition->exists()) {
             throw new common_exception_InconsistentData('required service definition item runner does not exists');
         }
         // create a call of service and associate the service definition to it:
         $interactiveService = $authoringService->createInteractiveService($activity);
         $interactiveService->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), $itemRunnerServiceDefinition->getUri());
         $authoringService->setActualParameter($interactiveService, $itemUriParam, $item->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN);
         // constant: we know it!
         if (!is_null($previousActivity)) {
             $connectorService->createSequential($previousActivity, $activity);
         } else {
             // set the property value as initial
             $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_TRUE);
         }
         $previousActivity = $activity;
     }
     $returnValue = true;
     return (bool) $returnValue;
 }
 public function testDeleteCreatedResources()
 {
     if (isset($this->config['delete']) && $this->config['delete'] === false) {
         $this->out('Skip resources deletion');
         return;
     }
     if (!empty($this->properties)) {
         foreach ($this->properties as $prop) {
             $this->assertTrue($prop->delete());
         }
     }
     if (!is_null($this->itemClass)) {
         $this->itemClass->delete();
     }
     if (!empty($this->units)) {
         foreach ($this->units as $unit) {
             $this->assertTrue($unit->delete());
         }
     }
     if (!empty($this->files)) {
         foreach ($this->files as $file) {
             $this->assertTrue($file->delete());
         }
     }
     if (!empty($this->users)) {
         foreach ($this->users as $user) {
             $this->assertTrue($user->delete());
         }
     }
     if (!empty($this->roles)) {
         foreach ($this->roles as $role) {
             $this->assertTrue($role->delete());
         }
     }
     $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton();
     foreach ($this->processExecutions as $processInstance) {
         if ($processInstance instanceof core_kernel_classes_Resource) {
             $this->assertTrue($processInstance->exists());
             $this->assertTrue($processExecutionService->deleteProcessExecution($processInstance));
             $this->assertFalse($processInstance->exists());
         }
     }
     foreach ($this->processDefinition as $process) {
         if ($process instanceof core_kernel_classes_Resource) {
             $authoringService = wfAuthoring_models_classes_ProcessService::singleton();
             $this->assertTrue($authoringService->deleteProcess($process));
             $this->assertFalse($process->exists());
         }
     }
     if (!empty($this->vars)) {
         foreach ($this->vars as $code => $variable) {
             $deleted = $variable->delete();
             $this->assertTrue($deleted);
             if (!$deleted) {
                 var_dump($code);
             }
         }
     }
 }
 /**
  * Short description of method activityTree
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @return array
  */
 public function activityTree(core_kernel_classes_Resource $process)
 {
     $returnValue = array();
     $this->currentActivity = null;
     if (empty($process) && !empty($this->currentProcess)) {
         $process = $this->currentProcess;
     }
     if (empty($process)) {
         throw new Exception("no process instance to populate the activity tree");
         return $data;
     }
     //initiate the return data value:
     $data = array('data' => __("Process Tree:") . ' ' . $process->getLabel(), 'attributes' => array('id' => 'node-process-root', 'class' => 'node-process-root', 'rel' => tao_helpers_Uri::encode($process->getUri())), 'children' => array());
     //instanciate the processAuthoring service
     $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
     $activities = array();
     $activities = $processAuthoringService->getActivitiesByProcess($process);
     // throw new Exception(var_dump($activities));
     foreach ($activities as $activity) {
         $this->currentActivity = $activity;
         $this->addedConnectors = array();
         //required to prevent cyclic connexion between connectors of a given activity
         $initial = false;
         $last = false;
         $activityData = array();
         $activityData = $this->activityNode($activity, 'next', false);
         //default value will do
         //get connectors
         $connectors = $processAuthoringService->getConnectorsByActivity($activity);
         //following nodes:
         if (!empty($connectors['next'])) {
             //connector following the current activity: there should be only one
             foreach ($connectors['next'] as $connector) {
                 $this->currentConnector = $connector;
                 $activityData['children'][] = $this->connectorNode($connector, '', true);
             }
         } else {
             // throw new Exception("no connector associated to the activity: {$activity->getUri()}");
             //Simply not add a connector here: this should be considered as the last activity:
             $last = true;
         }
         //check if it is the first activity node:
         $isIntial = $activity->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL));
         if (!is_null($isIntial) && $isIntial instanceof core_kernel_classes_Resource) {
             if ($isIntial->getUri() == GENERIS_TRUE) {
                 $initial = true;
             }
         }
         if ($initial) {
             $activityData = $this->addNodeClass($activityData, "node-activity-initial");
             if ($last) {
                 $activityData = $this->addNodeClass($activityData, 'node-activity-last');
                 $activityData = $this->addNodeClass($activityData, "node-activity-unique");
             }
         } elseif ($last) {
             $activityData = $this->addNodeClass($activityData, 'node-activity-last');
         }
         //get interactive services
         $services = null;
         $services = $activity->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES));
         foreach ($services->getIterator() as $service) {
             if ($service instanceof core_kernel_classes_Resource) {
                 $activityData['children'][] = array('data' => $service->getLabel(), 'attributes' => array('id' => tao_helpers_Uri::encode($service->getUri()), 'class' => 'node-interactive-service'));
             }
         }
         //add children here
         if ($initial) {
             array_unshift($data["children"], $activityData);
         } else {
             $data["children"][] = $activityData;
         }
     }
     $returnValue = $data;
     return (array) $returnValue;
 }
 /**
  * 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);
     }
 }