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 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 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; }
public function testIsUri() { $toto = 'http://localhost/middleware/Rules.rdf#i122044076930844'; $toto2 = 'j ai super fain'; $toto3 = 'http://localhost/middleware/Rules.rdf'; $this->assertTrue(common_Utils::isUri($toto)); $this->assertFalse(common_Utils::isUri($toto2)); $this->assertFalse(common_Utils::isUri($toto3)); }
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; }
/** * @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); }
/** * 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 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)); }
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 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); } }
/** * 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 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); } } }
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 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); }
/** * 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'); } }
/** * 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; }
/** * Short description of method getValue * * @access public * @author Joel Bout, <*****@*****.**> * @param string rowId * @param string columnId * @param string data * @return mixed */ public function getValue($rowId, $columnId, $data = null) { $returnValue = null; if (isset($this->data[$rowId])) { //return values: if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } else { if (common_Utils::isUri($rowId)) { $excludedProperties = is_array($this->options) && isset($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array(); $processExecutionService = wfEngine_models_classes_ProcessExecutionService::singleton(); $processInstance = new core_kernel_classes_Resource($rowId); $this->data[$rowId] = array(); if (!in_array(RDFS_LABEL, $excludedProperties)) { $this->data[$rowId][RDFS_LABEL] = $processInstance->getLabel(); } if (!in_array(PROPERTY_PROCESSINSTANCES_STATUS, $excludedProperties)) { $status = $processExecutionService->getStatus($processInstance); $this->data[$rowId][PROPERTY_PROCESSINSTANCES_STATUS] = is_null($status) ? 'n/a' : $status->getLabel(); } if (!in_array(PROPERTY_PROCESSINSTANCES_EXECUTIONOF, $excludedProperties)) { $executionOf = $processExecutionService->getExecutionOf($processInstance); $this->data[$rowId][PROPERTY_PROCESSINSTANCES_EXECUTIONOF] = is_null($executionOf) ? 'n/a' : $executionOf->getLabel(); } if (!in_array(PROPERTY_PROCESSINSTANCES_TIME_STARTED, $excludedProperties)) { $time = (string) $processInstance->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_TIME_STARTED)); $this->data[$rowId][PROPERTY_PROCESSINSTANCES_TIME_STARTED] = !empty($time) ? date('d-m-Y G:i:s', $time) : 'n/a'; } // if(!in_array(PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS, $excludedProperties)){ // $currentActivityExecutions = $processExecutionService->getCurrentActivityExecutions($processInstance); // $this->data[$rowId][PROPERTY_PROCESSINSTANCES_CURRENTACTIVITYEXECUTIONS] = new wfAuthoring_helpers_Monitoring_ActivityMonitoringGrid(array_keys($currentActivityExecutions)); // } if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } } return $returnValue; }
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('processUri')); if (!empty($processExecutionUri) && common_Utils::isUri($processExecutionUri)) { $processExecution = new core_kernel_classes_Resource($processExecutionUri); //check that the process execution is not finished or closed here: if ($this->processExecutionService->isFinished($processExecution)) { common_Logger::w('Cannot browse a finished process execution'); $this->redirectToMain(); } else { $this->processExecution = $processExecution; $activityExecutionUri = urldecode($this->getRequestParameter('activityUri')); if (!empty($activityExecutionUri) && common_Utils::isUri($activityExecutionUri)) { $activityExecution = new core_kernel_classes_Resource($activityExecutionUri); $currentActivityExecutions = $this->processExecutionService->getCurrentActivityExecutions($this->processExecution); //check if it is a current activity exec: if (array_key_exists($activityExecutionUri, $currentActivityExecutions)) { $this->activityExecution = $activityExecution; //if ok, check the nonce: $nc = $this->getRequestParameter('nc'); if ($this->activityExecutionService->checkNonce($this->activityExecution, $nc)) { $this->activityExecutionNonce = true; } else { $this->activityExecutionNonce = false; } } else { //the provided activity execution is no longer the current one (link may be outdated). //the user is redirected to the current activity execution if allowed, //or redirected to "main" if there are more than one allowed current activity execution or none common_Logger::w('The provided activity execution is no longer the current one'); $this->autoRedirecting = true; } } } } }
public function getValue($rowId, $columnId, $data = null) { $returnValue = null; if (isset($this->data[$rowId])) { //return values: if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } else { if (common_Utils::isUri($rowId)) { $processInstance = new core_kernel_classes_Resource($rowId); //TODO: property uris need to be set in the constant files: $unit = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('unitUri')); $countryCode = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('CountryCOde')); $langCode = $processInstance->getOnePropertyValue(TranslationProcessHelper::getProperty('LanguageCode')); $this->data[$rowId] = array('unit' => is_null($unit) ? 'n/a' : $unit->getLabel(), 'country' => $countryCode instanceof core_kernel_classes_Literal ? $countryCode->literal : 'n/a', 'language' => $langCode instanceof core_kernel_classes_Literal ? $langCode->literal : 'n/a'); if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } } return $returnValue; }
/** * * @author "Patrick Plichart, <*****@*****.**>" * @param string $resultServerUri * @param string $callOptions * @throws common_exception_MissingParameter */ public function initResultServer($resultServerUri, $callOptions = null) { if (common_Utils::isUri($resultServerUri)) { PHPSession::singleton()->setAttribute("resultServerUri", $resultServerUri); // check if a resultServer has already been intialized for this definition $initializedResultServer = null; $listResultServers = array(); if (PHPSession::singleton()->hasAttribute("resultServerObject")) { $listResultServers = PHPSession::singleton()->getAttribute("resultServerObject"); if (isset($listResultServers[$resultServerUri])) { $initializedResultServer = $listResultServers[$resultServerUri]; } } if (is_null($callOptions) and !is_null($initializedResultServer)) { // the policy is that if the result server has already been intialized and configured further calls without callOptions will reuse the same calloptions } else { $listResultServers[$resultServerUri] = new taoResultServer_models_classes_ResultServer($resultServerUri, $callOptions); PHPSession::singleton()->setAttribute("resultServerObject", $listResultServers); } } else { throw new common_exception_MissingParameter("resultServerUri"); } }
/** * Check additional inputs for the 'setConfig' action. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @return void */ public function checkHardifyInput() { $defaults = array('class' => null, 'createForeigns' => false, 'recursive' => false, 'additionalProperties' => null, 'topClass' => null); $this->options = array_merge($defaults, $this->options); if (empty($this->options['class'])) { $this->error("Please provide the 'class' parameter.", true); } else { $classUri = trim($this->options['class']); if (common_Utils::isUri($classUri)) { // We are OK with the class to Hardify $class = new core_kernel_classes_Class($classUri); $this->options['class'] = $class; if (!empty($this->options['additionalProperties'])) { $additionalProperties = explode(',', $this->options['additionalProperties']); if (empty($additionalProperties)) { $this->error("The 'additionalProperties' parameter value is invalid.", true); } else { foreach ($additionalProperties as $k => $aP) { $uri = trim($aP); if (true == common_Utils::isUri($uri)) { // store clean uri. $additionalProperties[$k] = new core_kernel_classes_Property($uri); } else { $this->error("'{$uri}' is not a valid URI in 'additionalProperties'.", true); } } $this->options['additionalProperties'] = $additionalProperties; if ($this->options['topClass'] == null) { $this->options['topClass'] = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE); } else { $topClassUri = trim($this->options['topClass']); if (true == common_Utils::isUri($topClassUri)) { $this->options['topClass'] = new core_kernel_classes_Class($topClassUri); } else { $this->error("'{$topClassUri}' is not a valid URI in 'topClass'.", true); } } } } } else { $this->error("The 'class' parameter value is not a valid URI.", true); } } }
/** * @dataProvider serviceProvider * @author Lionel Lecaque, lionel@taotesting.com */ public function testGetAll($service, $topclass = null) { if ($topclass == null) { $this->markTestSkipped('This test do not apply to topclass', $topclass); } $url = $this->host . $service; $returnedData = $this->curl($url); $data = json_decode($returnedData, true); $this->assertArrayHasKey('success', $data); $this->assertTrue($data["success"]); $ItemClass = new \core_kernel_classes_Class($topclass); $instances = $ItemClass->getInstances(true); foreach ($data['data'] as $results) { $this->assertInternalType('array', $results); $this->assertArrayHasKey('uri', $results); $this->assertArrayHasKey('properties', $results); $this->assertInternalType('array', $instances); $this->assertArrayHasKey($results['uri'], $instances); $resource = $instances[$results['uri']]; foreach ($results['properties'] as $propArray) { $this->assertInternalType('array', $propArray); $this->assertArrayHasKey('predicateUri', $propArray); $prop = new \core_kernel_classes_Property($propArray['predicateUri']); $values = $resource->getPropertyValues($prop); $this->assertArrayHasKey('values', $propArray); $current = current($propArray['values']); $this->assertInternalType('array', $current); $this->assertArrayHasKey('valueType', $current); if (\common_Utils::isUri(current($values))) { $this->assertEquals('resource', $current['valueType']); } else { $this->assertEquals('literal', $current['valueType']); } $this->assertArrayHasKey('value', $current); $this->assertEquals(current($values), $current['value']); } } }
/** * Short description of method insertRows * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @param array rows * @return boolean */ public function insertRows($rows) { $returnValue = (bool) false; // The class has multiple properties $multipleColumns = array(); $size = count($rows); if ($size > 0) { $dbWrapper = \core_kernel_classes_DbWrapper::singleton(); //building the insert query //set the column names $query = 'INSERT INTO "' . $this->table . '" (uri'; foreach ($this->columns as $column) { if (isset($column['multi']) && $column['multi'] === true) { continue; } $query .= ', ' . $dbWrapper->quoteIdentifier($column['name']) . ''; } $query .= ') VALUES '; $uris = array(); //set the values foreach ($rows as $i => $row) { $uris[] = $row['uri']; $query .= "('{$row['uri']}'"; foreach ($this->columns as $column) { if (array_key_exists($column['name'], $row)) { //the property is multiple, postone its treatment if (isset($column['multi']) && $column['multi'] === true) { continue; } else { if (isset($column['foreign']) && !empty($column['foreign'])) { //set the uri of the foreign resource $foreignResource = $row[$column['name']]; if ($foreignResource instanceof \core_kernel_classes_Resource) { $query .= ", '{$foreignResource->getUri()}'"; } else { if (!empty($foreignResource)) { $query .= ", " . $dbWrapper->quote($foreignResource); } else { $query .= ", NULL"; } } } else { $value = $row[$column['name']]; if ($value instanceof \core_kernel_classes_Resource) { $query .= ", '{$value->getUri()}'"; } else { //the value is a literal $value = trim($dbWrapper->quote($value), "'\""); $query .= ", '{$value}'"; } } } } } $query .= ")"; if ($i < $size - 1) { $query .= ','; } } // Insert rows of the main table $dbWrapper->exec($query); //get the ids of the inserted rows $uriList = ''; foreach ($uris as $uri) { $uriList .= "'{$uri}',"; } $uriList = substr($uriList, 0, strlen($uriList) - 1); $instanceIds = array(); $query = 'SELECT "id", "uri" FROM "' . $this->table . '" WHERE "uri" IN (' . $uriList . ')'; $result = $dbWrapper->query($query); while ($r = $result->fetch()) { $instanceIds[$r['uri']] = $r['id']; } // If the class has multiple properties // Insert rows in its associate table <tableName>Props foreach ($rows as $row) { $queryRows = ""; foreach ($this->columns as $column) { $multiplePropertyUri = Utils::getLongName($column['name']); if (!isset($column['multi']) || $column['multi'] === false || $multiplePropertyUri == RDF_TYPE) { continue; } $multiQuery = 'SELECT "object", "l_language" FROM "statements" WHERE "subject" = ? AND "predicate" = ?'; $multiResult = $dbWrapper->query($multiQuery, array($row['uri'], $multiplePropertyUri)); while ($t = $multiResult->fetch()) { if (!empty($queryRows)) { $queryRows .= ','; } $object = $dbWrapper->quote($t['object']); if (\common_Utils::isUri($t['object'])) { $queryRows .= "({$instanceIds[$row['uri']]}, '{$multiplePropertyUri}', NULL, {$object}, '{$t['l_language']}')"; } else { $queryRows .= "({$instanceIds[$row['uri']]}, '{$multiplePropertyUri}', {$object}, NULL, '{$t['l_language']}')"; } } } if (!empty($queryRows)) { $queryMultiple = 'INSERT INTO "' . $this->table . 'props" ("instance_id", "property_uri", "property_value", "property_foreign_uri", "l_language") VALUES ' . $queryRows; $multiplePropertiesResult = $dbWrapper->exec($queryMultiple); } } } return (bool) $returnValue; }
/** * Short description of method checkProvidedUri * * @access private * @author Jerome Bogaerts, <*****@*****.**> * @param string uri * @return string */ private static function checkProvidedUri($uri) { $returnValue = (string) ''; if ($uri != '') { if (common_Utils::isUri($uri)) { $returnValue = $uri; } else { throw new common_Exception("Could not create new Resource, malformed URI provided: '" . $uri . "'."); } } else { $returnValue = common_Utils::getNewUri(); } return (string) $returnValue; }
/** * Get JSON monitoring data */ public function monitorProcess() { $returnValue = array(); $filters = null; //get the filter if ($this->hasRequestParameter('filter')) { $filter = $this->getRequestParameter('filter'); $filter = $filter == 'null' || empty($filter) ? null : $filter; if (is_array($filter)) { foreach ($filter as $propertyUri => $propertyValues) { foreach ($propertyValues as $i => $propertyValue) { $propertyDecoded = tao_helpers_Uri::decode($propertyValue); if (common_Utils::isUri($propertyDecoded)) { $filters[tao_helpers_Uri::decode($propertyUri)][$i] = $propertyDecoded; } } } } } //get the processes uris $processesUri = $this->hasRequestParameter('processesUri') ? $this->getRequestParameter('processesUri') : null; $processInstancesClass = new core_kernel_classes_Class(CLASS_PROCESSINSTANCES); if (!is_null($filters)) { $processExecutions = $processInstancesClass->searchInstances($filters, array('recursive' => true)); } else { if (!is_null($processesUri)) { foreach ($processesUri as $processUri) { $processExecutions[$processUri] = new core_kernel_classes_resource($processUri); } } else { $processExecutions = $processInstancesClass->getInstances(); } } $processMonitoringGrid = new wfEngine_helpers_Monitoring_ProcessMonitoringGrid(array_keys($processExecutions), $this->processMonitoringGridOptions); $data = $processMonitoringGrid->toArray(); echo json_encode($data); }
/** * 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; }
/** * Build a SQL search pattern on basis of a pattern and a comparison mode. * * @param tring pattern A value to compare. * @param boolean like The manner to compare values. If set to true, the LIKE SQL operator will be used. If set to false, the = (equal) SQL operator will be used. * @return string */ public static function buildSearchPattern(common_persistence_SqlPersistence $persistence, $pattern, $like = true) { $returnValue = ''; // Take care of RDFS Literals! if ($pattern instanceof core_kernel_classes_Literal) { $pattern = $pattern->__toString(); } switch (gettype($pattern)) { case 'object': if ($pattern instanceof core_kernel_classes_Resource) { $returnValue = '= ' . $persistence->quote($pattern->getUri()); } else { common_Logger::w('non ressource as search parameter: ' . get_class($pattern), 'GENERIS'); } break; default: if ($like === true) { $like = \common_Utils::isUri($pattern) ? false : true; } $patternToken = $pattern; $wildcard = mb_strpos($patternToken, '*', 0, 'UTF-8') !== false; $object = trim(str_replace('*', '%', $patternToken)); if ($like) { if (!$wildcard && !preg_match("/^%/", $object)) { $object = "%" . $object; } if (!$wildcard && !preg_match("/%\$/", $object)) { $object = $object . "%"; } if (!$wildcard && $object === '%') { $object = '%%'; } $returnValue .= 'LIKE ' . $persistence->quote($object); } else { $returnValue .= '= ' . $persistence->quote($patternToken); } break; } return $returnValue; }