use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class ImportObjectsFromFileTaskHandler method launch.
/**
* Launch an import. Calling this method will start import in a new
* thread, possibly on a different node.
*
* @param input
* @param task
* @param parentResult
*/
public void launch(File input, Task task, OperationResult parentResult) {
LOGGER.debug("Launching import accounts from file {}", input);
OperationResult result = parentResult.createSubresult(ImportObjectsFromFileTaskHandler.class.getName() + ".launch");
result.addParam("input", input);
// TODO
// Set handler URI so we will be called back
task.setHandlerUri(HANDLER_URI);
// Readable task name
PolyStringType polyString = new PolyStringType("Import from file " + input);
task.setName(polyString);
// ((Collection)modifications).add(objectClassDelta);
try {
PrismProperty filenameProp = filenamePropertyDefinition.instantiate();
filenameProp.setRealValue(input.getAbsolutePath());
task.setExtensionProperty(filenameProp);
task.savePendingModifications(result);
// task.modify(modifications, result);
} catch (ObjectNotFoundException e) {
LOGGER.error("Task object not found, expecting it to exist (task {})", task, e);
result.recordFatalError("Task object not found", e);
throw new IllegalStateException("Task object not found, expecting it to exist", e);
} catch (ObjectAlreadyExistsException e) {
LOGGER.error("Task object was not updated (task {})", task, e);
result.recordFatalError("Task object was not updated", e);
throw new IllegalStateException("Task object was not updated", e);
} catch (SchemaException e) {
LOGGER.error("Error dealing with schema (task {})", task, e);
result.recordFatalError("Error dealing with schema", e);
throw new IllegalStateException("Error dealing with schema", e);
}
// Switch task to background. This will start new thread and call
// the run(task) method.
// Note: the thread may be actually started on a different node
taskManager.switchToBackground(task, result);
result.setBackgroundTaskOid(task.getOid());
LOGGER.trace("Import objects from file {} switched to background, control thread returning with task {}", input, task);
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.
private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
ShadowType shadowType;
try {
shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
} catch (ObjectNotFoundException e) {
// Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
// the chance to react yet. Just ignore such shadow.
LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
continue;
}
if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
ShadowAssociationType shadowAssociationType = newValue.asContainerable();
shadowAssociationType.setName(assocName);
ObjectReferenceType shadowRef = new ObjectReferenceType();
shadowRef.setOid(linkRef.getOid());
shadowAssociationType.setShadowRef(shadowRef);
}
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.
the class LazyXPathVariableResolver method resolveVariable.
@Override
public Object resolveVariable(QName name) {
if (variables == null) {
return null;
}
if (name != null && (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty())) {
LOGGER.warn("Using variable without a namespace (" + name + "), possible namespace problem (e.g. missing namespace prefix declaration) in " + contextDescription);
}
// Note: null is a legal variable name here. It corresponds to the root node
Object variableValue = variables.get(name);
if (variableValue == null) {
// TODO: warning ???
return null;
}
QName type = null;
// Attempt to resolve object reference
if (objectResolver != null && variableValue instanceof ObjectReferenceType) {
ObjectReferenceType ref = (ObjectReferenceType) variableValue;
if (ref.getOid() == null) {
SchemaException newEx = new SchemaException("Null OID in reference in variable " + name + " in " + contextDescription, name);
throw new TunnelException(newEx);
} else {
type = ref.getType();
try {
// TODO task
variableValue = objectResolver.resolve(ref, ObjectType.class, null, contextDescription, null, result);
} catch (ObjectNotFoundException e) {
ObjectNotFoundException newEx = new ObjectNotFoundException("Object not found during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, ref.getOid());
// We have no other practical way how to handle the error
throw new TunnelException(newEx);
} catch (SchemaException e) {
ExpressionSyntaxException newEx = new ExpressionSyntaxException("Schema error during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, name);
throw new TunnelException(newEx);
}
}
}
try {
return convertToXml(variableValue, name, prismContext, contextDescription);
} catch (SchemaException e) {
throw new TunnelException(e);
}
}
use of com.evolveum.midpoint.util.exception.ObjectNotFoundException 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.ObjectNotFoundException 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;
}
Aggregations