/** * 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(); }
public function testGetInteractiveServices() { $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton(); $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS); $processDefinition = $processDefinitionClass->createInstance('ProcessForUnitTest', 'Unit test'); $authoringService = wfAuthoring_models_classes_ProcessService::singleton(); $interactiveService = wfEngine_models_classes_InteractiveServiceService::singleton(); //define activities and connectors $activity1 = $authoringService->createActivity($processDefinition, 'activity1'); $service1 = $authoringService->createInteractiveService($activity1); $this->assertTrue(count($this->service->getInteractiveServices($activity1)) == 1); $this->assertTrue(array_key_exists($service1->getUri(), $this->service->getInteractiveServices($activity1))); $service1->delete(true); $activity1->delete(true); $processDefinition->delete(true); }
public function index() { if (is_null($this->processExecution)) { common_Logger::w('ProcessBrowser invoked without processExecution'); $this->redirectToMain(); return; } if ($this->autoRedirecting) { $this->autoredirectToIndex(); return; } /* * @todo: clean usage * known use of Session::setAttribute("processUri") in: * - taoDelivery_actions_ItemDelivery::runner() * - tao_actions_Api::createAuthEnvironment() */ $this->setSessionAttribute("processUri", $this->processExecution->getUri()); //user data for browser view $userViewData = wfEngine_helpers_UsersHelper::buildCurrentUserForView(); $this->setData('userViewData', $userViewData); $browserViewData = array(); // general data for browser view. //init services: $userService = wfEngine_models_classes_UserService::singleton(); $activityService = wfEngine_models_classes_ActivityService::singleton(); $interactiveServiceService = wfEngine_models_classes_InteractiveServiceService::singleton(); //get current user: $currentUser = $userService->getCurrentUser(); if (is_null($currentUser)) { throw new wfEngine_models_classes_ProcessExecutionException("No current user found!"); } //get activity execution from currently available process definitions: $currentlyAvailableActivityExecutions = $this->processExecutionService->getAvailableCurrentActivityExecutions($this->processExecution, $currentUser, true); $activityExecution = null; if (count($currentlyAvailableActivityExecutions) == 0) { common_Logger::w('No available current activity exec found: no permission or issue in process execution'); $this->pause(); return; } else { if (!is_null($this->activityExecution) && $this->activityExecution instanceof core_kernel_classes_Resource) { foreach ($currentlyAvailableActivityExecutions as $availableActivityExec) { if ($availableActivityExec->getUri() == $this->activityExecution->getUri()) { $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, $this->activityExecution, $currentUser); break; } } if (is_null($activityExecution)) { //invalid choice of activity execution: $this->activityExecution = null; // $invalidActivity = new core_kernel_classes_Resource($activityUri); // throw new wfEngine_models_classes_ProcessExecutionException("invalid choice of activity definition in process browser {$invalidActivity->getLabel()} ({$invalidActivity->getUri()}). \n<br/> The link may be outdated."); $this->autoredirectToIndex(); return; } } else { if (count($currentlyAvailableActivityExecutions) == 1) { $activityExecution = $this->processExecutionService->initCurrentActivityExecution($this->processExecution, reset($currentlyAvailableActivityExecutions), $currentUser); if (is_null($activityExecution)) { throw new wfEngine_models_classes_ProcessExecutionException('cannot initiate the activity execution of the unique next activity definition'); } } else { //count > 1: //parallel branch, ask the user to select activity to execute: common_Logger::i('Ask the user to select activity'); $this->pause(); return; } } } if (!is_null($activityExecution)) { $this->activityExecution = $activityExecution; $browserViewData[''] = $this->processExecution->getUri(); $browserViewData['activityExecutionUri'] = $activityExecution->getUri(); $this->activityExecutionService->createNonce($this->activityExecution); $browserViewData['activityExecutionNonce'] = $this->activityExecutionService->getNonce($activityExecution); //get interactive services (call of services): $activityDefinition = $this->activityExecutionService->getExecutionOf($activityExecution); $interactiveServices = $activityService->getInteractiveServices($activityDefinition); $services = array(); foreach ($interactiveServices as $interactiveService) { $serviceCallModel = tao_models_classes_service_ServiceCall::fromResource($interactiveService); $vars = $serviceCallModel->getRequiredVariables(); $parameters = array(); foreach ($vars as $variable) { $key = (string) $variable->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSVARIABLES_CODE)); $value = $activityExecution->getOnePropertyValue(new core_kernel_classes_Property($variable)); if ($value instanceof core_kernel_classes_Resource) { $parameters[$key] = $value->getUri(); } elseif ($value instanceof core_kernel_classes_Literal) { $parameters[$key] = (string) $value; } } $serviceCallId = $activityExecution->getUri() . (count($interactiveServices) == 1 ? '' : $interactiveService->getUri()); $jsServiceApi = tao_helpers_ServiceJavascripts::getServiceApi($serviceCallModel, $serviceCallId, $parameters); $services[] = array('style' => $interactiveServiceService->getStyle($interactiveService), 'api' => $jsServiceApi); } $this->setData('services', $services); //set activity control: $controls = $activityService->getControls($activityDefinition); $browserViewData['controls'] = array('backward' => isset($controls[INSTANCE_CONTROL_BACKWARD]) ? (bool) $controls[INSTANCE_CONTROL_BACKWARD] : false, 'forward' => isset($controls[INSTANCE_CONTROL_FORWARD]) ? (bool) $controls[INSTANCE_CONTROL_FORWARD] : false); // If paused, resume it: if ($this->processExecutionService->isFinished($this->processExecution)) { $this->processExecutionService->resume($this->processExecution); } //get process definition: $processDefinition = $this->processExecutionService->getExecutionOf($this->processExecution); // Browser view main data. $browserViewData['processLabel'] = $processDefinition->getLabel(); $browserViewData['processExecutionLabel'] = $this->processExecution->getLabel(); $browserViewData['activityLabel'] = $activityDefinition->getLabel(); $browserViewData['processUri'] = $this->processExecution->getUri(); $browserViewData['active_Resource'] = "'" . $activityDefinition->getUri() . "'"; $browserViewData['isInteractiveService'] = true; $this->setData('browserViewData', $browserViewData); $this->setData('activity', $activityDefinition); /* <DEBUG> :populate the debug widget */ if (DEBUG_MODE) { $this->setData('debugWidget', DEBUG_MODE); $servicesResources = array(); foreach ($services as $service) { $servicesResource = $service; $servicesResource['input'] = $interactiveServiceService->getInputValues($interactiveService, $activityExecution); $servicesResource['output'] = $interactiveServiceService->getOutputValues($interactiveService, $activityExecution); $servicesResources[] = $servicesResource; } $variableService = wfEngine_models_classes_VariableService::singleton(); $this->setData('debugData', array('Activity' => $activityDefinition, 'ActivityExecution' => $activityExecution, 'CurrentActivities' => $currentlyAvailableActivityExecutions, 'Services' => $servicesResources, 'VariableStack' => $variableService->getAll())); } /* </DEBUG> */ $this->setData('activityExecutionUri', $browserViewData['activityExecutionUri']); $this->setData('processUri', $browserViewData['processUri']); $this->setData('activityExecutionNonce', $browserViewData['activityExecutionNonce']); $this->setData('client_config_url', $this->getClientConfigUrl()); $this->setView('process_browser.tpl'); } }
/** * Short description of method deleteCallOfService * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource service * @return boolean */ public function deleteCallOfService(core_kernel_classes_Resource $service) { $interactiveServiceService = wfEngine_models_classes_InteractiveServiceService::singleton(); return $interactiveServiceService->deleteInteractiveService($service); }
/** * Walk through the cloned process and replace the item runner placeholders * * @param core_kernel_classes_Resource $processDefinition */ protected function process(core_kernel_classes_Resource $processDefinition) { $report = new common_report_Report(common_report_Report::TYPE_SUCCESS); $activities = wfEngine_models_classes_ProcessDefinitionService::singleton()->getAllActivities($processDefinition); foreach ($activities as $activity) { $services = wfEngine_models_classes_ActivityService::singleton()->getInteractiveServices($activity); foreach ($services as $service) { $serviceDefinition = $service->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION)); if ($serviceDefinition->getUri() == INSTANCE_ITEMCONTAINER_SERVICE) { $item = taoWfTest_models_classes_WfTestService::singleton()->getItemByService($service); if (is_null($item)) { $report->add($this->fail(__('No valid item found for service "%s"', $service->getLabel()))); } else { $itemReport = $this->subCompile($item); if ($itemReport->getType() == common_report_Report::TYPE_SUCCESS) { $serviceCall = $itemReport->getData(); $storedServiceCall = $serviceCall->toOntology(); // remove old service wfEngine_models_classes_InteractiveServiceService::singleton()->deleteInteractiveService($service); $activity->removePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $service); // add new service $activity->setPropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES), $storedServiceCall); } $report->add($itemReport); if ($itemReport->getType() != common_report_Report::TYPE_SUCCESS) { $report->setType($itemReport->getType()); } } } } } return $report; }
/** * Short description of method delete * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource activity * @return boolean */ public function delete(core_kernel_classes_Resource $activity) { $returnValue = (bool) false; $connectorService = wfAuthoring_models_classes_ConnectorService::singleton(); $interactiveServiceService = wfEngine_models_classes_InteractiveServiceService::singleton(); $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS); $connectors = $connectorClass->searchInstances(array(PROPERTY_CONNECTORS_ACTIVITYREFERENCE => $activity->getUri()), array('like' => false, 'recursive' => 0)); foreach ($connectors as $connector) { $connectorService->delete($connector); } //deleting resource "acitivty" with its references should be enough normally to remove all references... to be tested //delete call of service!! foreach ($this->getInteractiveServices($activity) as $service) { $interactiveServiceService->deleteInteractiveService($service); } //delete referenced actiivty cardinality resources: $activityCardinalityClass = new core_kernel_classes_Class(CLASS_ACTIVITYCARDINALITY); $cardinalities = $activityCardinalityClass->searchInstances(array(PROPERTY_STEP_NEXT => $activity->getUri()), array('like' => false)); foreach ($cardinalities as $cardinality) { $cardinality->delete(true); } //delete activity itself: $returnValue = $activity->delete(true); return (bool) $returnValue; }