Search in sources :

Example 6 with PreconditionViolationException

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);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) VersionPrecondition(com.evolveum.midpoint.repo.api.VersionPrecondition) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) DOMUtil(com.evolveum.midpoint.util.DOMUtil) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) List(java.util.List) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) NotNull(org.jetbrains.annotations.NotNull) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) COMPLETED(com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType.COMPLETED) AssertJUnit(org.testng.AssertJUnit) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ArrayList(java.util.ArrayList) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) DeltaConvertor(com.evolveum.midpoint.schema.DeltaConvertor) ModificationPrecondition(com.evolveum.midpoint.repo.api.ModificationPrecondition) SqlRepoTestUtil(com.evolveum.midpoint.repo.sql.testing.SqlRepoTestUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) GetOperationOptions.createRawCollection(com.evolveum.midpoint.schema.GetOperationOptions.createRawCollection) SynchronizationUtils(com.evolveum.midpoint.common.SynchronizationUtils) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemName(com.evolveum.midpoint.prism.path.ItemName) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) SerializationOptions.createSerializeForExport(com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException) Test(org.testng.annotations.Test)

Example 7 with PreconditionViolationException

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();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException)

Example 8 with PreconditionViolationException

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;
    }
}
Also used : OwnerResolver(com.evolveum.midpoint.security.api.OwnerResolver) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException)

Aggregations

PreconditionViolationException (com.evolveum.midpoint.repo.api.PreconditionViolationException)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)3 VersionPrecondition (com.evolveum.midpoint.repo.api.VersionPrecondition)3 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)3 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)3 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)3 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)3 Test (org.testng.annotations.Test)3 SynchronizationUtils (com.evolveum.midpoint.common.SynchronizationUtils)2 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 SerializationOptions.createSerializeForExport (com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport)2 com.evolveum.midpoint.prism.delta (com.evolveum.midpoint.prism.delta)2 EquivalenceStrategy (com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 PrismAsserts (com.evolveum.midpoint.prism.util.PrismAsserts)2