/**
  * Short description of method createActivity
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource process
  * @param  string label
  * @return core_kernel_classes_Resource
  */
 public function createActivity(core_kernel_classes_Resource $process, $label = '')
 {
     $returnValue = null;
     $activityLabel = "";
     $number = 0;
     if (empty($label)) {
         $number = $process->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES))->count();
         $number += 1;
         $activityLabel = "Activity_{$number}";
     } else {
         $activityLabel = $label;
     }
     $activityClass = new core_kernel_classes_Class(CLASS_ACTIVITIES);
     $activity = $activityClass->createInstance($activityLabel, "created by ActivityService.Class");
     if (!empty($activity)) {
         //associate the new instance to the process instance
         $process->setPropertyValue(new core_kernel_classes_Property(PROPERTY_PROCESS_ACTIVITIES), $activity->getUri());
         //set if it is the first or not:
         if ($number == 1) {
             $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_TRUE);
         } else {
             $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL), GENERIS_FALSE);
         }
         //by default, set the 'isHidden' property value to false:
         $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISHIDDEN), GENERIS_FALSE);
         //by default we add the back and forward controls to the activity
         $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_CONTROLS), array(INSTANCE_CONTROL_BACKWARD, INSTANCE_CONTROL_FORWARD));
         $returnValue = $activity;
     } else {
         throw new Exception("the activity cannot be created for the process {$process->getUri()}");
     }
     return $returnValue;
 }
 private function getItem(core_kernel_classes_Resource $service)
 {
     $inParameterCollection = $service->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN));
     $propActualParamConstantValue = new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_CONSTANTVALUE);
     $propActualParamFormalParam = new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_FORMALPARAMETER);
     $propFormalParamName = new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_NAME);
     foreach ($inParameterCollection->getIterator() as $inParameter) {
         $formalParameter = $inParameter->getUniquePropertyValue($propActualParamFormalParam);
         if ($formalParameter->getUri() == 'http://www.tao.lu/Ontologies/TAODelivery.rdf#FormalParamItemUri') {
             $inParameterConstant = $inParameter->getOnePropertyValue($propActualParamConstantValue);
             if (!is_null($inParameterConstant) && $inParameterConstant instanceof core_kernel_classes_Resource) {
                 return $inParameterConstant;
             } else {
                 throw new common_exception_InconsistentData('missing item constant for service ' . $service->getUri());
             }
         }
     }
     throw new common_exception_InconsistentData('no item parameter for ' . $service->getUri());
 }
 public function testRemoveStatement()
 {
     $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(GENERIS_TRUE, $predicate, 'test', 'EN'));
     $remove = $this->object->removeStatement(GENERIS_TRUE, $predicate, 'test', 'EN');
     $this->assertTrue($remove);
     $value = $true->getPropertyValuesCollection($property);
     $this->assertTrue($value->isEmpty());
 }
 /**
  * Short description of method isIsolatedConnector
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource connector
  * @return boolean
  */
 public function isIsolatedConnector(core_kernel_classes_Resource $connector)
 {
     $returnValue = (bool) false;
     $returnValue = true;
     //need to be initiated as true
     $propNextActivities = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     foreach ($connector->getPropertyValuesCollection($propNextActivities)->getIterator() as $nextActivityOrConnector) {
         if ($this->activityService->isActivity($nextActivityOrConnector)) {
             $returnValue = false;
         } else {
             if ($this->connectorService->isConnector($nextActivityOrConnector)) {
                 $isolated = $this->isIsolatedConnector($nextActivityOrConnector);
                 if ($returnValue) {
                     $returnValue = $isolated;
                 }
             } else {
                 throw new common_exception_Error('the next acitivty of "' . $connector->getUri() . '" is neither an activity nor a connector');
             }
         }
     }
     if ($returnValue) {
         $this->isolatedConnectors[$connector->getUri()] = $connector;
     }
     return (bool) $returnValue;
 }
 /**
  * Short description of method evaluateSPX
  *
  * @access protected
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  array $variable
  * @return mixed
  */
 protected function evaluateSPX($variable = array())
 {
     common_Logger::d('SPX TYPE', array('Generis Term evaluateSPX'));
     $resource = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET));
     if ($resource instanceof core_kernel_classes_Resource) {
         if (array_key_exists($resource->getUri(), $variable)) {
             common_Logger::d('Variable uri : ' . $resource->getUri() . ' found', array('Generis Term evaluateSPX'));
             common_Logger::d('Variable name : ' . $resource->getLabel() . ' found', array('Generis Term evaluateSPX'));
             $resource = new core_kernel_classes_Resource($variable[$resource->getUri()]);
             common_Logger::d('Variable repaced uri : ' . $resource->getUri(), array('Generis Term evaluateSPX'));
             common_Logger::d('Variable repaced name : ' . $resource->getLabel(), array('Generis Term evaluateSPX'));
         }
         try {
             $propertyInstance = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE));
         } catch (common_Exception $e) {
             echo $e;
             var_dump($this);
             die('unable to get property value in Term');
         }
         //    		if(array_key_exists($propertyInstance->getUri(),$variable)) {
         //				$logger->debug('Variable uri : ' .  $propertyInstance->getUri() . ' found' , __FILE__, __LINE__);
         //    			$logger->debug('Variable name : ' .  $propertyInstance->getLabel() . ' found' , __FILE__, __LINE__);
         //				$propertyInstance = new core_kernel_classes_Resource($variable[$resource->getUri()]);
         //    			$logger->debug('Variable repaced uri : ' .  $propertyInstance->getUri() , __FILE__, __LINE__);
         //    			$logger->debug('Variable repaced name : ' .  $propertyInstance->getLabel() , __FILE__, __LINE__);
         //    	    }
         $property = new core_kernel_classes_Property($propertyInstance->getUri());
         common_Logger::d('Property uri ' . $property->getUri(), array('Generis Term evaluateSPX'));
         common_Logger::d('Property name ' . $property->getLabel(), array('Generis Term evaluateSPX'));
         $returnValue = $resource->getPropertyValuesCollection($property);
         common_Logger::d($returnValue->count() . ' values returned ', array('Generis Term evaluateSPX'));
         if ($returnValue->isEmpty()) {
             $newEmptyTerm = new core_kernel_rules_Term(INSTANCE_TERM_IS_NULL, __METHOD__);
             common_Logger::d('Empty Term Created', array('Generis Term evaluateSPX'));
             $property = new core_kernel_classes_Property(PROPERTY_TERM_VALUE);
             $returnValue = $newEmptyTerm->getUniquePropertyValue($property);
         } else {
             if ($returnValue->count() == 1) {
                 $returnValue = $returnValue->get(0);
             }
         }
     }
     return $returnValue;
 }
 /**
  * 
  * @author Lionel Lecaque, lionel@taotesting.com
  * @param core_kernel_classes_Resource $source
  * @param core_kernel_classes_Resource $destination
  * @param core_kernel_classes_Property $property
  */
 protected function cloneInstanceProperty(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination, core_kernel_classes_Property $property)
 {
     $range = $property->getRange();
     // Avoid doublons, the RDF TYPE property will be set by the implementation layer
     if ($property->getUri() != RDF_TYPE) {
         foreach ($source->getPropertyValuesCollection($property)->getIterator() as $propertyValue) {
             if (!is_null($range) && $range->getUri() == CLASS_GENERIS_FILE) {
                 $file = new core_kernel_versioning_File($propertyValue->getUri());
                 $newFile = $file->getRepository()->spawnFile($file->getAbsolutePath(), $file->getLabel());
                 $destination->setPropertyValue($property, $newFile);
             } else {
                 $destination->setPropertyValue($property, $propertyValue);
             }
         }
     }
 }
 /**
  * Short description of method getProcessVars
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource processDefinition
  * @return array
  */
 public function getProcessVars(core_kernel_classes_Resource $processDefinition)
 {
     $returnValue = array();
     $rangeProp = new core_kernel_classes_Property(RDFS_RANGE);
     $widgetProp = new core_kernel_classes_Property(PROPERTY_WIDGET);
     $variables = $processDefinition->getPropertyValuesCollection($this->processVariablesProp);
     $returnValue[RDFS_LABEL] = array('name' => "Name", 'widgets' => WIDGET_FTE, 'range' => RDFS_LITERAL);
     foreach ($variables->getIterator() as $variable) {
         $widgets = $variable->getPropertyValues($widgetProp);
         $label = $variable->getLabel();
         $range = $variable->getPropertyValues($rangeProp);
         $returnValue[$variable->getUri()] = array('name' => trim(strip_tags($label)), 'widgets' => $widgets, 'range' => $range);
     }
     return (array) $returnValue;
 }
 /**
  * Short description of method getServicesByActivity
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource activity
  * @return array
  */
 public function getServicesByActivity(core_kernel_classes_Resource $activity)
 {
     $returnValue = array();
     $services = $activity->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_INTERACTIVESERVICES));
     foreach ($services->getIterator() as $service) {
         if ($service instanceof core_kernel_classes_Resource) {
             $returnValue[$service->getUri()] = $service;
         }
     }
     return (array) $returnValue;
 }
 public static function nextActivityElements(core_kernel_classes_Resource $connector, $type, $allowCreation = true, $includeConnectors = true, $optionsWidget = 'Combobox')
 {
     $returnValue = array();
     $authorizedOptionsWidget = array('Combobox', 'Checkbox');
     if (!in_array($optionsWidget, $authorizedOptionsWidget)) {
         throw new Exception('Wrong type of widget');
         return $returnValue;
     }
     $idPrefix = '';
     $nextActivity = null;
     $propTransitionRule = new core_kernel_classes_Property(PROPERTY_CONNECTORS_TRANSITIONRULE);
     $propNextActivities = new core_kernel_classes_Property(PROPERTY_STEP_NEXT);
     //find the next activity if available
     switch (strtolower($type)) {
         case 'next':
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $activity) {
                 if ($activity instanceof core_kernel_classes_Resource) {
                     $nextActivity = $activity;
                     //we take the last one...(note: there should be only one though)
                 }
             }
             $idPrefix = 'next';
             break;
         case 'then':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_THEN))->getIterator() as $then) {
                         if ($then instanceof core_kernel_classes_Resource) {
                             $nextActivity = $then;
                         }
                     }
                 }
             }
             $idPrefix = 'then';
             break;
         case 'else':
             $transitionRuleCollection = $connector->getPropertyValuesCollection($propTransitionRule);
             foreach ($transitionRuleCollection->getIterator() as $transitionRule) {
                 if ($transitionRule instanceof core_kernel_classes_Resource) {
                     foreach ($transitionRule->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_TRANSITIONRULES_ELSE))->getIterator() as $else) {
                         if ($else instanceof core_kernel_classes_Resource) {
                             $nextActivity = $else;
                         }
                     }
                 }
             }
             $idPrefix = 'else';
             break;
         case 'parallel':
             $nextActivity = array();
             $nextActivityCollection = $connector->getPropertyValuesCollection($propNextActivities);
             foreach ($nextActivityCollection->getIterator() as $cardinality) {
                 if ($cardinality instanceof core_kernel_classes_Resource) {
                     $nextActivity[] = $cardinality;
                 }
             }
             $idPrefix = 'parallel';
             break;
         case 'join':
             // should only have one following activity
             $nextActivity = $connector->getOnePropertyValue($propNextActivities);
             $idPrefix = $type;
             break;
         default:
             throw new Exception("unknown type for the next activity");
     }
     $activityOptions = array();
     $connectorOptions = array();
     if ($allowCreation) {
         //create the activity label element (used only in case of new activity craetion)
         $elementActivityLabel = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityLabel", 'Textbox');
         $elementActivityLabel->setDescription(__('Label'));
         //add the "creating" option
         $activityOptions["newActivity"] = __("create new activity");
         $connectorOptions["newConnector"] = __("create new connector");
     }
     //the activity associated to the connector:
     $referencedActivity = $connector->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_CONNECTORS_ACTIVITYREFERENCE));
     //mandatory property value, initiated at the connector creation
     if ($referencedActivity instanceof core_kernel_classes_Resource) {
         $processDefClass = new core_kernel_classes_Class(CLASS_PROCESS);
         $processes = $processDefClass->searchInstances(array(PROPERTY_PROCESS_ACTIVITIES => $referencedActivity->getUri()), array('like' => false));
         if (count($processes) > 0) {
             $process = array_shift($processes);
             if (!empty($process)) {
                 //get list of activities and connectors for the current process:
                 $connectorClass = new core_kernel_classes_Class(CLASS_CONNECTORS);
                 $processAuthoringService = wfAuthoring_models_classes_ProcessService::singleton();
                 $activities = $processAuthoringService->getActivitiesByProcess($process);
                 foreach ($activities as $activityTemp) {
                     //include activities options:
                     $encodedUri = tao_helpers_Uri::encode($activityTemp->getUri());
                     $activityOptions[$encodedUri] = $activityTemp->getLabel();
                     if (strtolower($type) == 'parallel') {
                         $elementHidden = tao_helpers_form_FormFactory::getElement("{$encodedUri}_num_hidden", 'Hidden');
                         $returnValue[$idPrefix . '_' . $activityTemp->getUri()] = $elementHidden;
                     }
                     //include connectors options:
                     if ($includeConnectors) {
                         $connectors = $connectorClass->searchInstances(array(PROPERTY_CONNECTORS_ACTIVITYREFERENCE => $activityTemp->getUri()), array('like' => false));
                         foreach ($connectors as $connectorTemp) {
                             if ($connector->getUri() != $connectorTemp->getUri()) {
                                 $connectorOptions[tao_helpers_Uri::encode($connectorTemp->getUri())] = $connectorTemp->getLabel();
                             }
                         }
                     }
                 }
             }
         }
     }
     //create the description element
     $elementDescription = tao_helpers_form_FormFactory::getElement($idPrefix, 'Free');
     $elementDescription->setValue(strtoupper($type) . ' :');
     //create the activity select element:
     $elementActivities = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityUri", $optionsWidget);
     $elementActivities->setDescription(__('Activity'));
     $elementActivities->setOptions($activityOptions);
     $elementChoice = null;
     $elementConnectors = null;
     if ($includeConnectors) {
         //the default radio button to select between the 3 possibilities:
         $elementChoice = tao_helpers_form_FormFactory::getElement($idPrefix . "_activityOrConnector", 'Radiobox');
         $elementChoice->setDescription(__('Activity or Connector'));
         $options = array("activity" => __("Activity"), "connector" => __("Connector"));
         $elementChoice->setOptions($options);
         //create the connector select element:
         $elementConnectors = tao_helpers_form_FormFactory::getElement($idPrefix . "_connectorUri", $optionsWidget);
         $elementConnectors->setDescription(__('Connector'));
         $elementConnectors->setOptions($connectorOptions);
     }
     if (!empty($nextActivity)) {
         if (is_array($nextActivity) && $optionsWidget == 'Checkbox') {
             if (strtolower($type) == 'parallel') {
                 $cardinalityService = wfEngine_models_classes_ActivityCardinalityService::singleton();
                 foreach ($nextActivity as $cardinality) {
                     $activity = $cardinalityService->getDestination($cardinality);
                     $number = $cardinalityService->getCardinality($cardinality);
                     if (isset($returnValue[$idPrefix . '_' . $activity->getUri()])) {
                         $returnValue[$idPrefix . '_' . $activity->getUri()]->setValue($number instanceof core_kernel_classes_Resource ? tao_helpers_Uri::encode($number->getUri()) : intval($number));
                     }
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             } else {
                 foreach ($nextActivity as $activity) {
                     $elementActivities->setValue($activity->getUri());
                     //no need for tao_helpers_Uri::encode
                 }
             }
         } elseif ($nextActivity instanceof core_kernel_classes_Resource) {
             $aService = wfEngine_models_classes_ActivityService::singleton();
             if ($aService->isActivity($nextActivity)) {
                 if ($includeConnectors) {
                     $elementChoice->setValue("activity");
                 }
                 $elementActivities->setValue($nextActivity->getUri());
                 //no need for tao_helpers_Uri::encode
             }
             $conmectorService = wfEngine_models_classes_ConnectorService::singleton();
             if ($conmectorService->isConnector($nextActivity) && $includeConnectors) {
                 $elementChoice->setValue("connector");
                 $elementConnectors->setValue($nextActivity->getUri());
             }
         }
     }
     //put all elements in the return value:
     $returnValue[$idPrefix . '_description'] = $elementDescription;
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_choice'] = $elementChoice;
     }
     $returnValue[$idPrefix . '_activities'] = $elementActivities;
     if ($allowCreation) {
         $returnValue[$idPrefix . '_label'] = $elementActivityLabel;
     }
     if ($includeConnectors) {
         $returnValue[$idPrefix . '_connectors'] = $elementConnectors;
     }
     return $returnValue;
 }
 public function getItemByService(core_kernel_classes_Resource $service)
 {
     $returnValue = null;
     $propertyIterator = $service->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_ACTUALPARAMETERIN))->getIterator();
     foreach ($propertyIterator as $actualParam) {
         $formalParam = $actualParam->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_FORMALPARAMETER));
         if ($formalParam->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_NAME)) == 'itemUri') {
             $returnValue = $actualParam->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_ACTUALPARAMETER_CONSTANTVALUE));
             break;
         }
     }
     return $returnValue;
 }
Beispiel #11
0
 /**
  * Get the roles that a given user has.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Resource user A Generis User.
  * @return array
  */
 public function getUserRoles(core_kernel_classes_Resource $user)
 {
     $returnValue = array();
     // We use a Depth First Search approach to flatten the Roles Graph.
     $rolesProperty = new core_kernel_classes_Property(PROPERTY_USER_ROLES);
     $rootRoles = $user->getPropertyValuesCollection($rolesProperty);
     foreach ($rootRoles->getIterator() as $r) {
         $returnValue[$r->getUri()] = $r;
         $returnValue = array_merge($returnValue, $this->getIncludedRoles($r));
     }
     $returnValue = array_unique($returnValue);
     return (array) $returnValue;
 }