/** * SyncTask constructor. * @param Action|string $invocable * @param array $params */ public function __construct($invocable, $params) { $this->id = \common_Utils::getNewUri(); $this->invocable = $invocable; $this->setParameters($params); $this->setStatus(self::STATUS_CREATED); }
public function getResourceDescription(core_kernel_classes_Resource $resource, $fromDefinition = true) { $returnValue = new stdClass(); $properties = array(); if ($fromDefinition) { $types = $resource->getTypes(); foreach ($types as $type) { foreach ($type->getProperties(true) as $property) { //$this->$$property->getUri() = array($property->getLabel(),$this->getPropertyValues()); $properties[$property->getUri()] = $property; } } //var_dump($properties); $properties = array_unique($properties); $propertiesValues = $resource->getPropertiesValues($properties); if (count($propertiesValues) == 0) { throw new common_exception_NoContent(); } $propertiesValuesStdClasses = $this->propertiesValuestoStdClasses($propertiesValues); } else { $triples = $resource->getRdfTriples(); if (count($triples) == 0) { throw new common_exception_NoContent(); } foreach ($triples as $triple) { $properties[$triple->predicate][] = common_Utils::isUri($triple->object) ? new core_kernel_classes_Resource($triple->object) : new core_kernel_classes_Literal($triple->object); } $propertiesValuesStdClasses = $this->propertiesValuestoStdClasses($properties); } $returnValue->uri = $resource->getUri(); $returnValue->properties = $propertiesValuesStdClasses; return $returnValue; }
/** * @param boolean $public * @return tao_models_classes_service_StorageDirectory */ public function spawnDirectory($public = false) { $id = common_Utils::getNewUri() . ($public ? '+' : '-'); $directory = $this->getDirectoryById($id); mkdir($directory->getPath(), 0700, true); return $directory; }
/** * Short description of method getValue * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param string rowId * @param string columnId * @param string data * @return mixed */ public function getValue($rowId, $columnId, $data = null) { $returnValue = null; //@TODO : to be delegated to the LazyAdapter : columnNames, adapterOptions, excludedProperties if (isset($this->data[$rowId])) { //return values: if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } else { if (common_Utils::isUri($rowId)) { $user = new core_kernel_classes_Resource($rowId); $this->data[$rowId] = array(); $fastProperty = array(RDFS_LABEL, PROPERTY_USER_LOGIN, PROPERTY_USER_FIRSTNAME, PROPERTY_USER_LASTNAME, PROPERTY_USER_MAIL, PROPERTY_USER_UILG, PROPERTY_USER_DEFLG); $properties = array(); $propertyUris = array_diff($fastProperty, $this->excludedProperties); foreach ($propertyUris as $activityExecutionPropertyUri) { $properties[] = new core_kernel_classes_Property($activityExecutionPropertyUri); } $propertiesValues = $user->getPropertiesValues($properties); foreach ($propertyUris as $propertyUri) { $value = null; if (isset($propertiesValues[$propertyUri]) && count($propertiesValues[$propertyUri])) { $value = reset($propertiesValues[$propertyUri]); } switch ($propertyUri) { case RDFS_LABEL: case PROPERTY_USER_LOGIN: case PROPERTY_USER_FIRSTNAME: case PROPERTY_USER_LASTNAME: case PROPERTY_USER_MAIL: case PROPERTY_USER_LOGIN: case PROPERTY_USER_UILG: case PROPERTY_USER_DEFLG: $this->data[$rowId][$propertyUri] = $value instanceof core_kernel_classes_Resource ? $value->getLabel() : (string) $value; break; } } //get roles: if (!in_array('roles', $this->excludedProperties)) { $i = 0; foreach ($user->getTypes() as $role) { if ($role instanceof core_kernel_classes_Resource) { if ($i) { $this->data[$rowId]['roles'] .= ', '; } else { $this->data[$rowId]['roles'] = ''; } $this->data[$rowId]['roles'] .= $role->getLabel(); } $i++; } } if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } } return $returnValue; }
/** * * @param unknown $userId * @param core_kernel_classes_Resource $assembly * @return taoDelivery_models_classes_execution_KVDeliveryExecution */ public static function spawn(common_persistence_KeyValuePersistence $persistence, $userId, core_kernel_classes_Resource $assembly) { $identifier = self::DELIVERY_EXECUTION_PREFIX . common_Utils::getNewUri(); $de = new self($persistence, $identifier, array(RDFS_LABEL => $assembly->getLabel(), PROPERTY_DELVIERYEXECUTION_DELIVERY => $assembly->getUri(), PROPERTY_DELVIERYEXECUTION_SUBJECT => $userId, PROPERTY_DELVIERYEXECUTION_START => time(), PROPERTY_DELVIERYEXECUTION_STATUS => INSTANCE_DELIVERYEXEC_ACTIVE)); $de->save(); return $de; }
/** * * @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 }
public function testPhpSerialize() { $phpCode = \common_Utils::toPHPVariableString(new FreeAccess()); $restoredModel = eval('return ' . $phpCode . ';'); $this->assertInstanceOf('oat\\generis\\model\\data\\permission\\PermissionInterface', $restoredModel); $this->assertEquals(array(), $restoredModel->getSupportedRights()); $this->assertEquals(array('res1' => array(FreeAccess::RIGHT_UNSUPPORTED)), $restoredModel->getPermissions($this->user, array('res1'))); }
/** * @see \oat\oatbox\PhpSerializable::__toPhpCode() */ public function __toPhpCode() { $class = get_class($this); $name = $this->name; $url = $this->url; $rules = \common_Utils::toHumanReadablePhpString($this->getRules()); return "new {$class}(\n '{$name}',\n {$rules},\n '{$url}'\n )"; }
/** * * @param common_persistence_KeyValuePersistence $persistence * @param unknown $userId * @param core_kernel_classes_Resource $assembly * @return DeliveryExecution */ public static function spawn(common_persistence_KeyValuePersistence $persistence, $userId, core_kernel_classes_Resource $assembly) { $identifier = self::DELIVERY_EXECUTION_PREFIX . common_Utils::getNewUri(); $params = array(RDFS_LABEL => $assembly->getLabel(), PROPERTY_DELVIERYEXECUTION_DELIVERY => $assembly->getUri(), PROPERTY_DELVIERYEXECUTION_SUBJECT => $userId, PROPERTY_DELVIERYEXECUTION_START => microtime(), PROPERTY_DELVIERYEXECUTION_STATUS => InterfaceDeliveryExecution::STATE_ACTIVE); $kvDe = new static($persistence, $identifier, $params); $kvDe->save(); $de = new DeliveryExecution($kvDe); return $de; }
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; }
/** * @param $action * @param $parameters * @param boolean $repeatedly Whether task created repeatedly (for example when execution of task was failed and task puts to the queue again). * @return JsonTask * @throws \common_exception_Error */ public function createTask($action, $parameters, $repeatedly = false) { $task = new JsonTask($action, $parameters); $platform = $this->getPersistence()->getPlatForm(); $query = 'INSERT INTO ' . self::QUEUE_TABLE_NAME . ' (' . self::QUEUE_ID . ', ' . self::QUEUE_OWNER . ', ' . self::QUEUE_TASK . ', ' . self::QUEUE_STATUS . ', ' . self::QUEUE_ADDED . ', ' . self::QUEUE_UPDATED . ') ' . 'VALUES (?, ?, ?, ?, ?, ?)'; $persistence = $this->getPersistence(); $id = \common_Utils::getNewUri(); $persistence->exec($query, array($id, \common_session_SessionManager::getSession()->getUser()->getIdentifier(), json_encode($task), Task::STATUS_CREATED, $platform->getNowExpression(), $platform->getNowExpression())); $task->setId($id); return $task; }
public function assign() { if (!is_null($this->activityExecution)) { $userUri = urldecode($this->getRequestParameter('userUri')); if (!empty($userUri) && common_Utils::isUri($userUri)) { $user = new core_kernel_classes_Resource($userUri); $this->setSuccess($this->activityExecutionService->setActivityExecutionUser($this->activityExecution, $user, true)); } else { $this->setErrorMessage('no user given'); } } }
/** * get the selected group from the current context (from the uri and classUri parameter in the request) * @return core_kernel_classes_Resource $group */ protected function getCurrentInstance() { $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); if (is_null($uri) || empty($uri) || !common_Utils::isUri($uri)) { throw new Exception("No valid uri found"); } $clazz = $this->getCurrentClass(); $role = $this->service->getRole($uri); if (is_null($role)) { throw new Exception("No role found for the uri {$uri}"); } return $role; }
/** * Short description of method getValue * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param string rowId * @param string columnId * @param string data * @return mixed */ public function getValue($rowId, $columnId, $data = null) { $returnValue = null; if (!empty($data) && is_string($data) && common_Utils::isUri($data)) { $data = new core_kernel_classes_Resource($data); } if ($data instanceof core_kernel_classes_Resource) { $returnValue = $data->getLabel(); } else { $returnValue = $data; //return the data, unaltered } return $returnValue; }
public static function toFile($filePath, $triples) { $graph = new \EasyRdf_Graph(); foreach ($triples as $triple) { if (!empty($triple->lg)) { $graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg); } elseif (\common_Utils::isUri($triple->object)) { $graph->add($triple->subject, $triple->predicate, $triple->object); } else { $graph->addLiteral($triple->subject, $triple->predicate, $triple->object); } } $format = \EasyRdf_Format::getFormat('rdfxml'); return file_put_contents($filePath, $graph->serialise($format)); }
/** * * @param core_kernel_classes_Resource $test * @param array $itemUris * @return boolean */ public function save(core_kernel_classes_Resource $test, array $content) { $serializer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID); $serial = $test->getOnePropertyValue($this->getProperty(TEST_TESTCONTENT_PROP)); if (!is_null($serial)) { $directory = $serializer->unserializeDirectory($serial); } else { // null so create one $fss = $this->getServiceLocator()->get(FileSystemService::SERVICE_ID); $base = $fss->getDirectory($this->getOption(self::OPTION_FILESYSTEM)); $directory = $base->getDirectory(\tao_helpers_Uri::getUniqueId(\common_Utils::getNewUri())); $test->editPropertyValues($this->getProperty(TEST_TESTCONTENT_PROP), $serializer->serialize($directory)); } return $directory->getFile('content.json')->put(json_encode($content)); }
/** * Short description of method getVersionedFile * * @access public * @author Cédric Alfonsi, <*****@*****.**> * @param string rowId * @param string columnId * @param string data * @return core_kernel_classes_Resource */ public function getVersionedFile($rowId, $columnId, $data = null) { $returnValue = null; if (empty($data)) { throw new Exception('data can not be empty'); } if (!empty($data) && common_Utils::isUri($data)) { $data = new core_kernel_classes_Resource($data); } if (!core_kernel_versioning_File::isVersionedFile($data)) { throw new Exception('data has to be a valid versioned file uri'); } $returnValue = $data; return $returnValue; }
public function setUp() { $this->login = '******'; $this->password = '******'; $kvStore = common_persistence_AdvKeyValuePersistence::getPersistence(AuthKeyValueAdapter::KEY_VALUE_PERSISTENCE_ID); $user = $kvStore->getDriver()->hGetAll($this->login); if (!$user) { $uri = \common_Utils::getNewUri(); $kvStore->getDriver()->hset($this->login, PROPERTY_USER_PASSWORD, ''); $kvStore->getDriver()->hset($this->login, 'parameters', json_encode(array("uri" => $uri, "http://www.w3.org/2000/01/rdf-schema#label" => "Test taker 1", "http://www.tao.lu/Ontologies/generis.rdf#userUILg" => "http://www.tao.lu/Ontologies/TAO.rdf#Langen-US", "http://www.tao.lu/Ontologies/generis.rdf#userDefLg" => "http://www.tao.lu/Ontologies/TAO.rdf#Langen-US", "http://www.tao.lu/Ontologies/generis.rdf#login" => $this->login, "http://www.tao.lu/Ontologies/generis.rdf#password" => core_kernel_users_Service::getPasswordHash()->encrypt($this->password), "http://www.tao.lu/Ontologies/generis.rdf#userRoles" => ["http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole"], "http://www.tao.lu/Ontologies/generis.rdf#userFirstName" => "Testtaker 1", "http://www.tao.lu/Ontologies/generis.rdf#userLastName" => "Family 047"))); } $config = array('max_size_cached_element' => 10000); $this->adapter = new AuthKeyValueAdapter($config); $this->adapter->setCredentials($this->login, $this->password); }
/** * @ignore */ private static function statement2rdf(PDOStatement $statement) { $graph = new EasyRdf_Graph(); while ($r = $statement->fetch()) { if (isset($r['l_language']) && !empty($r['l_language'])) { $graph->addLiteral($r['subject'], $r['predicate'], $r['object'], $r['l_language']); } elseif (common_Utils::isUri($r['object'])) { $graph->add($r['subject'], $r['predicate'], $r['object']); } else { $graph->addLiteral($r['subject'], $r['predicate'], $r['object']); } } $format = EasyRdf_Format::getFormat('rdfxml'); return $graph->serialise($format); }
public function __construct() { parent::__construct(); $this->processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton(); $this->activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton(); //validate ALL posted values: $processExecutionUri = urldecode($this->getRequestParameter('processExecutionUri')); if (!empty($processExecutionUri) && common_Utils::isUri($processExecutionUri)) { $this->processExecution = new core_kernel_classes_Resource($processExecutionUri); } $activityExecutionUri = urldecode($this->getRequestParameter('activityExecutionUri')); if (!empty($activityExecutionUri) && common_Utils::isUri($activityExecutionUri)) { $this->activityExecution = new core_kernel_classes_Resource($activityExecutionUri); } $this->setSuccess(false); }
public function testCreateTask() { $queue = $this->getInstance(); $params = ['foo' => 'bar', 2, 'three']; $task = $queue->createTask('invocable/Action', $params); $taskId = $task->getId(); $this->assertTrue($task instanceof JsonTask); $this->assertTrue(\common_Utils::isUri($taskId)); $taskData = $this->getTaskData($taskId)[0]; $this->assertEquals($taskId, $taskData[RdsQueue::QUEUE_ID]); $this->assertEquals(JsonTask::STATUS_CREATED, $taskData[RdsQueue::QUEUE_STATUS]); $this->assertRegExp('/\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}/', $taskData[RdsQueue::QUEUE_ADDED]); $this->assertRegExp('/\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}/', $taskData[RdsQueue::QUEUE_UPDATED]); $this->assertEquals(json_encode($task), $taskData[RdsQueue::QUEUE_TASK]); $this->deleteTask($taskId); }
public static function toResource($value) { if (is_array($value)) { $returnValue = array(); foreach ($value as $val) { $returnValue[] = self::toResource($val); } return $returnValue; } else { if (common_Utils::isUri($value)) { return new core_kernel_classes_Resource($value); } else { return new core_kernel_classes_Literal($value); } } }
/** * Short description of method setValue * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param value * @return mixed */ public function setValue($value) { if ($value instanceof tao_helpers_form_data_UploadFileDescription) { // The file is being uploaded. $this->value = $value; } else { if (common_Utils::isUri($value)) { // The file has already been uploaded $file = new core_kernel_file_File($value); $this->value = new tao_helpers_form_data_StoredFileDescription($file); } else { // Empty file upload description, nothing was uploaded. $this->value = new tao_helpers_form_data_UploadFileDescription('', 0, '', ''); } } }
public function render() { $relPath = tao_helpers_Request::getRelativeUrl(); list($extension, $module, $action, $codedUri, $path) = explode('/', $relPath, 5); $path = rawurldecode($path); $uri = base64_decode($codedUri); if (!common_Utils::isUri($uri)) { throw new common_exception_BadRequest('"' . $codedUri . '" does not decode to a valid item URI'); } $item = new core_kernel_classes_Resource($uri); if ($path === 'index') { $this->renderItem($item); } else { $this->renderResource($item, $path); } }
public function __construct() { parent::__construct(); $this->processDefinitionService = wfEngine_models_classes_ProcessDefinitionService::singleton(); $processDefinitionUri = urldecode($this->getRequestParameter('processDefinitionUri')); if (!empty($processDefinitionUri) && common_Utils::isUri($processDefinitionUri)) { $process = new core_kernel_classes_Resource($processDefinitionUri); if ($process->hasType(new core_kernel_classes_Class(CLASS_PROCESS))) { $this->processDefinition = $process; } else { $this->setErrorMessage(__('The resource is not a process definition')); } } else { $this->setErrorMessage(__('No process definition uri given')); } }
public function testSetStatement() { $true = new core_kernel_classes_Resource(GENERIS_TRUE, __METHOD__); $predicate = RDFS_SEEALSO; $property = new core_kernel_classes_Property($predicate, __METHOD__); $this->assertTrue($this->object->setStatement($true->getUri(), $predicate, 'test', DEFAULT_LANG), "setStatement should be able to set a value."); $values = $true->getPropertyValues($property); $this->assertTrue(count($values) > 0); $tripleFound = false; foreach ($values as $value) { if (!common_Utils::isUri($value) && $value == 'test') { $tripleFound = true; break; } } $this->assertTrue($tripleFound, "A property value for property " . $property->getUri() . " should be found for resource " . $true->getUri()); $this->object->removeStatement($true->getUri(), $predicate, 'test', DEFAULT_LANG); }
public static function createUser($data = array(), $lang = null) { if (!isset($data[PROPERTY_USER_LOGIN]) || !isset($data[PROPERTY_USER_PASSWORD])) { throw new \common_exception_InconsistentData('Cannot add user without login or password'); } if (is_null($lang)) { $lang = DEFAULT_LANG; } $login = $data[PROPERTY_USER_LOGIN]; $password = $data[PROPERTY_USER_PASSWORD]; $defaultData = array(RDFS_LABEL => 'Test taker', PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $lang, PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $lang, PROPERTY_USER_ROLES => array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole')); $data = array_merge($defaultData, $data); $data['uri'] = \common_Utils::getNewUri(); $kvStore = common_persistence_AdvKeyValuePersistence::getPersistence(AuthKeyValueAdapter::KEY_VALUE_PERSISTENCE_ID); $kvStore->hset(AuthKeyValueUserService::PREFIXES_KEY . ':' . $login, PROPERTY_USER_PASSWORD, $password); $kvStore->hset(AuthKeyValueUserService::PREFIXES_KEY . ':' . $login, 'parameters', json_encode($data)); return $data; }
/** * Result Table entry page * @throws \tao_models_classes_MissingRequestParameterException */ public function index() { $deliveryService = DeliveryAssemblyService::singleton(); if ($this->getRequestParameter('classUri') !== $deliveryService->getRootClass()->getUri()) { $filter = $this->getRequestParameter('filter'); $uri = $this->getRequestParameter('uri'); if (!\common_Utils::isUri(tao_helpers_Uri::decode($uri))) { throw new \tao_models_classes_MissingRequestParameterException('uri'); } $this->setData('filter', $filter); $this->setData('uri', $uri); $this->setView('resultTable.tpl'); } else { $this->setData('type', 'info'); $this->setData('error', __('No tests have been taken yet. As soon as a test-taker will take a test his results will be displayed here.')); $this->setView('index.tpl'); } }
/** * Imports the rdf file into the selected class * * @param string $file * @param core_kernel_classes_Class $class * @return common_report_Report */ private function flatImport($file, core_kernel_classes_Class $class) { $report = common_report_Report::createSuccess(__('Data imported successfully')); $graph = new EasyRdf_Graph(); $graph->parseFile($file); // keep type property $map = array(RDF_PROPERTY => RDF_PROPERTY); foreach ($graph->resources() as $resource) { $map[$resource->getUri()] = common_Utils::getNewUri(); } $format = EasyRdf_Format::getFormat('php'); $data = $graph->serialise($format); foreach ($data as $subjectUri => $propertiesValues) { $resource = new core_kernel_classes_Resource($map[$subjectUri]); $subreport = $this->importProperties($resource, $propertiesValues, $map, $class); $report->add($subreport); } return $report; }
/** * Short description of method render * * @access public * @author Joel Bout, <*****@*****.**> * @return string */ public function render() { if (!empty($this->value)) { if (common_Utils::isUri($this->value)) { $file = new core_kernel_file_File($this->value); if ($file->fileExists()) { $fileInfo = $file->getFileInfo(); $fileInfo->getFilename(); } else { $file->delete(); } } } $returnValue = $this->renderLabel(); $returnValue .= "<input type='hidden' name='MAX_FILE_SIZE' value='" . tao_helpers_form_elements_File::MAX_FILE_SIZE . "' />"; $returnValue .= "<input type='file' name='{$this->name}' id='{$this->name}' "; $returnValue .= $this->renderAttributes(); $returnValue .= " value='{$this->value}' />"; return (string) $returnValue; }