use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class BaseHandler method evaluateExpression.
private List<String> evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl<>(resultName, DOMUtil.XSD_STRING, prismContext);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
List<String> retval = new ArrayList<>();
for (PrismPropertyValue<String> item : exprResult.getZeroSet()) {
retval.add(item.getValue());
}
return retval;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class BaseHelper method evaluateExpression.
private List<String> evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_STRING, prismContext);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult;
exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
List<String> retval = new ArrayList<String>();
for (PrismPropertyValue<String> item : exprResult.getZeroSet()) {
retval.add(item.getValue());
}
return retval;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class BaseHelper method evaluateBooleanExpression.
protected boolean evaluateBooleanExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
if (exprResult.size() == 0) {
return false;
} else if (exprResult.size() > 1) {
throw new IllegalStateException("Filter expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
}
Boolean boolResult = exprResult.iterator().next().getValue();
return boolResult != null ? boolResult : false;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class TestMappingTime method testSetReferenceTimeAfter.
@Test
public void testSetReferenceTimeAfter() throws Exception {
final String TEST_NAME = "testSetReferenceTimeAfter";
System.out.println("===[ " + TEST_NAME + "]===");
// GIVEN
PrismObject<UserType> userOld = evaluator.getUserOld();
XMLGregorianCalendar disableTimestamp = userOld.asObjectable().getActivation().getDisableTimestamp();
userOld.asObjectable().getActivation().setDisableTimestamp(null);
ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_DISABLE_TIMESTAMP), evaluator.getPrismContext(), disableTimestamp);
Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", delta, userOld);
builder.setNow(TIME_FUTURE);
PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
builder.setDefaultTargetDefinition(existenceDef);
Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
OperationResult opResult = new OperationResult(TEST_NAME);
// WHEN
mapping.evaluate(null, opResult);
// THEN
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
PrismAsserts.assertTripleZero(outputTriple, false);
PrismAsserts.assertTripleNoPlus(outputTriple);
PrismAsserts.assertTripleNoMinus(outputTriple);
assertNextRecompute(mapping, null);
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class TestModelExpressions method testIsUniquePropertyValue.
/**
* MID-2887
*/
@Test
public void testIsUniquePropertyValue() throws Exception {
final String TEST_NAME = "testIsUniquePropertyValue";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);
PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);
ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<>(PROPERTY_NAME, DOMUtil.XSD_BOOLEAN, PrismTestUtil.getPrismContext());
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "user"), chef);
variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "value"), "Scumm Bar Chef");
// WHEN
List<PrismPropertyValue<Boolean>> scriptOutputs = evaluate(scriptExpression, variables, false, TEST_NAME, null, result);
// THEN
display("Script output", scriptOutputs);
assertEquals("Unexpected number of script outputs", 1, scriptOutputs.size());
Boolean scriptOutput = scriptOutputs.get(0).getValue();
assertEquals("Unexpected script output", Boolean.TRUE, scriptOutput);
}
Aggregations