use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class QueryConvertor method parseRefFilter.
private static <C extends Containerable> RefFilter parseRefFilter(MapXNode clauseXMap, PrismContainerDefinition<C> pcd, boolean preliminaryParsingOnly, PrismContext prismContext) throws SchemaException {
ItemPath itemPath = getPath(clauseXMap);
if (itemPath == null || itemPath.isEmpty()) {
throw new SchemaException("Cannot convert query, because query does not contain property path.");
}
QName itemName = ItemPath.getName(itemPath.last());
ItemDefinition itemDefinition = null;
if (pcd != null) {
itemDefinition = pcd.findItemDefinition(itemPath);
if (itemDefinition == null && !preliminaryParsingOnly) {
throw new SchemaException("No definition for item " + itemPath + " in " + pcd);
}
}
XNode valueXnode = clauseXMap.get(ELEMENT_VALUE);
if (valueXnode != null) {
if (preliminaryParsingOnly) {
return null;
}
RootXNode valueRoot = new RootXNode(ELEMENT_VALUE, valueXnode);
Item<?, ?> item = prismContext.parserFor(valueRoot).name(itemName).definition(itemDefinition).context(ParsingContext.allowMissingRefTypes()).parseItem();
if (!(item instanceof PrismReference)) {
throw new IllegalStateException("Expected PrismReference, got " + item);
}
PrismReference ref = (PrismReference) item;
if (item.getValues().size() < 1) {
throw new IllegalStateException("No values to search specified for item " + itemName);
}
return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, PrismValue.cloneCollection(ref.getValues()));
} else {
ExpressionWrapper expressionWrapper = parseExpression(clauseXMap, prismContext);
if (expressionWrapper != null) {
if (preliminaryParsingOnly) {
return null;
} else {
return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, expressionWrapper);
}
} else {
if (preliminaryParsingOnly) {
return null;
} else {
return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, (ExpressionWrapper) null);
}
}
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class QueryConvertor method serializeFullTextFilter.
private static MapXNode serializeFullTextFilter(FullTextFilter filter, PrismSerializer<RootXNode> xnodeSerializer) throws SchemaException {
MapXNode clauseMap = new MapXNode();
if (filter.getValues() != null && !filter.getValues().isEmpty()) {
ListXNode valuesNode = new ListXNode();
for (String value : filter.getValues()) {
XNode val = createPrimitiveXNode(value, DOMUtil.XSD_STRING);
valuesNode.add(val);
}
clauseMap.put(ELEMENT_VALUE, valuesNode);
} else if (filter.getExpression() != null) {
// TODO serialize expression
} else {
throw new SchemaException("FullText filter with no values nor expression");
}
return createFilter(CLAUSE_FULL_TEXT, clauseMap);
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class AssignmentEvaluator method resolveTargetsFromFilter.
@NotNull
private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> targetClass, SearchFilterType filter, AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(lensContext, null, ctx.task, ctx.result));
try {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(ctx.result);
ExpressionVariables variables = Utils.getDefaultExpressionVariables(segment.source, null, null, systemConfiguration.asObjectable());
variables.addVariableDefinition(ExpressionConstants.VAR_SOURCE, segment.getOrderOneObject());
AssignmentPathVariables assignmentPathVariables = LensUtil.computeAssignmentPathVariables(ctx.assignmentPath);
if (assignmentPathVariables != null) {
Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
}
ObjectFilter origFilter = QueryConvertor.parseFilter(filter, targetClass, prismContext);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), prismContext, " evaluating resource filter expression ", ctx.task, ctx.result);
if (evaluatedFilter == null) {
throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + segment.source);
}
return repository.searchObjects(targetClass, ObjectQuery.createObjectQuery(evaluatedFilter), null, ctx.result);
// we don't check for no targets here; as we don't care for referential integrity
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class PersonaProcessor method readExistingPersonas.
public <F extends FocusType> List<FocusType> readExistingPersonas(LensContext<F> context, Task task, OperationResult result) {
LensFocusContext<F> focusContext = context.getFocusContext();
PrismObject<F> focus = focusContext.getObjectNew();
List<FocusType> personas = new ArrayList<>();
String desc = "personaRef in " + focus;
for (ObjectReferenceType personaRef : focus.asObjectable().getPersonaRef()) {
try {
FocusType persona = objectResolver.resolve(personaRef, FocusType.class, null, desc, task, result);
personas.add(persona);
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.warn("Cannot find persona {} referenced from {}", personaRef.getOid(), focus);
// But go on...
}
}
return personas;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class AssignmentProcessor method evaluateConstructions.
private <F extends FocusType> void evaluateConstructions(LensContext<F> context, Collection<EvaluatedAssignmentImpl<F>> evaluatedAssignments, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
if (evaluatedAssignments == null) {
return;
}
ObjectDeltaObject<F> focusOdo = null;
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
focusOdo = focusContext.getObjectDeltaObject();
}
Iterator<EvaluatedAssignmentImpl<F>> iterator = evaluatedAssignments.iterator();
while (iterator.hasNext()) {
EvaluatedAssignmentImpl<F> evaluatedAssignment = iterator.next();
try {
evaluatedAssignment.evaluateConstructions(focusOdo, context.getSystemConfiguration(), task, result);
} catch (ObjectNotFoundException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
iterator.remove();
if (!ModelExecuteOptions.isForce(context.getOptions())) {
ModelUtils.recordFatalError(result, ex);
}
} catch (SchemaException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
}
ModelUtils.recordFatalError(result, ex);
String resourceOid = FocusTypeUtil.determineConstructionResource(evaluatedAssignment.getAssignmentType());
if (resourceOid == null) {
// This is a role assignment or something like that. Just throw the original exception for now.
throw ex;
}
ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid, FocusTypeUtil.determineConstructionKind(evaluatedAssignment.getAssignmentType()), FocusTypeUtil.determineConstructionIntent(evaluatedAssignment.getAssignmentType()));
LensProjectionContext accCtx = context.findProjectionContext(rad);
if (accCtx != null) {
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
iterator.remove();
}
}
}
Aggregations