Search in sources :

Example 6 with OperationOptionsBuilder

use of org.identityconnectors.framework.common.objects.OperationOptionsBuilder in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method fetchChanges.

@Override
public List<Change> fetchChanges(ObjectClassComplexTypeDefinition objectClass, PrismProperty<?> lastToken, AttributesToReturn attrsToReturn, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchChanges");
    result.addContext("objectClass", objectClass);
    result.addParam("lastToken", lastToken);
    // create sync token from the property last token
    SyncToken syncToken = null;
    try {
        syncToken = getSyncToken(lastToken);
        LOGGER.trace("Sync token created from the property last token: {}", syncToken == null ? null : syncToken.getValue());
    } catch (SchemaException ex) {
        result.recordFatalError(ex.getMessage(), ex);
        throw new SchemaException(ex.getMessage(), ex);
    }
    final List<SyncDelta> syncDeltas = new ArrayList<SyncDelta>();
    // get icf object class
    ObjectClass icfObjectClass;
    if (objectClass == null) {
        icfObjectClass = ObjectClass.ALL;
    } else {
        icfObjectClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
    }
    OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
    if (objectClass != null) {
        convertToIcfAttrsToGet(objectClass, attrsToReturn, optionsBuilder);
    }
    OperationOptions options = optionsBuilder.build();
    SyncResultsHandler syncHandler = new SyncResultsHandler() {

        @Override
        public boolean handle(SyncDelta delta) {
            LOGGER.trace("Detected sync delta: {}", delta);
            return syncDeltas.add(delta);
        }
    };
    OperationResult connIdResult = result.createSubresult(ConnectorFacade.class.getName() + ".sync");
    connIdResult.addContext("connector", connIdConnectorFacade.getClass());
    connIdResult.addArbitraryObjectAsParam("connIdObjectClass", icfObjectClass);
    connIdResult.addArbitraryObjectAsParam("syncToken", syncToken);
    connIdResult.addArbitraryObjectAsParam("syncHandler", syncHandler);
    SyncToken lastReceivedToken;
    try {
        InternalMonitor.recordConnectorOperation("sync");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
        lastReceivedToken = connIdConnectorFacade.sync(icfObjectClass, syncToken, syncHandler, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass);
        connIdResult.recordSuccess();
        connIdResult.addReturn(OperationResult.RETURN_COUNT, syncDeltas.size());
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SYNC, objectClass, ex);
        Throwable midpointEx = processIcfException(ex, this, connIdResult);
        result.computeStatus();
        // exception
        if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            throw (SchemaException) midpointEx;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    // convert changes from icf to midpoint Change
    List<Change> changeList;
    try {
        changeList = getChangesFromSyncDeltas(icfObjectClass, syncDeltas, resourceSchema, result);
    } catch (SchemaException ex) {
        result.recordFatalError(ex.getMessage(), ex);
        throw new SchemaException(ex.getMessage(), ex);
    }
    if (lastReceivedToken != null) {
        Change lastChange = new Change((ObjectDelta) null, getToken(lastReceivedToken));
        LOGGER.trace("Adding last change: {}", lastChange);
        changeList.add(lastChange);
    }
    result.recordSuccess();
    result.addReturn(OperationResult.RETURN_COUNT, changeList == null ? 0 : changeList.size());
    return changeList;
}
Also used : OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) Change(com.evolveum.midpoint.provisioning.ucf.api.Change) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) SystemException(com.evolveum.midpoint.util.exception.SystemException) SyncResultsHandler(org.identityconnectors.framework.common.objects.SyncResultsHandler)

Example 7 with OperationOptionsBuilder

use of org.identityconnectors.framework.common.objects.OperationOptionsBuilder in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method executeScriptIcf.

