use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class ResourceObjectReferenceResolver method fetchResourceObject.
public PrismObject<ShadowType> fetchResourceObject(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, AttributesToReturn attributesToReturn, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
ResourceType resource = ctx.getResource();
ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
try {
if (!ResourceTypeUtil.isReadCapabilityEnabled(resource)) {
throw new UnsupportedOperationException("Resource does not support 'read' operation");
}
ResourceObjectIdentification identification = ResourceObjectIdentification.create(objectClassDefinition, identifiers);
identification = resolvePrimaryIdentifiers(ctx, identification, parentResult);
identification.validatePrimaryIdenfiers();
return connector.fetchObject(ShadowType.class, identification, attributesToReturn, ctx, parentResult);
} catch (ObjectNotFoundException e) {
parentResult.recordFatalError("Object not found. Identifiers: " + identifiers + ". Reason: " + e.getMessage(), e);
throw new ObjectNotFoundException("Object not found. identifiers=" + identifiers + ", objectclass=" + PrettyPrinter.prettyPrint(objectClassDefinition.getTypeName()) + ": " + e.getMessage(), e);
} catch (CommunicationException e) {
parentResult.recordFatalError("Error communication with the connector " + connector + ": " + e.getMessage(), e);
throw e;
} catch (GenericFrameworkException e) {
parentResult.recordFatalError("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
throw new GenericConnectorException("Generic error in the connector " + connector + ". Reason: " + e.getMessage(), e);
} catch (SchemaException ex) {
parentResult.recordFatalError("Can't get resource object, schema error: " + ex.getMessage(), ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
parentResult.recordFatalError("Can't get resource object, expression error: " + ex.getMessage(), ex);
throw ex;
} catch (ConfigurationException e) {
parentResult.recordFatalError(e);
throw e;
}
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertAllowRequestItems.
protected void assertAllowRequestItems(String userOid, String targetRoleOid, AuthorizationDecisionType expectedDefaultDecision, QName... expectedAllowedItemQNames) throws SchemaException, SecurityViolationException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
PrismObject<UserType> user = getUser(userOid);
PrismObject<RoleType> target = getRole(targetRoleOid);
ItemSecurityDecisions decisions = modelInteractionService.getAllowedRequestAssignmentItems(user, target);
display("Request decisions for " + target, decisions);
assertEquals("Wrong assign default decision", expectedDefaultDecision, decisions.getDefaultDecision());
assertEquals("Unexpected number of allowed items", expectedAllowedItemQNames.length, decisions.getItemDecisionMap().size());
decisions.getItemDecisionMap().forEach((path, decision) -> {
assertEquals("wrong item " + path + " decision", AuthorizationDecisionType.ALLOW, decision);
QName lastPathName = path.lastNamed().getName();
if (!Arrays.stream(expectedAllowedItemQNames).anyMatch(qname -> QNameUtil.match(qname, lastPathName))) {
AssertJUnit.fail("Unexpected path " + path);
}
});
}
use of com.evolveum.midpoint.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class PrimaryChangeAspectHelper method evaluateApplicabilityCondition.
//endregion
//region ========================================================================== Expression evaluation
public boolean evaluateApplicabilityCondition(PcpAspectConfigurationType config, ModelContext modelContext, Serializable itemToApprove, ExpressionVariables additionalVariables, PrimaryChangeAspect aspect, Task task, OperationResult result) {
if (config == null || config.getApplicabilityCondition() == null) {
return true;
}
ExpressionType expressionType = config.getApplicabilityCondition();
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
ExpressionVariables expressionVariables = new ExpressionVariables();
expressionVariables.addVariableDefinition(SchemaConstants.C_MODEL_CONTEXT, modelContext);
expressionVariables.addVariableDefinition(SchemaConstants.C_ITEM_TO_APPROVE, itemToApprove);
if (additionalVariables != null) {
expressionVariables.addVariableDefinitions(additionalVariables);
}
PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple;
try {
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, "applicability condition expression", task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, "applicability condition expression", task, result);
exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | RuntimeException e) {
// TODO report as a specific exception?
throw new SystemException("Couldn't evaluate applicability condition in aspect " + aspect.getClass().getSimpleName() + ": " + e.getMessage(), e);
}
Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
if (exprResult.size() == 0) {
return false;
} else if (exprResult.size() > 1) {
throw new IllegalStateException("Applicability condition 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.util.exception.ExpressionEvaluationException 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.util.exception.ExpressionEvaluationException in project midpoint by Evolveum.
the class ApprovalSchemaHelper method prepareStage.
public void prepareStage(ApprovalStageDefinitionType stageDef, RelationResolver relationResolver, ReferenceResolver referenceResolver) {
try {
// resolves filters in approvers
List<ObjectReferenceType> resolvedApprovers = new ArrayList<>();
for (ObjectReferenceType ref : stageDef.getApproverRef()) {
resolvedApprovers.addAll(referenceResolver.resolveReference(ref, "approver ref"));
}
// resolves approver relations
resolvedApprovers.addAll(relationResolver.getApprovers(stageDef.getApproverRelation()));
stageDef.getApproverRef().clear();
stageDef.getApproverRef().addAll(resolvedApprovers);
stageDef.getApproverRelation().clear();
// default values
if (stageDef.getOutcomeIfNoApprovers() == null) {
stageDef.setOutcomeIfNoApprovers(ApprovalLevelOutcomeType.REJECT);
}
if (stageDef.getGroupExpansion() == null) {
stageDef.setGroupExpansion(GroupExpansionType.BY_CLAIMING_WORK_ITEMS);
}
} catch (ExpressionEvaluationException | ObjectNotFoundException | SchemaException e) {
// todo propagate these exceptions?
throw new SystemException("Couldn't prepare approval schema for execution: " + e.getMessage(), e);
}
}
Aggregations