/**
  * @return array
  */
 protected function getResource($relPath)
 {
     $dir = $this->getTempDirectory();
     $file = $dir->getFile($relPath);
     $file->put(file_get_contents(__DIR__ . $relPath));
     /** @var FileReferenceSerializer $serializer */
     $serializer = ServiceManager::getServiceManager()->get(FileReferenceSerializer::SERVICE_ID);
     $fileUri = $serializer->serialize($file);
     $class = new \core_kernel_classes_Class('fakeClass');
     $resource = $class->createInstance('fakeInstance');
     $prop = new \core_kernel_classes_Property('fakeProp');
     $prop->setRange(new \core_kernel_classes_Class(CLASS_GENERIS_FILE));
     $resource->editPropertyValues($prop, new \core_kernel_classes_Resource($fileUri));
     return array($file, $resource);
 }
 public function createContextOfThetest()
 {
     // ----- Top Class : TaoSubject
     $subjectClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOSubject.rdf#Subject');
     // Create a new subject class for the unit test
     $this->targetSubjectClass = $subjectClass->createSubClass("Sub Subject Class (Unit Test)");
     // Add a custom property to the newly created class
     // Add an instance to this subject class
     $this->subject1 = $this->targetSubjectClass->createInstance("Sub Subject (Unit Test)");
     // Create a new subject sub class to the previous sub class
     $this->targetSubjectSubClass = $this->targetSubjectClass->createSubClass("Sub Sub Subject Class (Unit Test)");
     // Add an instance to this sub subject class
     $this->subject2 = $this->targetSubjectSubClass->createInstance("Sub Sub Subject (Unit Test)");
     // ----- Top Class : Work
     // Create a class and test its instances & properties.
     $this->taoClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#TAOObject');
     $this->targetWorkClass = $this->taoClass->createSubClass('Work', 'The Work class');
     // Add properties to the Work class.
     $this->targetAuthorProperty = $this->targetWorkClass->createProperty('Author', 'The author of the work.');
     $literalClass = new core_kernel_classes_Class(RDFS_LITERAL);
     $this->targetAuthorProperty->setRange($literalClass);
     // Create the Movie class that extends the Work class.
     $this->targetMovieClass = $this->targetWorkClass->createSubClass('Movie', 'The Movie class');
     $this->targetMovieClass = new core_kernel_classes_Class($this->targetMovieClass->getUri());
     // Add properties to the Movie class.
     $this->targetProducerProperty = $this->targetMovieClass->createProperty('Producer', 'The producer of the movie.');
     $this->targetProducerProperty->setRange($literalClass);
     $this->targetProducerProperty->setMultiple(true);
     $this->targetActorsProperty = $this->targetMovieClass->createProperty('Actors', 'The actors playing in the movie.');
     $this->targetActorsProperty->setRange($literalClass);
     $this->targetActorsProperty->setMultiple(true);
     $this->targetRelatedMoviesProperty = $this->targetMovieClass->createProperty('Related Movies', 'Movies related to the movie.');
     $this->targetRelatedMoviesProperty->setRange($this->targetMovieClass);
     $this->targetRelatedMoviesProperty->setMultiple(true);
     //$this->generisUser = core_kernel_users_Service::singleton()->addUser('testCaseUser','testCasepass');
 }
 /**
  * Add a process variable in the model
  * @param string $code
  * @return boolean
  */
 private function addProcessVariable($code)
 {
     $code = preg_replace("/^\\^/", '', $code);
     if (!$this->processVarExists($code)) {
         $processVar = $this->processVarClass->createInstance(self::unCamelize($code));
         if (!is_null($processVar)) {
             //set the new instance of process variable as a property of the class process instance:
             if ($processVar->setType(new core_kernel_classes_Class(RDF_PROPERTY))) {
                 $newProcessInstanceProperty = new core_kernel_classes_Property($processVar->getUri());
                 $newProcessInstanceProperty->setDomain(new core_kernel_classes_Class(CLASS_TOKEN));
                 $newProcessInstanceProperty->setRange($this->rdfLiteralClass);
             }
             return $processVar->setPropertyValue($this->processVarCodeProp, $code);
         }
     }
     return false;
 }
 /**
  * Advanced property handling
  *
  * @param array $propertyValues
  */
 protected function saveAdvProperty($propertyValues)
 {
     // might break using hard
     $range = array();
     foreach ($propertyValues as $key => $value) {
         if (is_array($value)) {
             // set the range
             foreach ($value as $v) {
                 $range[] = new core_kernel_classes_Class(tao_helpers_Uri::decode($v));
             }
         } else {
             $values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
         }
     }
     //if label is empty
     $validator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Property\'s label field is required')));
     if (!$validator->evaluate($values[RDFS_LABEL])) {
         throw new Exception($validator->getMessage());
     }
     $property = new core_kernel_classes_Property($values['uri']);
     unset($values['uri']);
     $property->removePropertyValues(new core_kernel_classes_Property(RDFS_RANGE));
     if (!empty($range)) {
         foreach ($range as $r) {
             $property->setRange($r);
         }
     }
     $this->bindProperties($property, $values);
 }
 /**
  * Short description of method createProcessVariable
  *
  * @access public
  * @author Somsack Sipasseuth, <*****@*****.**>
  * @param  string label
  * @param  string code
  * @return core_kernel_classes_Resource
  */
 public function createProcessVariable($label = '', $code = '')
 {
     $returnValue = null;
     if (!empty($code) && $this->getProcessVariable($code)) {
         throw new Exception("A process variable with the code '{$code}' already exists");
     }
     if (empty($label)) {
         $label = "Process variable";
         if (!empty($code)) {
             $label .= " " . $code;
         }
     }
     $returnValue = $this->createInstance($this->processVariablesClass, $label);
     if (!empty($code)) {
         $returnValue->setPropertyValue($this->codeProperty, $code);
     }
     //set the new instance of process variable as a property of the class process instance:
     $ok = $returnValue->setType(new core_kernel_classes_Class(RDF_PROPERTY));
     if ($ok) {
         $newTokenProperty = new core_kernel_classes_Property($returnValue->getUri());
         $newTokenProperty->setDomain(new core_kernel_classes_Class(CLASS_ACTIVITY_EXECUTION));
         $newTokenProperty->setRange(new core_kernel_classes_Class(RDFS_LITERAL));
         //literal only!
         $newTokenProperty->setPropertyValue(new core_kernel_classes_Property(PROPERTY_MULTIPLE), GENERIS_TRUE);
     } else {
         throw new Exception("the newly created process variable {$label} ({$returnValue->getUri()}) cannot be set as a property of the class Activity Execution");
     }
     return $returnValue;
 }
 /**
  * Advanced property handling
  *
  * @param array $propertyValues
  */
 protected function saveAdvProperty($propertyValues)
 {
     // might break using hard
     $range = array();
     foreach ($propertyValues as $key => $value) {
         if (is_array($value)) {
             // set the range
             foreach ($value as $v) {
                 $range[] = new core_kernel_classes_Class(tao_helpers_Uri::decode($v));
             }
         } else {
             $values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
         }
     }
     $property = new core_kernel_classes_Property($values['uri']);
     unset($values['uri']);
     $property->removePropertyValues(new core_kernel_classes_Property(RDFS_RANGE));
     if (!empty($range)) {
         foreach ($range as $r) {
             $property->setRange($r);
         }
     }
     $this->bindProperties($property, $values);
 }