use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.
the class ShadowManager method getNormalizedValue.
private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException {
RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName());
QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName();
MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName());
List<PrismPropertyValue<T>> normalized = new ArrayList<>();
for (PrismPropertyValue<T> origPValue : attr.getValues()) {
T normalizedValue = matchingRule.normalize(origPValue.getValue());
PrismPropertyValue<T> normalizedPValue = origPValue.clone();
normalizedPValue.setValue(normalizedValue);
normalized.add(normalizedPValue);
}
return normalized;
}
use of com.evolveum.midpoint.prism.PrismPropertyValue 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.PrismPropertyValue 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;
}
use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.
the class WorkItemProvider method createTaskQuery.
// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
List<ObjectFilter> remainingClauses = components.getRemainderClauses();
if (!remainingClauses.isEmpty()) {
throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
}
final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
if (workItemIdFilter != null) {
Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
if (filterValues.size() > 1) {
throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
}
taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
}
if (assigneeFilter != null) {
taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
}
if (candidateRolesFilter != null) {
// TODO what about candidate users? (currently these are not supported)
List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
if (!candidateGroups.isEmpty()) {
taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
} else {
// no groups -> no result
return null;
}
}
if (query != null && query.getPaging() != null) {
ObjectPaging paging = query.getPaging();
if (paging.getOrderingInstructions().size() > 1) {
throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
} else if (paging.getOrderingInstructions().size() == 1) {
ItemPath orderBy = paging.getOrderBy();
if (CREATED_PATH.equivalent(orderBy)) {
taskQuery = taskQuery.orderByTaskCreateTime();
} else {
throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
}
switch(paging.getDirection()) {
case DESCENDING:
taskQuery = taskQuery.desc();
break;
case ASCENDING:
default:
taskQuery = taskQuery.asc();
break;
}
}
}
if (includeVariables) {
return taskQuery.includeTaskLocalVariables().includeProcessVariables();
} else {
return taskQuery;
}
}
use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.
the class EntitlementConverter method createQuery.
// precondition: valueAttr has exactly one value
private <TV, TA> ObjectQuery createQuery(RefinedAssociationDefinition assocDefType, RefinedAttributeDefinition<TA> assocAttrDef, ResourceAttribute<TV> valueAttr) throws SchemaException {
MatchingRule<TA> matchingRule = matchingRuleRegistry.getMatchingRule(assocDefType.getResourceObjectAssociationType().getMatchingRule(), assocAttrDef.getTypeName());
PrismPropertyValue<TA> converted = PrismUtil.convertPropertyValue(valueAttr.getValue(0), valueAttr.getDefinition(), assocAttrDef);
TA normalizedRealValue = matchingRule.normalize(converted.getValue());
PrismPropertyValue<TA> normalized = new PrismPropertyValue<TA>(normalizedRealValue);
LOGGER.trace("Converted entitlement filter value: {} ({}) def={}", normalized, normalized.getValue().getClass(), assocAttrDef);
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).item(new ItemPath(ShadowType.F_ATTRIBUTES, assocAttrDef.getName()), assocAttrDef).eq(normalized).build();
query.setAllowPartialResults(true);
return query;
}
Aggregations