Search in sources :

Example 41 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class AbstractManualResourceTest method assertPendingOperation.

private PendingOperationType assertPendingOperation(PrismObject<ShadowType> shadow, PendingOperationType pendingOperation, XMLGregorianCalendar requestStart, XMLGregorianCalendar requestEnd, OperationResultStatusType expectedStatus, XMLGregorianCalendar completionStart, XMLGregorianCalendar completionEnd) {
    assertNotNull("No operation ", pendingOperation);
    ObjectDeltaType deltaType = pendingOperation.getDelta();
    assertNotNull("No delta in pending operation in " + shadow, deltaType);
    // TODO: check content of pending operations in the shadow
    TestUtil.assertBetween("No request timestamp in pending operation in " + shadow, requestStart, requestEnd, pendingOperation.getRequestTimestamp());
    OperationResultStatusType status = pendingOperation.getResultStatus();
    assertEquals("Wrong status in pending operation in " + shadow, expectedStatus, status);
    if (expectedStatus != OperationResultStatusType.IN_PROGRESS) {
        TestUtil.assertBetween("No completion timestamp in pending operation in " + shadow, completionStart, completionEnd, pendingOperation.getCompletionTimestamp());
    }
    return pendingOperation;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType)

Example 42 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class TestModelWebServiceNegative method test200ModifyAccountWrongExplicitType.

@Test
public void test200ModifyAccountWrongExplicitType() throws Exception {
    final String TEST_NAME = "test200ModifyAccountWrongExplicitType";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelWebServiceNegative.class.getName() + "." + TEST_NAME);
    ObjectDeltaType objectChange = createShadowReplaceChange(ACCOUNT_SHADOW_GUYBRUSH_OID, "attributes/" + DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "42", DOMUtil.XSD_INT);
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    deltaList.getDelta().add(objectChange);
    // WHEN, THEN
    //assertExecuteChangesFailure(deltaList, null, SchemaViolationFaultType.class, "The value of type", "cannot be applied to attribute");
    assertExecuteChangesFailure(deltaList, null, SchemaViolationFaultType.class, "Expected", "but got class");
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 43 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class TestModelWebServiceNegative method test100ModifyAccountExplicitType.

/**
	 * First tests are positive, to make sure that this method works.
	 */
