use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class PrismObject method createNewValue.
public PrismObjectValue<O> createNewValue() {
checkMutability();
PrismObjectValue<O> newValue = new PrismObjectValue<>(prismContext);
try {
add(newValue, false);
return newValue;
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal Error: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class AssociationTargetSearchExpressionEvaluator method createPrismValue.
protected PrismContainerValue<ShadowAssociationType> createPrismValue(String oid, QName targetTypeQName, List<ItemDelta<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> additionalAttributeDeltas, ExpressionEvaluationContext params) {
ShadowAssociationType associationType = new ShadowAssociationType();
PrismContainerValue<ShadowAssociationType> associationCVal = associationType.asPrismContainerValue();
associationType.setName(params.getMappingQName());
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(oid);
targetRef.setType(targetTypeQName);
associationType.setShadowRef(targetRef);
try {
if (additionalAttributeDeltas != null) {
ItemDelta.applyTo(additionalAttributeDeltas, associationCVal);
}
getPrismContext().adopt(associationCVal, ShadowType.COMPLEX_TYPE, new ItemPath(ShadowType.F_ASSOCIATION));
if (InternalsConfig.consistencyChecks) {
associationCVal.assertDefinitions("associationCVal in assignment expression in " + params.getContextDescription());
}
} catch (SchemaException e) {
// Should not happen
throw new SystemException(e);
}
return associationCVal;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class XPathScriptEvaluator method evaluate.
private Object evaluate(QName returnType, String code, ExpressionVariables variables, ObjectResolver objectResolver, Collection<FunctionLibrary> functions, String contextDescription, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, ExpressionSyntaxException {
XPathExpressionCodeHolder codeHolder = new XPathExpressionCodeHolder(code);
//System.out.println("code " + code);
XPath xpath = factory.newXPath();
XPathVariableResolver variableResolver = new LazyXPathVariableResolver(variables, objectResolver, contextDescription, prismContext, result);
xpath.setXPathVariableResolver(variableResolver);
xpath.setNamespaceContext(new MidPointNamespaceContext(codeHolder.getNamespaceMap()));
xpath.setXPathFunctionResolver(getFunctionResolver(functions));
XPathExpression expr;
try {
expr = xpath.compile(codeHolder.getExpressionAsString());
} catch (Exception e) {
Throwable originalException = ExceptionUtil.lookForTunneledException(e);
if (originalException != null && originalException instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) originalException;
}
if (originalException != null && originalException instanceof ExpressionSyntaxException) {
throw (ExpressionSyntaxException) originalException;
}
if (e instanceof XPathExpressionException) {
throw createExpressionEvaluationException(e, contextDescription);
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new SystemException(e.getMessage(), e);
}
Object rootNode;
try {
rootNode = determineRootNode(variableResolver, contextDescription);
} catch (SchemaException e) {
throw new ExpressionSyntaxException(e.getMessage(), e);
}
Object evaluatedExpression;
try {
evaluatedExpression = expr.evaluate(rootNode, returnType);
} catch (Exception e) {
Throwable originalException = ExceptionUtil.lookForTunneledException(e);
if (originalException != null && originalException instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) originalException;
}
if (originalException != null && originalException instanceof ExpressionSyntaxException) {
throw (ExpressionSyntaxException) originalException;
}
if (e instanceof XPathExpressionException) {
throw createExpressionEvaluationException(e, contextDescription);
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new SystemException(e.getMessage(), e);
}
if (evaluatedExpression == null) {
return null;
}
return evaluatedExpression;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method executeSearchAttempt.
private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObject> rawResult, Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, boolean searchOnResource, boolean tryAlsoRepository, final List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
final List<V> list = new ArrayList<V>();
Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
if (!searchOnResource) {
options.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
}
extendOptions(options, searchOnResource);
ResultHandler<O> handler = new ResultHandler<O>() {
@Override
public boolean handle(PrismObject<O> object, OperationResult parentResult) {
if (rawResult != null) {
rawResult.add(object);
}
list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));
return true;
}
};
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (IllegalStateException e) {
// this comes from checkConsistence methods
throw new IllegalStateException(e.getMessage() + " in " + contextDescription, e);
} catch (SchemaException e) {
throw new SchemaException(e.getMessage() + " in " + contextDescription, e);
} catch (SystemException e) {
throw new SystemException(e.getMessage() + " in " + contextDescription, e);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e) {
if (searchOnResource && tryAlsoRepository) {
options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
try {
objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
} catch (SchemaException e1) {
throw new SchemaException(e1.getMessage() + " in " + contextDescription, e1);
} catch (CommunicationException | ConfigurationException | SecurityViolationException e1) {
// shadow for group doesn't exist? (MID-2107)
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} else {
throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
}
} catch (ObjectNotFoundException e) {
throw e;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Assignment expression resulted in {} objects, using query:\n{}", list.size(), query.debugDump());
}
return list;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class ShadowManager method lookupShadowInRepository.
/**
* Locates the appropriate Shadow in repository that corresponds to the
* provided resource object.
*
* DEAD flag is cleared - in memory as well as in repository.
*
* @param parentResult
*
* @return current shadow object that corresponds to provided
* resource object or null if the object does not exist
*/
public PrismObject<ShadowType> lookupShadowInRepository(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
ObjectQuery query = createSearchShadowQuery(ctx, resourceShadow, prismContext, parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Searching for shadow using filter:\n{}", query.debugDump());
}
// PagingType paging = new PagingType();
// TODO: check for errors
List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
MiscSchemaUtil.reduceSearchResult(results);
LOGGER.trace("lookupShadow found {} objects", results.size());
if (results.size() == 0) {
return null;
}
if (results.size() > 1) {
for (PrismObject<ShadowType> result : results) {
LOGGER.trace("Search result:\n{}", result.debugDump());
}
LOGGER.error("More than one shadow found for " + resourceShadow);
// TODO: Better error handling later
throw new IllegalStateException("More than one shadow found for " + resourceShadow);
}
PrismObject<ShadowType> shadow = results.get(0);
checkConsistency(shadow);
if (Boolean.TRUE.equals(shadow.asObjectable().isDead())) {
LOGGER.debug("Repository shadow {} is marked as dead - resetting the flag", ObjectTypeUtil.toShortString(shadow));
shadow.asObjectable().setDead(false);
List<ItemDelta<?, ?>> deltas = DeltaBuilder.deltaFor(ShadowType.class, prismContext).item(ShadowType.F_DEAD).replace().asItemDeltas();
try {
repositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, parentResult);
} catch (ObjectAlreadyExistsException e) {
throw new SystemException("Unexpected exception when resetting 'dead' flag: " + e.getMessage(), e);
}
}
return shadow;
}
Aggregations