use of com.evolveum.midpoint.repo.api.PreconditionViolationException in project midpoint by Evolveum.
the class ModifyTest method test162ModifyWithPrecondition2.
@Test
public void test162ModifyWithPrecondition2() throws Exception {
OperationResult result = createOperationResult();
// GIVEN
String versionBefore = repositoryService.getVersion(RoleType.class, roleOid, result);
ModificationPrecondition<RoleType> precondition = o -> false;
// WHEN
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(RoleType.class).item(RoleType.F_DESCRIPTION).replace("123456").asItemDeltas();
try {
repositoryService.modifyObject(RoleType.class, roleOid, itemDeltas, precondition, getModifyOptions(), result);
// THEN
fail("unexpected success");
} catch (PreconditionViolationException e) {
// ok
System.out.println("got expected exception: " + e.getMessage());
}
String versionAfter = repositoryService.getVersion(RoleType.class, roleOid, result);
assertEquals("unexpected version change", versionBefore, versionAfter);
}
use of com.evolveum.midpoint.repo.api.PreconditionViolationException in project midpoint by Evolveum.
the class CaseEngineOperationImpl method commit.
private void commit(OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, PreconditionViolationException, ExpressionEvaluationException, ConfigurationException, CommunicationException, SecurityViolationException {
OperationResult result = parentResult.subresult(OP_COMMIT).setMinor().build();
try {
if (getCaseOid() == null) {
addCaseToRepo(result);
} else {
// Throws PreconditionViolationException if there's a race condition
modifyCaseInRepo(result);
}
if (CaseState.of(currentCase).isClosing()) {
closeTheCase(result);
}
auditRecords.flush(result);
notificationEvents.flush(result);
} catch (PreconditionViolationException e) {
result.recordNotApplicable("Concurrent repository access");
throw e;
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.close();
}
}
use of com.evolveum.midpoint.repo.api.PreconditionViolationException in project midpoint by Evolveum.
the class DeltaExecution method executeModification.
// endregion
// region Modification
private void executeModification(OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, ConflictDetectedException {
Class<E> objectClass = delta.getObjectTypeClass();
// We need current object here. The current object is used to get data for id-only container delete deltas,
// replace deltas and so on. The authorization code can figure out new object if needed, but it needs
// current object to start from.
// We cannot use old object here. That would fail in multi-wave executions. We want object that has all the previous
// wave changes already applied.
PrismObject<E> baseObject = elementContext.getObjectCurrent();
try {
OwnerResolver ownerResolver = createOwnerResolver(result);
b.securityEnforcer.authorize(ModelAuthorizationAction.MODIFY.getUrl(), AuthorizationPhaseType.EXECUTION, AuthorizationParameters.Builder.buildObjectDelta(baseObject, delta), ownerResolver, task, result);
if (shouldApplyModifyMetadata(objectClass, context.getSystemConfigurationBean())) {
b.metadataManager.applyMetadataModify(delta, objectClass, elementContext, b.clock.currentTimeXMLGregorianCalendar(), task, context);
}
if (delta.isEmpty()) {
// Nothing to do
return;
}
if (TaskType.class.isAssignableFrom(objectClass)) {
b.taskManager.modifyTask(delta.getOid(), delta.getModifications(), result);
} else if (NodeType.class.isAssignableFrom(objectClass)) {
b.cacheRepositoryService.modifyObject(NodeType.class, delta.getOid(), delta.getModifications(), result);
} else if (ObjectTypes.isClassManagedByProvisioning(objectClass)) {
String oid = modifyProvisioningObject(result);
if (!oid.equals(delta.getOid())) {
delta.setOid(oid);
LensUtil.setContextOid(context, elementContext, oid);
}
} else {
FocusConstraintsChecker.clearCacheForDelta(delta.getModifications());
ModificationPrecondition<E> precondition = createRepoModificationPrecondition();
try {
b.cacheRepositoryService.modifyObject(objectClass, delta.getOid(), delta.getModifications(), precondition, null, result);
} catch (PreconditionViolationException e) {
throw new ConflictDetectedException(e);
}
}
task.recordObjectActionExecuted(baseObject, objectClass, delta.getOid(), ChangeType.MODIFY, context.getChannel(), null);
} catch (Throwable t) {
task.recordObjectActionExecuted(baseObject, objectClass, delta.getOid(), ChangeType.MODIFY, context.getChannel(), t);
throw t;
}
}
Aggregations