Search in sources :

Example 1 with SyncToken

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

the class ConnectorInstanceConnIdImpl method getSyncToken.

private SyncToken getSyncToken(PrismProperty tokenProperty) throws SchemaException {
    if (tokenProperty == null) {
        return null;
    }
    if (tokenProperty.getValues() == null) {
        return null;
    }
    if (tokenProperty.getValues().isEmpty()) {
        return null;
    }
    if (tokenProperty.getValues().size() > 1) {
        throw new SchemaException("Unexpected number of attributes in SyncToken. SyncToken is single-value attribute and can contain only one value.");
    }
    Object tokenValue = tokenProperty.getAnyRealValue();
    if (tokenValue == null) {
        return null;
    }
    SyncToken syncToken = new SyncToken(tokenValue);
    return syncToken;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject)

Example 2 with SyncToken

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

the class ConnectorInstanceConnIdImpl method fetchCurrentToken.

@Override
public <T> PrismProperty<T> fetchCurrentToken(ObjectClassComplexTypeDefinition objectClassDef, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException {
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchCurrentToken");
    result.addParam("objectClass", objectClassDef);
    ObjectClass icfObjectClass;
    if (objectClassDef == null) {
        icfObjectClass = ObjectClass.ALL;
    } else {
        icfObjectClass = connIdNameMapper.objectClassToIcf(objectClassDef, getSchemaNamespace(), connectorType, legacySchema);
    }
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".sync");
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    icfResult.addArbitraryObjectAsParam("icfObjectClass", icfObjectClass);
    SyncToken syncToken = null;
    try {
        InternalMonitor.recordConnectorOperation("getLatestSyncToken");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET_LATEST_SYNC_TOKEN, objectClassDef);
        syncToken = connIdConnectorFacade.getLatestSyncToken(icfObjectClass);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_LATEST_SYNC_TOKEN, objectClassDef);
        icfResult.recordSuccess();
        icfResult.addReturn("syncToken", syncToken == null ? null : String.valueOf(syncToken.getValue()));
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET_LATEST_SYNC_TOKEN, objectClassDef, ex);
        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 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);
        }
    }
    if (syncToken == null) {
        result.recordWarning("Resource have not provided a current sync token");
        return null;
    }
    PrismProperty<T> property = getToken(syncToken);
    result.recordSuccess();
    return property;
}
Also used : SyncToken(org.identityconnectors.framework.common.objects.SyncToken) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SystemException(com.evolveum.midpoint.util.exception.SystemException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult)

Example 3 with SyncToken

use of org.identityconnectors.framework.common.objects.SyncToken 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)

Aggregations

SyncToken (org.identityconnectors.framework.common.objects.SyncToken)3 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)2 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)2 Change (com.evolveum.midpoint.provisioning.ucf.api.Change)1 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)1 OperationOptions (org.identityconnectors.framework.common.objects.OperationOptions)1 OperationOptionsBuilder (org.identityconnectors.framework.common.objects.OperationOptionsBuilder)1 SyncDelta (org.identityconnectors.framework.common.objects.SyncDelta)1 SyncResultsHandler (org.identityconnectors.framework.common.objects.SyncResultsHandler)1