use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class TestModelExpressions method executeScriptExpressionString.
private String executeScriptExpressionString(final String TEST_NAME, ExpressionVariables variables) throws SchemaException, IOException, JAXBException, ExpressionEvaluationException, ObjectNotFoundException {
// GIVEN
OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);
ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
if (variables == null) {
variables = new ExpressionVariables();
}
// WHEN
TestUtil.displayWhen(TEST_NAME);
List<PrismPropertyValue<String>> scriptOutputs = evaluate(scriptExpression, variables, false, TEST_NAME, null, result);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Script output", scriptOutputs);
result.computeStatus();
TestUtil.assertSuccess(result);
if (scriptOutputs.size() == 0) {
return null;
}
assertEquals("Unexpected number of script outputs", 1, scriptOutputs.size());
return scriptOutputs.get(0).getValue();
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class CustomNotifier method evaluateExpression.
private List<NotificationMessageType> evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<NotificationMessageType> resultDef = new PrismPropertyDefinitionImpl<>(resultName, NotificationMessageType.COMPLEX_TYPE, prismContext);
Expression<PrismPropertyValue<NotificationMessageType>, PrismPropertyDefinition<NotificationMessageType>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<NotificationMessageType>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
return exprResult.getZeroSet().stream().map(PrismPropertyValue::getValue).collect(Collectors.toList());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class SchemaProcessorTest method testRoundTripGeneric.
@Test
public void testRoundTripGeneric() throws SchemaException {
// GIVEN
PrismSchemaImpl schema = new PrismSchemaImpl(SCHEMA_NS, PrismTestUtil.getPrismContext());
// Ordinary property
schema.createPropertyDefinition("number1", DOMUtil.XSD_INT);
// Property container
PrismContainerDefinitionImpl containerDefinition = schema.createPropertyContainerDefinition("ContainerType");
// ... in it ordinary property
containerDefinition.createPropertyDefinition("login", DOMUtil.XSD_STRING);
// ... and local property with a type from another schema
containerDefinition.createPropertyDefinition("password", ProtectedStringType.COMPLEX_TYPE);
// ... property reference
containerDefinition.createPropertyDefinition(SchemaConstants.C_CREDENTIALS, CredentialsType.COMPLEX_TYPE);
// ... read-only int property
PrismPropertyDefinition counterProperty = containerDefinition.createPropertyDefinition("counter", DOMUtil.XSD_INT);
((PrismPropertyDefinitionImpl) counterProperty).setReadOnly();
System.out.println("Generic schema before serializing to XSD: ");
System.out.println(schema.debugDump());
System.out.println();
// WHEN
Document xsd = schema.serializeToXsd();
String stringXmlSchema = DOMUtil.serializeDOMToString(xsd);
System.out.println("Generic schema after serializing to XSD: ");
System.out.println(stringXmlSchema);
System.out.println();
Document parsedXsd = DOMUtil.parseDocument(stringXmlSchema);
PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext());
System.out.println("Generic schema after parsing from XSD: ");
System.out.println(newSchema.debugDump());
System.out.println();
// THEN
PrismPropertyDefinition number1def = newSchema.findItemDefinitionByElementName(new QName(SCHEMA_NS, "number1"), PrismPropertyDefinition.class);
assertEquals(new QName(SCHEMA_NS, "number1"), number1def.getName());
assertEquals(DOMUtil.XSD_INT, number1def.getTypeName());
PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new QName(SCHEMA_NS, "ContainerType"));
assertEquals(new QName(SCHEMA_NS, "ContainerType"), newContainerDef.getTypeName());
PrismPropertyDefinition loginDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "login"));
assertEquals(new QName(SCHEMA_NS, "login"), loginDef.getName());
assertEquals(DOMUtil.XSD_STRING, loginDef.getTypeName());
assertTrue("Read flag is wrong", loginDef.canRead());
assertTrue("Create flag is wrong", loginDef.canAdd());
assertTrue("Update flag is wrong", loginDef.canModify());
PrismPropertyDefinition passwdDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "password"));
assertEquals(new QName(SCHEMA_NS, "password"), passwdDef.getName());
assertEquals(ProtectedStringType.COMPLEX_TYPE, passwdDef.getTypeName());
PrismPropertyDefinition credDef = newContainerDef.findPropertyDefinition(new QName(SchemaConstants.NS_C, "credentials"));
assertEquals(new QName(SchemaConstants.NS_C, "credentials"), credDef.getName());
assertEquals(new QName(SchemaConstants.NS_C, "CredentialsType"), credDef.getTypeName());
PrismPropertyDefinition countDef = newContainerDef.findPropertyDefinition(new QName(SCHEMA_NS, "counter"));
assertEquals(new QName(SCHEMA_NS, "counter"), countDef.getName());
assertEquals(DOMUtil.XSD_INT, countDef.getTypeName());
assertTrue("Read flag is wrong", countDef.canRead());
assertFalse("Create flag is wrong", countDef.canAdd());
assertFalse("Update flag is wrong", countDef.canModify());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class ExpressionHandler method evaluateConfirmationExpression.
public boolean evaluateConfirmationExpression(UserType user, ShadowType shadow, ExpressionType expressionType, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
Validate.notNull(user, "User must not be null.");
Validate.notNull(shadow, "Resource object shadow must not be null.");
Validate.notNull(expressionType, "Expression must not be null.");
Validate.notNull(result, "Operation result must not be null.");
ResourceType resource = resolveResource(shadow, result);
ExpressionVariables variables = getDefaultXPathVariables(user, shadow, resource);
String shortDesc = "confirmation expression for " + resource.asPrismObject();
PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues();
if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
throw new ExpressionEvaluationException("Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
}
if (nonNegativeValues.size() > 1) {
throw new ExpressionEvaluationException("Expression returned more than one value (" + nonNegativeValues.size() + ") in " + shortDesc);
}
PrismPropertyValue<Boolean> resultpval = nonNegativeValues.iterator().next();
if (resultpval == null) {
throw new ExpressionEvaluationException("Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
}
Boolean resultVal = resultpval.getValue();
if (resultVal == null) {
throw new ExpressionEvaluationException("Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
}
return resultVal;
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class ExpressionHandler method evaluateExpression.
public String evaluateExpression(ShadowType shadow, ExpressionType expressionType, String shortDesc, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
Validate.notNull(shadow, "Resource object shadow must not be null.");
Validate.notNull(expressionType, "Expression must not be null.");
Validate.notNull(result, "Operation result must not be null.");
ResourceType resource = resolveResource(shadow, result);
ExpressionVariables variables = getDefaultXPathVariables(null, shadow, resource);
PrismPropertyDefinition<String> outputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_STRING, prismContext);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
if (outputTriple == null) {
return null;
}
Collection<PrismPropertyValue<String>> nonNegativeValues = outputTriple.getNonNegativeValues();
if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
return null;
}
if (nonNegativeValues.size() > 1) {
throw new ExpressionEvaluationException("Expression returned more than one value (" + nonNegativeValues.size() + ") in " + shortDesc);
}
return nonNegativeValues.iterator().next().getValue();
}
Aggregations