private Object executeScriptIcf(StateReporter reporter, ExecuteProvisioningScriptOperation scriptOperation, OperationResult result) throws CommunicationException, GenericFrameworkException {
    String icfOpName = null;
    if (scriptOperation.isConnectorHost()) {
        icfOpName = "runScriptOnConnector";
    } else if (scriptOperation.isResourceHost()) {
        icfOpName = "runScriptOnResource";
    } else {
        result.recordFatalError("Where to execute the script?");
        throw new IllegalArgumentException("Where to execute the script?");
    }
    // convert execute script operation to the script context required from
    // the connector
    ScriptContext scriptContext = convertToScriptContext(scriptOperation);
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + "." + icfOpName);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    Object output = null;
    try {
        LOGGER.trace("Running script ({})", icfOpName);
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SCRIPT, null);
        if (scriptOperation.isConnectorHost()) {
            InternalMonitor.recordConnectorOperation("runScriptOnConnector");
            output = connIdConnectorFacade.runScriptOnConnector(scriptContext, new OperationOptionsBuilder().build());
        } else if (scriptOperation.isResourceHost()) {
            InternalMonitor.recordConnectorOperation("runScriptOnResource");
            output = connIdConnectorFacade.runScriptOnResource(scriptContext, new OperationOptionsBuilder().build());
        }
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null);
        icfResult.recordSuccess();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Finished running script ({}), script result: {}", icfOpName, PrettyPrinter.prettyPrint(output));
        }
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null, ex);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Finished running script ({}), ERROR: {}", icfOpName, ex.getMessage());
        }
        Throwable midpointEx = processIcfException(ex, this, icfResult);
        result.computeStatus();
        // exception
        if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            // Schema exception during delete? It must be a missing UID
            throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    return output;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ScriptContext(org.identityconnectors.framework.common.objects.ScriptContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject)

Example 8 with OperationOptionsBuilder

use of org.identityconnectors.framework.common.objects.OperationOptionsBuilder in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method deleteObject.

@Override
public AsynchronousOperationResult deleteObject(ObjectClassComplexTypeDefinition objectClass, Collection<Operation> additionalOperations, Collection<? extends ResourceAttribute<?>> identifiers, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException {
    Validate.notNull(objectClass, "No objectclass");
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".deleteObject");
    result.addCollectionOfSerializablesAsParam("identifiers", identifiers);
    ObjectClass objClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
    Uid uid;
    try {
        uid = getUid(objectClass, identifiers);
    } catch (SchemaException e) {
        result.recordFatalError(e);
        throw e;
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".delete");
    icfResult.addArbitraryObjectAsParam("uid", uid);
    icfResult.addArbitraryObjectAsParam("objectClass", objClass);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    try {
        InternalMonitor.recordConnectorOperation("delete");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_DELETE, objectClass, uid);
        connIdConnectorFacade.delete(objClass, uid, new OperationOptionsBuilder().build());
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, null, uid);
        icfResult.recordSuccess();
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, ex, uid);
        String desc = this.getHumanReadableName() + " while deleting object identified by ICF UID '" + uid.getUidValue() + "'";
        Throwable midpointEx = processIcfException(ex, desc, icfResult);
        result.computeStatus("Removing attribute values failed");
        // exception
        if (midpointEx instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) midpointEx;
        } else if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            // Schema exception during delete? It must be a missing UID
            throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
    result.computeStatus();
    return AsynchronousOperationResult.wrap(result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) Uid(org.identityconnectors.framework.common.objects.Uid) QualifiedUid(org.identityconnectors.framework.common.objects.QualifiedUid) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)8 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 OperationOptionsBuilder (org.identityconnectors.framework.common.objects.OperationOptionsBuilder)8 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)7 GuardedString (org.identityconnectors.common.security.GuardedString)6 OperationOptions (org.identityconnectors.framework.common.objects.OperationOptions)6 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)5 QualifiedUid (org.identityconnectors.framework.common.objects.QualifiedUid)5 Uid (org.identityconnectors.framework.common.objects.Uid)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 QName (javax.xml.namespace.QName)3 SyncResultsHandler (org.identityconnectors.framework.common.objects.SyncResultsHandler)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 Holder (com.evolveum.midpoint.util.Holder)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2