use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method searchObjectsIterative.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(final Class<T> type, ObjectQuery query, final Collection<SelectorOptions<GetOperationOptions>> options, final ResultHandler<T> handler, Task task, final OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(parentResult, "Operation result must not be null.");
Validate.notNull(handler, "Handler must not be null.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Start to search object. Query {}", query != null ? query.debugDump() : "(null)");
}
final OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".searchObjectsIterative");
result.setSummarizeSuccesses(true);
result.setSummarizeErrors(true);
result.setSummarizePartialErrors(true);
result.addParam("query", query);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
ObjectFilter filter = null;
if (query != null) {
filter = ObjectQueryUtil.simplify(query.getFilter());
query = query.cloneEmpty();
query.setFilter(filter);
}
if (InternalsConfig.consistencyChecks && filter != null) {
// We may not have all the definitions here. We will apply the definitions later
filter.checkConsistence(false);
}
if (filter != null && filter instanceof NoneFilter) {
result.recordSuccessIfUnknown();
result.cleanupResult();
LOGGER.trace("Finished searching. Nothing to do. Filter is NONE");
SearchResultMetadata metadata = new SearchResultMetadata();
metadata.setApproxNumberOfAllResults(0);
return metadata;
}
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
if (!ShadowType.class.isAssignableFrom(type)) {
ResultHandler<T> internalHandler = (object, objResult) -> handleRepoObject(type, object, options, handler, task, objResult);
Collection<SelectorOptions<GetOperationOptions>> repoOptions = null;
if (GetOperationOptions.isReadOnly(rootOptions)) {
repoOptions = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
}
SearchResultMetadata metadata = null;
try {
// TODO think about strictSequential flag
metadata = getCacheRepositoryService().searchObjectsIterative(type, query, internalHandler, repoOptions, false, result);
result.computeStatus();
result.recordSuccessIfUnknown();
} catch (SchemaException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
}
result.cleanupResult();
return metadata;
}
final boolean shouldDoRepoSearch = ProvisioningUtil.shouldDoRepoSearch(rootOptions);
final ShadowHandler shadowHandler = new ShadowHandler() {
@Override
public boolean handle(ShadowType shadowType) {
OperationResult handleResult = result.createSubresult(ProvisioningService.class.getName() + ".searchObjectsIterative.handle");
if (shouldDoRepoSearch) {
return handleRepoObject(type, (PrismObject<T>) shadowType.asPrismObject(), options, handler, task, handleResult);
}
if (shadowType == null) {
throw new IllegalArgumentException("Null shadow in call to handler");
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("searchObjectsIterative: processing shadow: {}", SchemaDebugUtil.prettyPrint(shadowType));
}
boolean doContinue;
try {
PrismObject shadow = shadowType.asPrismObject();
validateObject(shadow);
doContinue = handler.handle(shadow, handleResult);
handleResult.computeStatus();
handleResult.recordSuccessIfUnknown();
if (!handleResult.isSuccess() && !handleResult.isHandledError()) {
Collection<? extends ItemDelta> shadowModificationType = PropertyDelta.createModificationReplacePropertyCollection(ShadowType.F_RESULT, getResourceObjectShadowDefinition(), handleResult.createOperationResultType());
try {
ConstraintsChecker.onShadowModifyOperation(shadowModificationType);
cacheRepositoryService.modifyObject(ShadowType.class, shadowType.getOid(), shadowModificationType, result);
} catch (ObjectNotFoundException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Not found: " + ex.getMessage(), ex);
} catch (ObjectAlreadyExistsException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Already exists: " + ex.getMessage(), ex);
} catch (SchemaException ex) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: Schema error: " + ex.getMessage(), ex);
} catch (RuntimeException e) {
result.recordFatalError("Saving of result to " + shadow + " shadow failed: " + e.getMessage(), e);
throw e;
}
}
} catch (RuntimeException e) {
result.recordFatalError(e);
throw e;
} finally {
handleResult.computeStatus();
handleResult.recordSuccessIfUnknown();
// AbstractSummarizingResultHandler [lazyman]
if (result.isSuccess()) {
result.getSubresults().clear();
}
result.summarize();
}
return doContinue;
}
};
SearchResultMetadata metadata;
try {
metadata = getShadowCache(Mode.STANDARD).searchObjectsIterative(query, options, shadowHandler, true, task, result);
result.computeStatus();
} catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}
return metadata;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method refreshShadow.
@Override
public void refreshShadow(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(shadow, "Shadow for refresh must not be null.");
OperationResult result = parentResult.createSubresult(ProvisioningServiceImpl.class.getName() + ".finishOperation");
LOGGER.debug("Refreshing shadow {}", shadow);
try {
getShadowCache(Mode.RECON).refreshShadow(shadow, task, result);
refreshShadowLegacy(shadow, options, task, result);
} catch (GenericFrameworkException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't refresh shadow: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
throw new CommunicationException(e.getMessage(), e);
} catch (CommunicationException | SchemaException | ObjectNotFoundException | ConfigurationException | SecurityViolationException | ObjectAlreadyExistsException | ExpressionEvaluationException | RuntimeException | Error e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't refresh shadow: " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
throw e;
}
result.computeStatus();
result.cleanupResult();
LOGGER.debug("Finished refreshing shadow {}: ", shadow, result);
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method modifyObject.
@SuppressWarnings("rawtypes")
@Override
public <T extends ObjectType> String modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectAlreadyExistsException, ExpressionEvaluationException {
Validate.notNull(oid, "OID must not be null.");
Validate.notNull(modifications, "Modifications must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
if (InternalsConfig.encryptionChecks) {
CryptoUtil.checkEncrypted(modifications);
}
if (InternalsConfig.consistencyChecks) {
ItemDelta.checkConsistence(modifications);
}
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".modifyObject");
result.addCollectionOfSerializablesAsParam("modifications", modifications);
result.addParam(OperationResult.PARAM_OID, oid);
result.addParam("scripts", scripts);
result.addParam("options", options);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("*PROVISIONING: modifyObject: object modifications:\n{}", DebugUtil.debugDump(modifications));
}
// getting object to modify
PrismObject<T> repoShadow = getRepoObject(type, oid, null, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("**PROVISIONING: modifyObject: object to modify (repository):\n{}.", repoShadow.debugDump());
}
try {
if (ShadowType.class.isAssignableFrom(type)) {
// calling shadow cache to modify object
oid = getShadowCache(Mode.STANDARD).modifyShadow((PrismObject<ShadowType>) repoShadow, oid, modifications, scripts, options, task, result);
} else {
cacheRepositoryService.modifyObject(type, oid, modifications, result);
}
result.computeStatus();
} catch (CommunicationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: communication problem: " + e.getMessage(), e);
throw e;
} catch (GenericFrameworkException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: generic error in the connector: " + e.getMessage(), e);
throw new CommunicationException(e.getMessage(), e);
} catch (SchemaException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: schema problem: " + e.getMessage(), e);
throw e;
} catch (ObjectNotFoundException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: object doesn't exist: " + e.getMessage(), e);
throw e;
} catch (RuntimeException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: unexpected problem: " + e.getMessage(), e);
throw new SystemException("Internal error: " + e.getMessage(), e);
} catch (ConfigurationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: configuration problem: " + e.getMessage(), e);
throw e;
} catch (SecurityViolationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: security violation: " + e.getMessage(), e);
throw e;
} catch (ObjectAlreadyExistsException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: object after modification would conflict with another existing object: " + e.getMessage(), e);
throw e;
} catch (ExpressionEvaluationException e) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't modify object: expression errror: " + e.getMessage(), e);
throw e;
}
result.cleanupResult();
return oid;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ProvisioningServiceImpl method addObject.
@Override
public <T extends ObjectType> String addObject(PrismObject<T> object, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(object, "Object to add must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");
if (InternalsConfig.encryptionChecks) {
CryptoUtil.checkEncrypted(object);
}
OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".addObject");
result.addParam("object", object);
result.addParam("scripts", scripts);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
String oid = null;
if (object.canRepresent(ShadowType.class)) {
try {
// calling shadow cache to add object
oid = getShadowCache(Mode.STANDARD).addShadow((PrismObject<ShadowType>) object, scripts, null, options, task, result);
LOGGER.trace("**PROVISIONING: Added shadow object {}", oid);
result.computeStatus();
} catch (GenericFrameworkException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object " + object + ". Reason: " + ex.getMessage(), ex);
throw new CommunicationException(ex.getMessage(), ex);
} catch (SchemaException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Schema violation: " + ex.getMessage(), ex);
throw new SchemaException("Couldn't add object. Schema violation: " + ex.getMessage(), ex);
} catch (ObjectAlreadyExistsException ex) {
result.computeStatus();
if (!result.isSuccess() && !result.isHandledError()) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Object already exist: " + ex.getMessage(), ex);
} else {
result.recordSuccess();
}
result.cleanupResult(ex);
throw new ObjectAlreadyExistsException("Couldn't add object. Object already exists: " + ex.getMessage(), ex);
} catch (ConfigurationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Configuration error: " + ex.getMessage(), ex);
throw ex;
} catch (SecurityViolationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Security violation: " + ex.getMessage(), ex);
throw ex;
} catch (ExpressionEvaluationException ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Expression error: " + ex.getMessage(), ex);
throw ex;
} catch (RuntimeException | Error ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't add object. Runtime error: " + ex.getMessage(), ex);
throw ex;
}
} else {
RepoAddOptions addOptions = null;
if (ProvisioningOperationOptions.isOverwrite(options)) {
addOptions = RepoAddOptions.createOverwrite();
}
oid = cacheRepositoryService.addObject(object, addOptions, result);
result.computeStatus();
}
result.cleanupResult();
return oid;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class SchemaExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, SecurityViolationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof SchemaException) {
throw (SchemaException) ex;
} else {
throw new SchemaException(ex.getMessage(), ex);
}
}
ObjectDelta delta = null;
switch(op) {
case ADD:
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
break;
case DELETE:
delta = ObjectDelta.createDeleteDelta(shadow.getClass(), shadow.getOid(), prismContext);
break;
case MODIFY:
Collection<? extends ItemDelta> modifications = null;
if (shadow.getObjectChange() != null) {
ObjectDeltaType deltaType = shadow.getObjectChange();
modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
}
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.getClass(), prismContext);
break;
}
if (op != FailedOperation.GET) {
// Task task = taskManager.createTaskInstance();
ResourceOperationDescription operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, parentResult);
changeNotificationDispatcher.notifyFailure(operationDescription, task, parentResult);
}
if (shadow.getOid() == null) {
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Collection<ItemDelta> modification = createAttemptModification(shadow, null);
try {
ConstraintsChecker.onShadowModifyOperation(modification);
cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
} catch (Exception e) {
//this should not happen. But if it happens, we should return original exception
// throw new SchemaException("Schema violation during processing shadow: "
// + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
parentResult.recordFatalError("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
throw new SchemaException("Schema violation during processing shadow: " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
}
Aggregations