use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class TestModelExpressions method testGetManagersOids.
@Test
public void testGetManagersOids() throws Exception {
final String TEST_NAME = "testGetManagersOids";
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<String> outputDefinition = new PrismPropertyDefinitionImpl<>(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "user"), chef);
// WHEN
List<PrismPropertyValue<String>> scriptOutputs = evaluate(scriptExpression, variables, false, TEST_NAME, null, result);
// THEN
display("Script output", scriptOutputs);
assertEquals("Unexpected number of script outputs", 3, scriptOutputs.size());
Set<String> oids = new HashSet<String>();
oids.add(scriptOutputs.get(0).getValue());
oids.add(scriptOutputs.get(1).getValue());
oids.add(scriptOutputs.get(2).getValue());
Set<String> expectedOids = new HashSet<String>(Arrays.asList(new String[] { CHEESE_OID, CHEESE_JR_OID, LECHUCK_OID }));
assertEquals("Unexpected script output", expectedOids, oids);
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class TestObjectQuery method testMatchEqualMultivalue.
@Test
public void testMatchEqualMultivalue() throws Exception {
PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML);
PrismPropertyDefinitionImpl def = new PrismPropertyDefinitionImpl(new QName("indexedString"), DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ObjectFilter filter = QueryBuilder.queryFor(UserType.class, PrismTestUtil.getPrismContext()).item(new ItemPath(UserType.F_EXTENSION, "indexedString"), def).eq("alpha").buildFilter();
boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry);
AssertJUnit.assertTrue("filter does not match object", match);
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class RunReportPopupPanel method runConfirmPerformed.
// private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
// Component c = parent.get(id);
// if (c == null) {
// return;
// }
// c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// }
private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model) {
ReportDto reportDto = model.getObject();
PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
PrismContainer<ReportParameterType> paramContainer;
try {
paramContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
paramContainer.add(reportParamValue);
List<JasperReportParameterDto> params = getParametersView().getModelObject();
for (JasperReportParameterDto paramDto : params) {
if (paramDto.getValue() == null) {
continue;
}
List<JasperReportValueDto> values = paramDto.getValue();
Class<?> paramClass = paramDto.getType();
boolean multivalue = false;
if (List.class.isAssignableFrom(paramClass)) {
paramClass = paramDto.getNestedType();
if (paramClass == null) {
getSession().error("Nested type for list must be defined!");
target.add(getPageBase().getFeedbackPanel());
return;
}
}
QName typeName = getPrismContext().getSchemaRegistry().determineTypeForClass(paramClass);
PrismPropertyDefinitionImpl<?> def = new PrismPropertyDefinitionImpl<>(new QName(ReportConstants.NS_EXTENSION, paramDto.getName()), typeName, getPrismContext());
def.setDynamic(true);
def.setRuntimeSchema(true);
// TODO multivalue is always 'false' here ...
def.setMaxOccurs(multivalue ? -1 : 1);
PrismProperty prop = def.instantiate();
for (JasperReportValueDto paramValue : values) {
Object realValue = paramValue.getValue();
if (realValue == null) {
continue;
}
if (AuditEventType.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventTypeType.class;
realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
} else if (AuditEventStage.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventStageType.class;
realValue = AuditEventStage.fromAuditEventStage((AuditEventStage) realValue);
}
prop.addRealValue(realValue);
}
if (!prop.isEmpty()) {
reportParamValue.add(prop);
}
}
} catch (SchemaException | ClassNotFoundException e) {
OperationResult result = new OperationResult("Parameters serialization");
result.recordFatalError("Could not serialize parameters");
getPageBase().showResult(result);
return;
}
runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class WfExpressionEvaluationHelper method evaluateExpression.
@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, ExpressionVariables variables, String contextDescription, Class<T> clazz, QName typeName, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
ExpressionFactory expressionFactory = getExpressionFactory();
PrismContext prismContext = expressionFactory.getPrismContext();
PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl<>(new QName(SchemaConstants.NS_C, "result"), typeName, prismContext);
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, contextDescription, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task, result);
context.setAdditionalConvertor(additionalConvertor);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, context, task, result);
return exprResultTriple.getZeroSet().stream().map(ppv -> (T) ppv.getRealValue()).collect(Collectors.toList());
}
use of com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl in project midpoint by Evolveum.
the class GcpExpressionHelper method evaluateBooleanExpression.
private boolean evaluateBooleanExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String opContext, Task taskFromModel, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
PrismContext prismContext = expressionFactory.getPrismContext();
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, opContext, taskFromModel, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, opContext, taskFromModel, result);
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, taskFromModel, result);
Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
if (exprResult.size() == 0) {
return false;
} else if (exprResult.size() > 1) {
throw new IllegalStateException("Expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
}
Boolean boolResult = exprResult.iterator().next().getValue();
return boolResult != null ? boolResult : false;
}
Aggregations