/** * Test user insertion with special chars */ public function testAddUtf8User() { $this->assertTrue($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN])); $tmclass = new core_kernel_classes_Class(CLASS_TAO_USER); $this->testUserUtf8 = $tmclass->createInstance(); $this->assertNotNull($this->testUserUtf8); $this->assertTrue($this->testUserUtf8->exists()); $result = $this->userService->bindProperties($this->testUserUtf8, $this->testUserUtf8Data); $this->assertNotNull($result); $this->assertNotEquals($result, false); $this->assertFalse($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN])); //check inserted data $this->testUserUtf8 = $this->getUserByLogin($this->testUserUtf8Data[PROPERTY_USER_LOGIN]); $this->assertInstanceOf('core_kernel_classes_Resource', $this->testUserUtf8); foreach ($this->testUserUtf8Data as $prop => $value) { try { $p = new core_kernel_classes_Property($prop); $v = $this->testUserUtf8->getUniquePropertyValue($p); $v = $v instanceof core_kernel_classes_Literal ? $v->literal : $v->getUri(); $this->assertEquals($value, $v); } catch (common_Exception $ce) { $this->fail($ce); } } }
/** * Short description of method getCode * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource language * @return string */ public function getCode(core_kernel_classes_Resource $language) { $returnValue = (string) ''; $valueProperty = new core_kernel_classes_Property(RDF_VALUE); $returnValue = $language->getUniquePropertyValue($valueProperty); return (string) $returnValue; }
/** * * @param array callOptions an array of parameters sent to the results storage configuration * @param mixed $resultServer * @param string uri or resource */ public function __construct($resultServer, $additionalStorages = array()) { $this->implementations = array(); if (is_object($resultServer) and get_class($resultServer) == 'core_kernel_classes_Resource') { $this->resultServer = $resultServer; } else { if (common_Utils::isUri($resultServer)) { $this->resultServer = new core_kernel_classes_Resource($resultServer); } } // the static storages if ($this->resultServer->getUri() != TAO_VOID_RESULT_SERVER) { $resultServerModels = $this->resultServer->getPropertyValues(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_PROP)); if (!isset($resultServerModels) or count($resultServerModels) == 0) { throw new common_Exception("The result server is not correctly configured (Resource definition)"); } foreach ($resultServerModels as $resultServerModelUri) { $resultServerModel = new core_kernel_classes_Resource($resultServerModelUri); $this->addImplementation($resultServerModel->getUniquePropertyValue(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_IMPL_PROP))->literal); } } if (!is_null($additionalStorages)) { // the dynamic storages foreach ($additionalStorages as $additionalStorage) { $this->addImplementation($additionalStorage["implementation"], $additionalStorage["parameters"]); } } common_Logger::i("Result Server Initialized using defintion:" . $this->resultServer->getUri()); // sets the details required depending on the type of storage }
/** * Short description of method getExpression * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource rule * @return mixed */ public function getExpression(core_kernel_classes_Resource $rule) { $returnValue = null; $property = new core_kernel_classes_Property(PROPERTY_RULE_IF); $returnValue = new core_kernel_rules_Expression($rule->getUniquePropertyValue($property)->getUri(), __METHOD__); return $returnValue; }
/** * @deprecated * @see taoTests_models_classes_TestModel::getAuthoring() */ public function getAuthoring(core_kernel_classes_Resource $test) { $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfAdvTest'); $widget = new Renderer($ext->getConstant('DIR_VIEWS') . 'templates' . DIRECTORY_SEPARATOR . 'authoring.tpl'); $widget->setData('processUri', $process->getUri()); $widget->setData('label', __('Authoring %s', $test->getLabel())); return $widget->render(); }
public function getTokenizer() { $tokenizerUri = $this->getUniquePropertyValue(new \core_kernel_classes_Property("http://www.tao.lu/Ontologies/TAO.rdf#IndexTokenizer")); $tokenizer = new \core_kernel_classes_Resource($tokenizerUri); $implClass = (string) $tokenizer->getUniquePropertyValue(new \core_kernel_classes_Property("http://www.tao.lu/Ontologies/TAO.rdf#TokenizerClass")); if (!class_exists($implClass)) { throw new \common_exception_Error('Tokenizer class "' . $implClass . '" not found for ' . $tokenizer->getUri()); } return new $implClass(); }
protected static function getParamName(core_kernel_classes_Resource $paramDefinition) { try { $paramKey = common_cache_FileCache::singleton()->get(self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri())); } catch (common_cache_NotFoundException $e) { $paramKey = common_Utils::fullTrim($paramDefinition->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_NAME))); common_cache_FileCache::singleton()->put($paramKey, self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri())); } return $paramKey; }
/** * Short description of method getThenActivity * * @access public * @author Lionel Lecaque, <*****@*****.**> * @param Resource rule * @return core_kernel_classes_Resource */ public function getThenActivity(core_kernel_classes_Resource $rule) { $returnValue = null; $thenProperty = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN); try { $returnValue = $rule->getUniquePropertyValue($thenProperty); } catch (common_Exception $e) { throw new wfEngine_models_classes_ProcessExecutionException('Transition Rule ' . $rule->getUri() . ' do not have value for Then Property'); } return $returnValue; }
/** * return a LTI link URI from a valid delivery id * @author Christophe GARCIA <*****@*****.**> */ public function getUrl() { try { if ($this->getRequestMethod() != \Request::HTTP_GET) { throw new \common_exception_NotImplemented('Only GET method is accepted to request this service.'); } if (!$this->hasRequestParameter('deliveryId')) { $this->returnFailure(new \common_exception_MissingParameter('At least one mandatory parameter was required but found missing in your request')); } $selectedDelivery = new \core_kernel_classes_Resource($this->getRequestParameter('deliveryId')); if (!$selectedDelivery->isInstanceOf(new \core_kernel_classes_Class(TAO_DELIVERY_CLASS))) { $this->returnFailure(new \common_exception_NotFound('Delivery not found')); } try { $selectedDelivery->getUniquePropertyValue(new \core_kernel_classes_Property(\TAO_DELIVERY_RESULTSERVER_PROP)); } catch (Exception $e) { $this->returnFailure(new \common_exception_BadRequest('The delivery is not associated to a Result server storage policy')); } $this->returnSuccess(LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $selectedDelivery->getUri()))); } catch (Exception $ex) { $this->returnFailure($ex); } }
/** * Edit a media instance with a new file and/or a new language * @param $fileTmp * @param $instanceUri * @param $language * @return bool $instanceUri or false on error */ public function editMediaInstance($fileTmp, $instanceUri, $language) { $instance = new \core_kernel_classes_Resource($instanceUri); $link = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK)); $link = $link instanceof \core_kernel_classes_Resource ? $link->getUri() : (string) $link; $fileManager = FileManager::getFileManagementModel(); $fileManager->deleteFile($link); $link = $fileManager->storeFile($fileTmp, $instance->getLabel()); if ($link !== false) { //get the file MD5 $md5 = md5_file($fileTmp); /** @var $instance \core_kernel_classes_Resource */ if (!is_null($instance) && $instance instanceof \core_kernel_classes_Resource) { $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LINK), $link); $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LANGUAGE), $language); $instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MD5), $md5); } if (common_ext_ExtensionsManager::singleton()->isEnabled('taoRevision')) { \common_Logger::i('Auto generating revision'); RevisionService::commit($instance, __('Imported new file')); } } return $link !== false ? true : false; }
/** * returns the test taker related to the delivery * * @author Patrick Plichart, <*****@*****.**> */ public function getTestTaker(core_kernel_classes_Resource $deliveryResult) { $propResultOfSubject = new core_kernel_classes_Property(PROPERTY_RESULT_OF_SUBJECT); return $deliveryResult->getUniquePropertyValue($propResultOfSubject); }
public function getServiceDefinition(core_kernel_classes_Resource $serviceCall) { return $serviceCall->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION)); }
/** * export a compiled delivery into an archive * * @param core_kernel_classes_Resource $compiledDelivery * @throws Exception * @return string */ public static function exportCompiledDelivery(core_kernel_classes_Resource $compiledDelivery) { $fileName = tao_helpers_Display::textCleaner($compiledDelivery->getLabel()) . '.zip'; $path = tao_helpers_File::concat(array(tao_helpers_Export::getExportPath(), $fileName)); if (!tao_helpers_File::securityCheck($path, true)) { throw new Exception('Unauthorized file name'); } $zipArchive = new ZipArchive(); if ($zipArchive->open($path, ZipArchive::CREATE) !== true) { throw new Exception('Unable to create archive at ' . $path); } $taoDeliveryVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion('taoDelivery'); $data = array('dir' => array(), 'label' => $compiledDelivery->getLabel(), 'version' => $taoDeliveryVersion); $directories = $compiledDelivery->getPropertyValues(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DIRECTORY)); foreach ($directories as $id) { $directory = tao_models_classes_service_FileStorage::singleton()->getDirectoryById($id); tao_helpers_File::addFilesToZip($zipArchive, $directory->getPath(), $directory->getRelativePath()); $data['dir'][$id] = $directory->getRelativePath(); } $runtime = $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME)); $serviceCall = tao_models_classes_service_ServiceCall::fromResource($runtime); $data['runtime'] = base64_encode($serviceCall->serializeToString()); $rdfExporter = new tao_models_classes_export_RdfExporter(); $rdfdata = $rdfExporter->getRdfString(array($compiledDelivery)); if (!$zipArchive->addFromString('delivery.rdf', $rdfdata)) { throw common_Exception('Unable to add metadata to exported delivery assembly'); } $data['meta'] = 'delivery.rdf'; $content = json_encode($data); //'<?php return '.common_Utils::toPHPVariableString($data).";"; if (!$zipArchive->addFromString(self::MANIFEST_FILE, $content)) { $zipArchive->close(); unlink($path); throw common_Exception('Unable to add manifest to exported delivery assembly'); } $zipArchive->close(); return $path; }
/** * Clone a QTI Test Resource. * * @param core_kernel_classes_Resource $source The resource to be cloned. * @param core_kernel_classes_Resource $destination An existing resource to be filled as the clone of $source. */ public function cloneContent(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination) { $contentProperty = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); $existingDir = new core_kernel_file_File($source->getUniquePropertyValue($contentProperty)); $service = taoQtiTest_models_classes_QtiTestService::singleton(); $dir = $service->createContent($destination, false); if ($existingDir->fileExists()) { tao_helpers_File::copy($existingDir->getAbsolutePath(), $dir->getAbsolutePath(), true, false); } else { common_Logger::w('Test "' . $source->getUri() . '" had no content, nothing to clone'); } }
/** * Migrates data between source and target storage * * @param array core_kernel_classes_Resource $sourceStorage * @param array core_kernel_classes_Resource core_kernel_classes_Resource * * @return array */ public function migrateData($sourceStorages, $targetStorages) { $sourceImpl = array(); $targetImpl = array(); $returnValue = array('success' => false); // holds the result of each storage $returnData = array(); if (!is_array($sourceStorages) || !is_array($targetStorages)) { // $sourceStorages must be an array of storages $return['status'] = __('Invalid request'); return $return; } if (!is_array($targetStorages)) { // $targetStorages must be an array of storages $return['status'] = __('Invalid request'); return $return; } foreach ($sourceStorages as $sourceStorage) { $returnData[] = array('uri' => $sourceStorage); } foreach ($sourceStorages as $sourceStorage) { $sourceStorageResource = new core_kernel_classes_Resource($sourceStorage); $implLiteral = $sourceStorageResource->getUniquePropertyValue(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_IMPL_PROP)); $impl = $implLiteral->__toString(); $interfaces = class_implements($impl); if (!in_array('taoResultServer_models_classes_ReadableResultStorage', $interfaces)) { $return['status'] = __($sourceStorage . 'does not implement ReadableResultStorage'); return $return; } else { $sourceImpl[] = new $impl(); $returnData[] = array('uri' => $sourceStorage); } } foreach ($targetStorages as $targetStorage) { $targetStorageResource = new core_kernel_classes_Resource($targetStorage); $implLiteral = $targetStorageResource->getUniquePropertyValue(new core_kernel_classes_Property(TAO_RESULTSERVER_MODEL_IMPL_PROP)); $impl = $implLiteral->__toString(); $interfaces = class_implements($impl); if (!in_array('taoResultServer_models_classes_WritableResultStorage', $interfaces)) { $return['status'] = __($sourceStorage . 'does not implement ReadableResultStorage'); return $return; } else { $targetImpl[] = new $impl(); } } foreach ($sourceImpl as $key => $storageSImpl) { //migrate test taker data $allTestTakerIds = $storageSImpl->getAllTestTakerIds(); foreach ($targetImpl as $storageTImpl) { foreach ($allTestTakerIds as $resultIDentifier => $testTakerId) { $storageTImpl->storeRelatedTestTaker($testTakerId["deliveryResultIdentifier"], $testTakerId["testTakerIdentifier"]); } } //migrate Delivery data $allDeliveryIds = $storageSImpl->getAllDeliveryIds(); foreach ($targetImpl as $storageTImpl) { foreach ($allDeliveryIds as $resultIDentifier => $deliveryId) { $storageTImpl->storeRelatedDelivery($deliveryId["deliveryResultIdentifier"], $deliveryId["deliveryIdentifier"]); } } //migrate all service call submitted variables $callIds = $storageSImpl->getAllCallIDs(); //o(n) foreach ($callIds as $callId) { $variables = $storageSImpl->getVariables($callId); foreach ($variables as $variableIdentifier => $observations) { foreach ($observations as $observation) { foreach ($targetImpl as $storageTImpl) { if (isset($observation->callIdItem)) { //item level variable $storageTImpl->storeItemVariable($observation->deliveryResultIdentifier, $observation->test, $observation->item, $observation->variable, $observation->callIdItem); } else { //test level variable //print_r($observation); $storageTImpl->storeTestVariable($observation->deliveryResultIdentifier, $observation->test, $observation->variable, $observation->callIdTest); } } } } } $returnData[$key]['testTakers'] = count($allTestTakerIds); $returnData[$key]['deliveries'] = count($allDeliveryIds); $returnData[$key]['callIds'] = count($callIds); } $returnValue['success'] = true; $returnValue['status'] = __('Migration Successful'); $returnValue['data'] = $returnData; return $returnValue; }
/** * Returns the link of a media resource * * @param \core_kernel_classes_Resource $resource * @return string */ protected function getLink(\core_kernel_classes_Resource $resource) { $instance = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK)); return $instance instanceof \core_kernel_classes_Resource ? $instance->getUri() : (string) $instance; }
/** * retrive type of Connector Conditionnal, Sequestionnal Parallele... * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource connector * @return core_kernel_classes_Resource */ public function getType(core_kernel_classes_Resource $connector) { $returnValue = null; $connTypeProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE); try { $returnValue = $connector->getUniquePropertyValue($connTypeProp); } catch (common_Exception $e) { throw new wfEngine_models_classes_ProcessDefinitonException('Exception when retreiving connector type ' . $connector->getUri()); } return $returnValue; }
/** * Get the core_kernel_file_File object corresponding to the content of $test. * * @param core_kernel_classes_Resource $test A resource corresponding to a TAO Test in the Knowledge Base. * @throws common_exception_Error If an error occurs while retrieving the test content. * @return core_kernel_file_File */ public function getTestContent(core_kernel_classes_Resource $test) { $testContentProperty = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); try { $testcontent = $test->getUniquePropertyValue($testContentProperty); } catch (common_exception_EmptyProperty $e) { $uri = $test->getUri(); $msg = "Test '{$uri}' has no content."; throw new common_exception_Error($msg); } catch (common_Exception $e) { $uri = $test->getUri(); $msg = "Multiple contents found for test '{$uri}'."; throw new common_exception_Error($msg); } if ($testcontent instanceof core_kernel_classes_Resource) { return new core_kernel_file_File($testcontent->getUri()); } else { $uri = $test->getUri(); $msg = "Test '{$uri}' content is not a resource. " . $testcontent; common_Logger::w($msg); return $testcontent; } }
/** * (non-PHPdoc) * * @see \oat\tao\model\media\MediaBrowser::getFileInfo */ public function getFileInfo($link) { // get the media link from the resource $resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link)); if ($resource->exists()) { $fileLink = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK)); $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink; $file = null; $fileManagement = FileManager::getFileManagementModel(); $filePath = $fileManagement->retrieveFile($fileLink); $mime = (string) $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE)); if (file_exists($filePath)) { // add the alt text to file array $altArray = $resource->getPropertyValues(new \core_kernel_classes_Property(MEDIA_ALT_TEXT)); $alt = $resource->getLabel(); if (count($altArray) > 0) { $alt = $altArray[0]; } $file = array('name' => $resource->getLabel(), 'uri' => 'taomedia://mediamanager/' . \tao_helpers_Uri::encode($link), 'mime' => $mime, 'filePath' => basename($filePath), 'size' => filesize($filePath), 'alt' => $alt); return $file; } else { throw new \tao_models_classes_FileNotFoundException($link); } } else { throw new \tao_models_classes_FileNotFoundException($link); } }
public function getOrigin(core_kernel_classes_Resource $assembly) { return (string) $assembly->getUniquePropertyValue(new core_kernel_classes_Property(self::PROPERTY_ORIGIN)); }
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::cloneContent() */ public function cloneContent(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination) { //clone the process: $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); try { $content = $source->getUniquePropertyValue($propInstanceContent); $destination->editPropertyValues($propInstanceContent, $content->duplicate()); } catch (Exception $e) { throw new Exception("the test process cannot be found"); } }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2015 (original work) Open Assessment Technologies SA; * * */ require_once dirname(__FILE__) . '/../includes/raw_start.php'; $user = new core_kernel_classes_Resource(LOCAL_NAMESPACE . DEFAULT_USER_URI_SUFFIX); $login = $user->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)); $password = readline("Enter new password for user '" . $login . "': "); $success = false; if (!empty($password)) { $hash = core_kernel_users_Service::getPasswordHash(); $success = $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD), $hash->encrypt($password)); } die($success ? 0 : 1);
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::onChangeTestLabel() */ public function onChangeTestLabel(core_kernel_classes_Resource $test) { $process = $test->getUniquePropertyValue(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP)); $process->setLabel("Process " . $test->getLabel()); }
/** * Returns the date of the compilation of an assembly as a timestamp * * @param core_kernel_classes_Resource $assembly * @return string */ public function getCompilationDate(core_kernel_classes_Resource $assembly) { return (string) $assembly->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_TIME)); }
public function testCreateSequenceActivity() { $processDefinition = $this->proc; $authoringService = $this->authoringService; $processVariableService = wfEngine_models_classes_VariableService::singleton(); //set the required process variables subjectUri and wsdlContract $var_map = $processVariableService->getProcessVariable("map", true); $var_param1 = $processVariableService->getProcessVariable("param1", true); $var_param2 = $processVariableService->getProcessVariable("param2", true); //create formal param associated to the 3 required proc var: $paramMap = $authoringService->getFormalParameter('map'); if (is_null($paramMap)) { $paramMap = $authoringService->createFormalParameter('map', 'processvariable', $var_map->getUri(), 'label of the formal param "map"'); } $param1 = $authoringService->getFormalParameter('param1'); if (is_null($param1)) { $param1 = $authoringService->createFormalParameter('param1', 'processvariable', $var_param1->getUri(), 'label of the formal param "param1"'); } $param2 = $authoringService->getFormalParameter('param2'); if (is_null($param2)) { $param2 = $authoringService->createFormalParameter('param2', 'processvariable', $var_param2->getUri(), 'label of the formal param "param2"'); } //creating the activity definition and connecting them sequentially: $activityDefinitions = array(); //create an activity and set it as the first: $activity1 = $authoringService->createActivity($processDefinition, 'activity1'); $this->assertNotNull($activity1); $authoringService->setFirstActivity($processDefinition, $activity1); $activityDefinitions[] = $activity1; //create a connector to the first activity and set the type as "sequential" $connector1 = null; $connector1 = $authoringService->createConnector($activity1); $authoringService->setConnectorType($connector1, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE)); $this->assertNotNull($connector1); //same for the 2nd activity: $activity2 = $authoringService->createSequenceActivity($connector1, null, 'activity2'); $connector2 = $authoringService->createConnector($activity2); $authoringService->setConnectorType($connector2, new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_SEQUENCE)); $activityDefinitions[] = $activity2; //then the last: $activity3 = $authoringService->createSequenceActivity($connector2, null, 'activity3'); $activityDefinitions[] = $activity3; //the last activity does not have a connector //set the service(i.e. unit) to each activity: $services = array(); $services[1] = array('url' => 'url of unit1', 'label' => 'label of unit1'); $services[2] = array('url' => 'url of unit2', 'label' => 'label of unit2'); $services[3] = array('url' => 'url of unit3', 'label' => 'label of unit3'); $i = 1; $serviceDefinitions = array(); foreach ($activityDefinitions as $activity) { $url_unit = $services[$i]['url']; $label_unit = $services[$i]['label']; //try to find if a service definiton has already been created for the unit: $serviceDefinition = null; $serviceDefinitionClass = new core_kernel_classes_Class(CLASS_SUPPORTSERVICES); $foundServiceDefinitions = $serviceDefinitionClass->searchInstances(array(PROPERTY_SUPPORTSERVICES_URL => $url_unit), array('like' => false)); if (!empty($foundServiceDefinitions)) { $serviceDefinition = array_shift($foundServiceDefinitions); } if (is_null($serviceDefinition)) { //if no corresponding service def found, create a service definition: $serviceDefinition = $serviceDefinitionClass->createInstance($label_unit, 'created by process map testcase'); //set service definition (the unit) and parameters: $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SUPPORTSERVICES_URL), $url_unit); $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $paramMap->getUri()); $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $param1->getUri()); $serviceDefinition->setPropertyValue(new core_kernel_classes_Property(PROPERTY_SERVICESDEFINITION_FORMALPARAMIN), $param2->getUri()); $serviceDefinitions[$serviceDefinition->getUri()] = $serviceDefinition; } $this->assertNotNull($serviceDefinition); //create a call of service and associate the service definition to it: $service = $authoringService->createInteractiveService($activity); $service->setPropertyValue(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), $serviceDefinition->getUri()); $authoringService->setActualParameter($service, $paramMap, $var_map->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE); $authoringService->setActualParameter($service, $param1, $var_param1->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE); $authoringService->setActualParameter($service, $param2, $var_param2->getUri(), PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN, PROPERTY_ACTUALPARAMETER_PROCESSVARIABLE); $this->assertNotNull($service); $i++; } //end of process definition creation //get the ordered list of activity of the sequential process: $activityList = array(); //get list of all activities: $activities = $authoringService->getActivitiesByProcess($processDefinition); $totalNumber = count($activities); //find the first one: property isinitial == true (must be only one, if not error) and set as the currentActivity: $currentActivity = null; foreach ($activities as $activity) { $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) { $currentActivity = $activity; break; } } } $this->assertNotNull($currentActivity); //start the loop: for ($i = 0; $i < $totalNumber; $i++) { //set the test in the table: $activityList[$i] = $currentActivity; //get its connector (check the type is "sequential) if ok, get the next activity $connectors = $currentActivity->getPropertyValues(new core_kernel_classes_Property(PROPERTY_STEP_NEXT)); $nextActivity = null; foreach ($connectors as $connectorUri) { $connector = new core_kernel_classes_Resource($connectorUri); $connectorType = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE)); if ($connectorType->getUri() == INSTANCE_TYPEOFCONNECTORS_SEQUENCE) { $nextActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_STEP_NEXT)); break; } } if (!is_null($nextActivity)) { $currentActivity = $nextActivity; } else { if ($i == $totalNumber - 1) { //it is normal, since it is the last activity and test } else { throw new Exception('the next activity of the connector is not found'); } } } $this->assertEquals(count($activityList), 3); //delete all created resources: $var_map->delete(); $var_param1->delete(); $var_param2->delete(); $paramMap->delete(); $param1->delete(); $param2->delete(); foreach ($serviceDefinitions as $serviceDefinition) { $serviceDefinition->delete(); } }
/** * To build the audit trail of a process execution. * Return the list of all activity executions, ordered by creation time, * with their row data. * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource processExecution * @param boolean withData * @return array */ public function getExecutionHistory(core_kernel_classes_Resource $processExecution, $withData = false) { $returnValue = array(); $previousProperty = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_PREVIOUS); $followingProperty = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_FOLLOWING); $recoveryService = wfEngine_models_classes_RecoveryService::singleton(); $currentActivityExecutions = $this->getCurrentActivityExecutions($processExecution); $creationTime = array(); $unorderedActivityExecutions = array(); $allActivityExecutions = $processExecution->getPropertyValues($this->processInstancesActivityExecutionsProp); $count = count($allActivityExecutions); for ($i = 0; $i < $count; $i++) { $uri = $allActivityExecutions[$i]; if (common_Utils::isUri($uri)) { $activityExecution = new core_kernel_classes_Resource($uri); $createdOn = (string) $activityExecution->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_TIME_CREATED)); if ($withData) { $previousArray = array(); $followingArray = array(); $previous = $activityExecution->getPropertyValues($previousProperty); $countPrevious = count($previous); for ($j = 0; $j < $countPrevious; $j++) { if (common_Utils::isUri($previous[$j])) { $prevousActivityExecution = new core_kernel_classes_Resource($previous[$j]); $previousArray[] = $prevousActivityExecution->getUri(); } } $following = $activityExecution->getPropertyValues($followingProperty); $countFollowing = count($following); for ($k = 0; $k < $countFollowing; $k++) { if (common_Utils::isUri($following[$k])) { $followingActivityExecution = new core_kernel_classes_Resource($following[$k]); $followingArray[] = $followingActivityExecution->getUri(); } } $unorderedActivityExecutions[$uri] = array('activityExecution' => $activityExecution, 'executionOf' => $this->activityExecutionService->getExecutionOf($activityExecution), 'createdOn' => date('d-m-Y G:i:s', $createdOn), 'current' => array_key_exists($activityExecution->getUri(), $currentActivityExecutions), 'status' => $this->activityExecutionService->getStatus($activityExecution), 'ACLmode' => $this->activityExecutionService->getAclMode($activityExecution), 'restrictedRole' => $this->activityExecutionService->getRestrictedRole($activityExecution), 'restrictedUser' => $this->activityExecutionService->getRestrictedUser($activityExecution), 'user' => $this->activityExecutionService->getActivityExecutionUser($activityExecution), 'previous' => $previousArray, 'following' => $followingArray, 'nonce' => $this->activityExecutionService->getNonce($activityExecution), 'context' => $recoveryService->getContext($activityExecution, ''), 'variables' => $this->activityExecutionService->getVariables($activityExecution)); } else { $unorderedActivityExecutions[$uri] = $activityExecution->getUri(); } $creationTime[$uri] = $createdOn; } } asort($creationTime); foreach ($creationTime as $uri => $time) { $returnValue[] = $unorderedActivityExecutions[$uri]; } return (array) $returnValue; }
/** * This function should build an authentification token for the user * This function is NOT yet secure * * @param core_kernel_classes_Resource $user * @return returns a token string */ protected function buildToken(core_kernel_classes_Resource $user, $time = null) { $time = is_null($time) ? time() : $time; $userPass = (string) $user->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD)); return $time . '_' . md5($time . $user->getUri() . $userPass); }
/** * Short description of method deleteConnectorNextActivity * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource connector * @param string connectionType * @return mixed */ public function deleteConnectorNextActivity(core_kernel_classes_Resource $connector, $connectionType = 'next') { $nextActivitiesProp = new core_kernel_classes_Property(PROPERTY_STEP_NEXT); $connectorService = wfEngine_models_classes_ConnectorService::singleton(); switch ($connectionType) { case 'next': $property = $nextActivitiesProp; break; case 'then': $property = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN); break; case 'else': $property = new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE); break; default: throw new Exception('Trying to delete the value of an unauthorized connector property'); } $activityRefProp = new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE); $activityRef = $connector->getUniquePropertyValue($activityRefProp)->getUri(); if ($property->getUri() == PROPERTY_STEP_NEXT) { //manage the connection to the following activities $nextActivityCollection = $connector->getPropertyValuesCollection($property); foreach ($nextActivityCollection->getIterator() as $nextActivity) { if ($connectorService->isConnector($nextActivity)) { $nextActivityRef = $nextActivity->getUniquePropertyValue($activityRefProp)->getUri(); if ($nextActivityRef == $activityRef) { //delete following connectors only if they have the same activity reference wfAuthoring_models_classes_ConnectorService::singleton()->delete($nextActivity); } } } $connector->removePropertyValues($nextActivitiesProp); } elseif ($property->getUri() == PROPERTY_TRANSITIONRULES_THEN || $property->getUri() == PROPERTY_TRANSITIONRULES_ELSE) { //it is a split connector: get the transition rule, if exists $transitionRule = $connector->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE)); if (!is_null($transitionRule)) { $nextActivity = $transitionRule->getOnePropertyValue($property); if (!is_null($nextActivity)) { if ($connectorService->isConnector($nextActivity)) { $nextActivityRef = $nextActivity->getUniquePropertyValue($activityRefProp)->getUri(); if ($nextActivityRef == $activityRef) { //delete following connectors only if they have the same activity reference wfAuthoring_models_classes_ConnectorService::singleton()->delete($nextActivity); } } $connector->removePropertyValues($nextActivitiesProp, array('pattern' => $nextActivity->getUri())); $transitionRule->removePropertyValues($property, array('pattern' => $nextActivity->getUri())); } } } }
public function getDeliveryFromCompiledDelivery(core_kernel_classes_Resource $compiledDelivery) { return $compiledDelivery->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_DELIVERY)); }
/** * Short description of method cloneInstance * * @access public * @author Joel Bout, <*****@*****.**> * @param \core_kernel_classes_Resource $instance * @param \core_kernel_classes_Class $clazz * @throws \common_Exception * @throws \core_kernel_classes_EmptyProperty * @return core_kernel_classes_Resource */ public function cloneInstance(\core_kernel_classes_Resource $instance, \core_kernel_classes_Class $clazz = null) { $loginProperty = new \core_kernel_classes_Property(PROPERTY_USER_LOGIN); $login = $instance->getUniquePropertyValue($loginProperty); $returnValue = parent::cloneInstance($instance, $clazz); $userService = \tao_models_classes_UserService::singleton(); try { while ($userService->loginExists($login)) { $login .= (string) rand(0, 9); } $returnValue->editPropertyValues($loginProperty, $login); } catch (common_Exception $ce) { // empty } return $returnValue; }