use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ShadowCacheReconciler method afterModifyOnResource.
@Override
public void afterModifyOnResource(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> modifications, OperationResult resourceOperationResult, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
LOGGER.trace("Modified shadow is reconciled. Start to clean up account after successful reconciliation.");
try {
cleanShadowInRepository(shadow, parentResult);
} catch (ObjectAlreadyExistsException ex) {
//should be never thrown
throw new SystemException("While modifying object in the repository got exception: " + ex.getMessage(), ex);
}
LOGGER.trace("Shadow cleaned up successfully.");
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ShadowCacheReconciler method cleanShadowInRepository.
private void cleanShadowInRepository(PrismObject<ShadowType> shadow, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {
PrismObject<ShadowType> normalizedShadow = shadow.clone();
ProvisioningUtil.normalizeShadow(normalizedShadow.asObjectable(), parentResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("normalized shadow {}", normalizedShadow.debugDump(1));
}
// FIXME: ugly hack, need to be fixed (problem with comparing operation
// result, because it was changed and in this call it is different as
// one in repo, therefore the following if)
PrismObject<ShadowType> oldShadow = shadow.clone();
ShadowUtil.getAttributesContainer(oldShadow).clear();
PrismObject<ShadowType> repoShadow = getRepositoryService().getObject(ShadowType.class, shadow.getOid(), null, parentResult);
ShadowType repoShadowType = repoShadow.asObjectable();
if (repoShadowType.getResult() != null) {
if (!repoShadowType.getResult().equals(oldShadow.asObjectable().getResult())) {
oldShadow.asObjectable().setResult(repoShadowType.getResult());
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("origin shadow with failure description {}", oldShadow.debugDump(1));
}
ObjectDelta delta = oldShadow.diff(normalizedShadow);
// TODO: remove this ugly hack (problem is in prism - objectChange does not get deleted by delta produced by diff method) - see MID-2174
PropertyDelta<ObjectDeltaType> clearObjectChange = PropertyDelta.createModificationReplaceProperty(ShadowType.F_OBJECT_CHANGE, oldShadow.getDefinition());
delta.removePropertyModification(ShadowType.F_OBJECT_CHANGE);
delta.addModification(clearObjectChange);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Normalizing shadow: change description: {}", delta.debugDump());
}
try {
ConstraintsChecker.onShadowModifyOperation(delta.getModifications());
getRepositoryService().modifyObject(ShadowType.class, oldShadow.getOid(), delta.getModifications(), parentResult);
} catch (SchemaException ex) {
parentResult.recordFatalError("Couldn't modify shadow: schema violation: " + ex.getMessage(), ex);
throw ex;
} catch (ObjectAlreadyExistsException ex) {
parentResult.recordFatalError("Couldn't modify shadow: shadow already exists: " + ex.getMessage(), ex);
throw ex;
} catch (ObjectNotFoundException ex) {
parentResult.recordFatalError("Couldn't modify shadow: shadow not found: " + ex.getMessage(), ex);
throw ex;
}
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ShadowManager method fixShadow.
/**
* Re-reads the shadow, re-evaluates the identifiers and stored values, updates them if necessary. Returns
* fixed shadow.
*/
public PrismObject<ShadowType> fixShadow(ProvisioningContext ctx, PrismObject<ShadowType> origRepoShadow, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
PrismObject<ShadowType> currentRepoShadow = repositoryService.getObject(ShadowType.class, origRepoShadow.getOid(), null, parentResult);
ProvisioningContext shadowCtx = ctx.spawn(currentRepoShadow);
RefinedObjectClassDefinition ocDef = shadowCtx.getObjectClassDefinition();
PrismContainer<Containerable> attributesContainer = currentRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer != null && attributesContainer.getValue() != null) {
ObjectDelta<ShadowType> shadowDelta = currentRepoShadow.createModifyDelta();
for (Item<?, ?> item : attributesContainer.getValue().getItems()) {
if (item instanceof PrismProperty<?>) {
PrismProperty<?> attrProperty = (PrismProperty<?>) item;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(attrProperty.getElementName());
if (attrDef == null) {
// No definition for this property, it should not be in the shadow
PropertyDelta<?> oldRepoAttrPropDelta = attrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(attrProperty.getValues()));
shadowDelta.addModification(oldRepoAttrPropDelta);
} else {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
List<PrismPropertyValue> valuesToAdd = null;
List<PrismPropertyValue> valuesToDelete = null;
for (PrismPropertyValue attrVal : attrProperty.getValues()) {
Object currentRealValue = attrVal.getValue();
Object normalizedRealValue = matchingRule.normalize(currentRealValue);
if (!normalizedRealValue.equals(currentRealValue)) {
if (attrDef.isSingleValue()) {
shadowDelta.addModificationReplaceProperty(attrProperty.getPath(), normalizedRealValue);
break;
} else {
if (valuesToAdd == null) {
valuesToAdd = new ArrayList<>();
}
valuesToAdd.add(new PrismPropertyValue(normalizedRealValue));
if (valuesToDelete == null) {
valuesToDelete = new ArrayList<>();
}
valuesToDelete.add(new PrismPropertyValue(currentRealValue));
}
}
}
PropertyDelta attrDelta = attrProperty.createDelta(attrProperty.getPath());
if (valuesToAdd != null) {
attrDelta.addValuesToAdd(valuesToAdd);
}
if (valuesToDelete != null) {
attrDelta.addValuesToDelete(valuesToDelete);
}
shadowDelta.addModification(attrDelta);
}
}
}
if (!shadowDelta.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Fixing shadow {} with delta:\n{}", origRepoShadow, shadowDelta.debugDump());
}
try {
repositoryService.modifyObject(ShadowType.class, origRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
} catch (ObjectAlreadyExistsException e) {
// This should not happen for shadows
throw new SystemException(e.getMessage(), e);
}
shadowDelta.applyTo(currentRepoShadow);
} else {
LOGGER.trace("No need to fixing shadow {} (empty delta)", origRepoShadow);
}
} else {
LOGGER.trace("No need to fixing shadow {} (no atttributes)", origRepoShadow);
}
return currentRepoShadow;
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ShadowManager method addNewRepositoryShadow.
// Used after ADD operation on resource
public String addNewRepositoryShadow(ProvisioningContext ctx, AsynchronousOperationReturnValue<PrismObject<ShadowType>> addResult, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ObjectAlreadyExistsException, ExpressionEvaluationException {
PrismObject<ShadowType> resourceShadow = addResult.getReturnValue();
PrismObject<ShadowType> repoShadow = createRepositoryShadow(ctx, resourceShadow);
if (repoShadow == null) {
parentResult.recordFatalError("Error while creating account shadow object to save in the reposiotory. Shadow is null.");
throw new IllegalStateException("Error while creating account shadow object to save in the reposiotory. Shadow is null.");
}
addPendingOperationAdd(repoShadow, addResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding repository shadow\n{}", repoShadow.debugDump());
}
String oid = null;
try {
ConstraintsChecker.onShadowAddOperation(repoShadow.asObjectable());
oid = repositoryService.addObject(repoShadow, null, parentResult);
} catch (ObjectAlreadyExistsException ex) {
// This should not happen. The OID is not supplied and it is
// generated by the repo
// If it happens, it must be a repo bug. Therefore it is safe to
// convert to runtime exception
parentResult.recordFatalError("Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex);
throw new ObjectAlreadyExistsException("Couldn't add shadow object to the repository. Shadow object already exist. Reason: " + ex.getMessage(), ex);
}
repoShadow.setOid(oid);
LOGGER.trace("Object added to the repository successfully.");
parentResult.recordSuccess();
return repoShadow.getOid();
}
use of com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException in project midpoint by Evolveum.
the class ModelCrudService method deleteObject.
/**
* <p>
* Deletes object with specified OID.
* </p>
* <p>
* Must fail if object with specified OID does not exists. Should be atomic.
* </p>
*
* @param oid
* OID of object to delete
* @param parentResult
* parent OperationResult (in/out)
* @throws ObjectNotFoundException
* specified object does not exist
* @throws IllegalArgumentException
* wrong OID format, described change is not applicable
* @throws ConsistencyViolationException
* sub-operation failed, cannot delete objects as its deletion
* would lead to inconsistent state
* @throws CommunicationException
* @throws ConfigurationException
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
public <T extends ObjectType> void deleteObject(Class<T> clazz, String oid, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, ConsistencyViolationException, CommunicationException, SchemaException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Validate.notNull(clazz, "Class must not be null.");
Validate.notEmpty(oid, "Oid must not be null or empty.");
Validate.notNull(parentResult, "Result type must not be null.");
OperationResult result = parentResult.createSubresult(DELETE_OBJECT);
result.addParams(new String[] { "oid" }, oid);
RepositoryCache.enter();
try {
ObjectDelta<T> objectDelta = new ObjectDelta<T>(clazz, ChangeType.DELETE, prismContext);
objectDelta.setOid(oid);
LOGGER.trace("Deleting object with oid {}.", new Object[] { oid });
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
modelService.executeChanges(deltas, options, task, result);
result.recordSuccess();
} catch (ObjectNotFoundException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (CommunicationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (SecurityViolationException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (RuntimeException ex) {
ModelUtils.recordFatalError(result, ex);
throw ex;
} catch (ObjectAlreadyExistsException ex) {
ModelUtils.recordFatalError(result, ex);
throw new SystemException(ex.getMessage(), ex);
} catch (ExpressionEvaluationException ex) {
ModelUtils.recordFatalError(result, ex);
throw new SystemException(ex.getMessage(), ex);
} finally {
RepositoryCache.exit();
}
}
Aggregations