/** * Short description of method createSPX * * @access public * @author firstname and lastname of author, <*****@*****.**> * @param Resource $subject * @param Property $predicate * @return core_kernel_rules_Term */ public static function createSPX(core_kernel_classes_Resource $subject, core_kernel_classes_Property $predicate) { $returnValue = null; $termSPXClass = new core_kernel_classes_Class(CLASS_TERM_SUJET_PREDICATE_X, __METHOD__); $label = 'Def Term SPX Label : ' . $subject->getLabel() . ' - ' . $predicate->getLabel(); $comment = 'Def Term SPX Label : ' . $subject->getUri() . ' ' . $predicate->getUri(); $SPXResource = core_kernel_classes_ResourceFactory::create($termSPXClass, $label, $comment); $returnValue = new core_kernel_rules_Term($SPXResource->getUri()); $subjectProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_SUBJET, __METHOD__); $predicateProperty = new core_kernel_classes_Property(PROPERTY_TERM_SPX_PREDICATE, __METHOD__); $returnValue->setPropertyValue($subjectProperty, $subject->getUri()); $returnValue->setPropertyValue($predicateProperty, $predicate->getUri()); return $returnValue; }
/** * Short description of method createOperation * * @access public * @author firstname and lastname of author, <*****@*****.**> * @param Term term1 * @param Term term2 * @param Resource operator * @return core_kernel_rules_Operation */ public static function createOperation(core_kernel_rules_Term $term1, core_kernel_rules_Term $term2, core_kernel_classes_Resource $operator) { $returnValue = null; $operationClass = new core_kernel_classes_Class(CLASS_OPERATION, __METHOD__); $label = 'Def Operation Label ' . $term1->getLabel() . ' ' . $operator->getLabel() . ' ' . $term2->getLabel(); $comment = 'Def Operation Comment ' . $term1->getUri() . ' ' . $operator->getUri() . ' ' . $term2->getUri(); $operatorProperty = new core_kernel_classes_Property(PROPERTY_OPERATION_OPERATOR, __METHOD__); $firstOperand = new core_kernel_classes_Property(PROPERTY_OPERATION_FIRST_OP, __METHOD__); $secondOperand = new core_kernel_classes_Property(PROPERTY_OPERATION_SECND_OP, __METHOD__); $termOperationInstance = core_kernel_classes_ResourceFactory::create($operationClass, $label, $comment); $returnValue = new core_kernel_rules_Operation($termOperationInstance->getUri()); $returnValue->debug = __METHOD__; $returnValue->setPropertyValue($operatorProperty, $operator->getUri()); $returnValue->setPropertyValue($firstOperand, $term1->getUri()); $returnValue->setPropertyValue($secondOperand, $term2->getUri()); return $returnValue; }
public function testEvaluate() { //bad term $badTermResource = core_kernel_classes_ResourceFactory::create(new core_kernel_classes_Class(CLASS_TERM), 'bad term', __METHOD__); $badTerm = new core_kernel_rules_Term($badTermResource->getUri()); try { $badTerm->evaluate(); $this->fail('should raise exception : Forbidden type'); } catch (common_Exception $e) { $this->assertEquals($e->getMessage(), 'Forbidden Type of Term'); } // eval const $constantResource = core_kernel_rules_TermFactory::createConst('test1'); $term = $constantResource->evaluate(); $this->assertIsA($term, 'core_kernel_classes_Literal'); $this->assertEquals($term, 'test1'); $constantResource->delete(); //eval SPX $booleanClass = new core_kernel_classes_Class(GENERIS_BOOLEAN); $maybe = core_kernel_classes_ResourceFactory::create($booleanClass, 'testCase testCreateSPX', __METHOD__); $SPXResource = core_kernel_rules_TermFactory::createSPX($maybe, new core_kernel_classes_Property(RDFS_COMMENT)); $spxResult = $SPXResource->evaluate(); $this->assertIsA($spxResult, 'core_kernel_classes_Literal'); $this->assertEquals($spxResult, __METHOD__); // eval operation $constant5 = core_kernel_rules_TermFactory::createConst('5'); $constant12 = core_kernel_rules_TermFactory::createConst('12'); $operation = core_kernel_rules_OperationFactory::createOperation($constant5, $constant12, new core_kernel_classes_Resource(INSTANCE_OPERATOR_ADD)); $operationTerm = new core_kernel_rules_Term($operation->getUri()); $result = $operationTerm->evaluate(); $this->assertEquals($result->literal, '17'); $fakeTerm = new core_kernel_rules_Term($maybe->getUri()); try { $fakeTerm->evaluate(); $this->fail('should raise exception : Forbidden type'); } catch (common_Exception $e) { $this->assertEquals($e->getMessage(), 'problem evaluating Term'); } $badTermResource->delete(); $constant5->delete(); $constant12->delete(); $SPXResource->delete(); $operation->delete(); $maybe->delete(); }
/** * Short description of method evaluateSet * * @access protected * @author firstname and lastname of author, <*****@*****.**> * @return mixed */ protected function evaluateSet() { common_Logger::d('Constructed Set TYPE', array('Generis Term evaluateSet')); $operator = $this->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_SET_OPERATOR)); $subSets = $this->getPropertyValuesCollection(new core_kernel_classes_Property(PROPERTY_SUBSET)); $returnValue = new core_kernel_classes_ContainerCollection($this); foreach ($subSets->getIterator() as $aSet) { if ($aSet instanceof core_kernel_classes_Resource) { $newSet = new core_kernel_rules_Term($aSet->getUri()); $resultSet = $newSet->evaluate(); if ($resultSet instanceof core_kernel_classes_ContainerCollection) { $returnValue = $this->evalutateSetOperation($operator, $returnValue, $resultSet); } else { $collection = new core_kernel_classes_ContainerCollection($this); $collection->add($resultSet); $returnValue = $this->evalutateSetOperation($operator, $returnValue, $collection); } } else { throw new common_Exception('Bad Type , waiting for a Resource '); } } return $returnValue; }
/** * Short description of method createNotification * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource connector * @param Resource user * @param Resource activityExecution * @param Resource processExecution * @return core_kernel_classes_Resource */ public function createNotification(core_kernel_classes_Resource $connector, core_kernel_classes_Resource $user, core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $processExecution = null) { $returnValue = null; $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton(); if (is_null($processExecution)) { $processExecution = $activityExecutionService->getRelatedProcessExecution($activityExecution); } $notification = $this->notificationClass->createInstance(); $notification->setPropertyValue($this->notificationToProp, $user); $notification->setPropertyValue($this->notificationProcessExecProp, $processExecution); $notification->setPropertyValue($this->notificationConnectorProp, $connector); $notification->setPropertyValue($this->notificationSentProp, GENERIS_FALSE); $notification->setPropertyValue($this->notificationDateProp, date("Y-m-d H:i:s")); //get the message content from the connector $content = (string) $connector->getOnePropertyValue($this->connectorNotificationProp); if (strlen(trim($content)) > 0) { $matches = array(); $expr = "/{{((http|https|file|ftp):\\/\\/[\\/.A-Za-z0-9_-]+#[A-Za-z0-9]+)}}/"; if (preg_match_all($expr, $content, $matches)) { if (isset($matches[1])) { $termUris = $matches[1]; $activity = $activityExecutionService->getExecutionOf($activityExecution); foreach ($termUris as $termUri) { $term = new core_kernel_rules_Term($termUri); $replacement = $term->evaluate(array(VAR_PROCESS_INSTANCE => $processExecution->getUri(), VAR_ACTIVITY_INSTANCE => $activityExecution->getUri(), VAR_ACTIVITY_DEFINITION => $activity->getUri(), VAR_CURRENT_USER => $user->getUri())); if ($replacement instanceof core_kernel_classes_Resource && $replacement->getUri() == INSTANCE_TERM_IS_NULL) { $replacement = ''; } $content = str_replace('{{' . $termUri . '}}', $replacement, $content); } } } } if (empty($content)) { throw new common_Exception('empty notification message'); } $notification->setPropertyValue($this->notificationMessageProp, $content); $returnValue = $notification; return $returnValue; }