Search in sources :

Example 11 with ConnIdOperation

use of com.evolveum.midpoint.schema.reporting.ConnIdOperation in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method modifyObjectDelta.

/**
 * Modifies object by using new delta update operations.
 */
private AsynchronousOperationReturnValue<Collection<PropertyModificationOperation>> modifyObjectDelta(ResourceObjectIdentification identification, ObjectClass objClass, Uid uid, PrismObject<ShadowType> shadow, Collection<Operation> changes, ConnectorOperationOptions options, UcfExecutionContext reporter, OperationResult result) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, SecurityViolationException, PolicyViolationException, ObjectAlreadyExistsException {
    ResourceObjectDefinition objectClassDef = identification.getResourceObjectDefinition();
    DeltaModificationConverter converter = new DeltaModificationConverter();
    converter.setChanges(changes);
    converter.setConnectorDescription(description);
    converter.setConnectorType(connectorType);
    converter.setConnIdNameMapper(connIdNameMapper);
    converter.setObjectDefinition(objectClassDef);
    converter.setProtector(protector);
    converter.setResourceSchema(rawResourceSchema);
    converter.setOptions(options);
    try {
        converter.convert();
    } catch (SchemaException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    LOGGER.trace("converted attributesDelta:\n {}", converter.debugDumpLazily(1));
    OperationResult connIdResult;
    // May or may not cover all executed changes
    @NotNull Set<AttributeDelta> knownExecutedChanges;
    Set<AttributeDelta> attributesDelta = converter.getAttributesDelta();
    if (!attributesDelta.isEmpty()) {
        OperationOptions connIdOptions = createConnIdOptions(options, changes);
        connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".updateDelta");
        connIdResult.addParam("objectClass", objectClassDef.toString());
        connIdResult.addParam("uid", uid.getUidValue());
        connIdResult.addParam("attributesDelta", attributesDelta.toString());
        connIdResult.addArbitraryObjectAsParam("options", connIdOptions);
        connIdResult.addContext("connector", connIdConnectorFacade.getClass());
        InternalMonitor.recordConnectorOperation("update");
        InternalMonitor.recordConnectorModification("update");
        ConnIdOperation operation = recordIcfOperationStart(reporter, ProvisioningOperation.ICF_UPDATE, objectClassDef, uid);
        LOGGER.trace("Invoking ICF update(), objectclass={}, uid={}, operation id={}, attributes delta: {}", objClass, uid, getIdentifier(operation), lazy(() -> dumpAttributesDelta(attributesDelta)));
        try {
            knownExecutedChanges = emptyIfNull(connIdConnectorFacade.updateDelta(objClass, uid, attributesDelta, connIdOptions));
            recordIcfOperationEnd(reporter, operation, null);
            connIdResult.recordSuccess();
        } catch (Throwable ex) {
            recordIcfOperationEnd(reporter, operation, ex);
            String desc = this.getHumanReadableName() + " while updating object identified by ConnId UID '" + uid.getUidValue() + "'";
            Throwable midpointEx = processConnIdException(ex, desc, connIdResult);
            result.computeStatus("Update failed");
            // exception
            if (midpointEx instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) midpointEx;
            } else if (midpointEx instanceof CommunicationException) {
                // in this situation this is not a critical error, becasue we know to handle it..so mute the error and sign it as expected
                result.muteError();
                connIdResult.muteError();
                throw (CommunicationException) midpointEx;
            } else if (midpointEx instanceof GenericFrameworkException) {
                throw (GenericFrameworkException) midpointEx;
            } else if (midpointEx instanceof SchemaException) {
                throw (SchemaException) midpointEx;
            } else if (midpointEx instanceof ObjectAlreadyExistsException) {
                throw (ObjectAlreadyExistsException) midpointEx;
            } else if (midpointEx instanceof RuntimeException) {
                throw (RuntimeException) midpointEx;
            } else if (midpointEx instanceof SecurityViolationException) {
                throw (SecurityViolationException) midpointEx;
            } else if (midpointEx instanceof PolicyViolationException) {
                throw (PolicyViolationException) midpointEx;
            } else if (midpointEx instanceof Error) {
                throw (Error) midpointEx;
            } else {
                throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
            }
        }
    } else {
        knownExecutedChanges = emptySet();
    }
    result.computeStatus();
    Collection<PropertyModificationOperation> knownExecutedOperations = convertToExecutedOperations(knownExecutedChanges, identification, objectClassDef);
    return AsynchronousOperationReturnValue.wrap(knownExecutedOperations, result);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) NotNull(org.jetbrains.annotations.NotNull) ConnIdOperation(com.evolveum.midpoint.schema.reporting.ConnIdOperation) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade)

Aggregations

ConnIdOperation (com.evolveum.midpoint.schema.reporting.ConnIdOperation)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)9 GuardedString (org.identityconnectors.common.security.GuardedString)8 ConnectorFacade (org.identityconnectors.framework.api.ConnectorFacade)4 NotNull (org.jetbrains.annotations.NotNull)3 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 Holder (com.evolveum.midpoint.util.Holder)2 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 QName (javax.xml.namespace.QName)2 Filter (org.identityconnectors.framework.common.objects.filter.Filter)2 LocalizationService (com.evolveum.midpoint.common.LocalizationService)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 Protector (com.evolveum.midpoint.prism.crypto.Protector)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)1