@Test
public void test100ModifyAccountExplicitType() throws Exception {
    final String TEST_NAME = "test100ModifyUserAddAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelWebServiceNegative.class.getName() + "." + TEST_NAME);
    ObjectDeltaType objectChange = createShadowReplaceChange(ACCOUNT_SHADOW_GUYBRUSH_OID, "attributes/" + DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "foo", DOMUtil.XSD_STRING);
    ObjectDeltaListType deltaList = new ObjectDeltaListType();
    deltaList.getDelta().add(objectChange);
    // WHEN
    modelWeb.executeChanges(deltaList, null);
    // THEN
    // Check account in dummy resource
    assertDefaultDummyAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, ACCOUNT_GUYBRUSH_DUMMY_FULLNAME, true);
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "foo");
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 44 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ConfigurationExceptionHandler 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 {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof ConfigurationException) {
            throw (ConfigurationException) ex;
        } else {
            throw new ConfigurationException(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;
        case GET:
            OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.ConfigurationExceptionHandler.handleError." + op.name());
            operationResult.addParam("shadow", shadow);
            operationResult.addParam("currentOperation", op);
            operationResult.addParam("exception", ex.getMessage());
            for (OperationResult subRes : parentResult.getSubresults()) {
                subRes.muteError();
            }
            operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because of configuration error. Returning shadow from the repository");
            shadow.setFetchResult(operationResult.createOperationResultType());
            return shadow;
    }
    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) {
        throw new ConfigurationException("Configuration error: " + 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
        LOGGER.error("Unexpected error while modifying shadow {}: {}", shadow, e.getMessage(), e);
        if (ex instanceof SchemaException) {
            throw ((SchemaException) ex);
        } else if (ex instanceof GenericFrameworkException) {
            throw ((GenericFrameworkException) ex);
        } else if (ex instanceof CommunicationException) {
            throw ((CommunicationException) ex);
        } else if (ex instanceof ObjectNotFoundException) {
            throw ((ObjectNotFoundException) ex);
        } else if (ex instanceof ObjectAlreadyExistsException) {
            throw ((ObjectAlreadyExistsException) ex);
        } else if (ex instanceof ConfigurationException) {
            throw ((ConfigurationException) ex);
        }
    }
    parentResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
    throw new ConfigurationException("Configuration error: " + ex.getMessage(), ex);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 45 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class GenericErrorHandler method handleError.

//	@Autowired
//	private OperationFinisher operationFinisher;
@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, ExpressionEvaluationException {
    if (!doDiscovery) {
        parentResult.recordFatalError(ex);
        if (ex instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) ex;
        } else {
            throw new GenericFrameworkException(ex.getMessage(), ex);
        }
    }
    //		OperationResult result = OperationResult.createOperationResult(shadow.getResult());
    String operation = (shadow.getFailedOperationType() == null ? "null" : shadow.getFailedOperationType().name());
    OperationResult result = parentResult.createSubresult(COMPENSATE_OPERATION);
    result.addContext("compensatedOperation", operation);
    result.addContext("operationType", op.name());
    result.addParam("shadow", shadow);
    result.addParam("currentOperation", op);
    result.addParam("reconciled", true);
    switch(op) {
        case GET:
            if (ShadowUtil.isDead(shadow) || ResourceTypeUtil.isDown(shadow.getResource()) || !compensate) {
                result.recordStatus(OperationResultStatus.PARTIAL_ERROR, "Unable to get object from the resource. Probably it has not been created yet because of previous unavailability of the resource.");
                result.computeStatus();
                shadow.setFetchResult(parentResult.createOperationResultType());
                return shadow;
            }
            if (shadow.getFailedOperationType() == null) {
                String message = "Generic error in the connector. Can't process shadow " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage();
                result.recordFatalError(message, ex);
                throw new GenericFrameworkException(message, ex);
            }
            try {
                //ProvisioningOperationOptions.createCompletePostponed(false);
                provisioningService.refreshShadow(shadow.asPrismObject(), null, task, result);
                result.computeStatus();
                if (result.isSuccess()) {
                    LOGGER.trace("Postponed operation was finished successfully while getting shadow. Getting new object.");
                    PrismObject prismShadow = provisioningService.getObject(shadow.getClass(), shadow.getOid(), null, task, result);
                    if (!prismShadow.hasCompleteDefinition()) {
                        LOGGER.trace("applying definitions to shadow");
                        provisioningService.applyDefinition(prismShadow, task, result);
                    }
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("Got {} after finishing postponed operation.", prismShadow.debugDump());
                    }
                    shadow = (T) prismShadow.asObjectable();
                }
            //				} catch(Exception e){
            //					result.recordFatalError("Could not finish operation " + operation + ". Reason: " + e.getMessage()));
            //					// just throw the origin exception
            //					throw new GenericFrameworkException(ex);
            } finally {
                result.computeStatus();
            }
            return shadow;
        case MODIFY:
            if (shadow.getFailedOperationType() == null) {
                String message = "Generic error in the connector. Can't process shadow " + ObjectTypeUtil.toShortString(shadow) + ". ";
                result.recordFatalError(message, ex);
                throw new GenericFrameworkException(message, ex);
            }
            // get the modifications from the shadow before the account
            // is created, because after successful creation of account,
            // the modification will be lost
            Collection<? extends ItemDelta> modifications = null;
            if (shadow.getObjectChange() != null) {
                ObjectDeltaType deltaType = shadow.getObjectChange();
                modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.asPrismObject().getDefinition());
            }
            PropertyDelta.applyTo(modifications, shadow.asPrismObject());
            provisioningService.refreshShadow(shadow.asPrismObject(), null, task, result);
            result.computeStatus();
            if (!result.isSuccess()) {
                // account wasn't created, probably resource is
                // still down, or there is other reason.just save the
                // pending modifications to the shadow in the
                // repository..next time by processing this shadow, we can try again
                // TODO: probably there is a need to union current changes with previous
                ConstraintsChecker.onShadowModifyOperation(modifications);
                cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), modifications, result);
                result.recordHandledError("Modifications not applied to the object, because resource is unreachable. They are stored to the shadow and will be applied when the resource goes online.");
            }
            return shadow;
        case DELETE:
            cacheRepositoryService.deleteObject(shadow.getClass(), shadow.getOid(), result);
            result.recordStatus(OperationResultStatus.HANDLED_ERROR, "Object has been not created on the resource yet. Shadow deleted from the repository");
            return shadow;
        default:
            result.recordFatalError("Can't process " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
            if (shadow.getOid() == null) {
                throw new GenericFrameworkException("Can't process " + ObjectTypeUtil.toShortString(shadow) + ": " + ex.getMessage(), ex);
            }
            Collection<ItemDelta> modification = createAttemptModification(shadow, null);
            ConstraintsChecker.onShadowModifyOperation(modification);
            cacheRepositoryService.modifyObject(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), modification, parentResult);
            String message = "Can't process " + ObjectTypeUtil.toShortString(shadow) + ". ";
            result.recordFatalError(message, ex);
            throw new GenericFrameworkException(message, ex);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)165 Test (org.testng.annotations.Test)54 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)47 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)44 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)41 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)37 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)33 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)23 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)21 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QName (javax.xml.namespace.QName)16 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)15 SystemException (com.evolveum.midpoint.util.exception.SystemException)13