Search in sources :

Example 1 with DummyDelta

use of com.evolveum.icf.dummy.resource.DummyDelta in project midpoint by Evolveum.

the class DummyConnector method sync.

/**
     * {@inheritDoc}
     */
public void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, final OperationOptions options) {
    log.info("sync::begin");
    validate(objectClass);
    Collection<String> attributesToGet = getAttrsToGet(options);
    try {
        int syncToken = (Integer) token.getValue();
        List<DummyDelta> deltas = resource.getDeltasSince(syncToken);
        for (DummyDelta delta : deltas) {
            Class<? extends DummyObject> deltaObjectClass = delta.getObjectClass();
            if (objectClass.is(ObjectClass.ALL_NAME)) {
            // take all changes
            } else if (objectClass.is(ObjectClass.ACCOUNT_NAME)) {
                if (deltaObjectClass != DummyAccount.class) {
                    log.ok("Skipping delta {0} because of objectclass mismatch", delta);
                    continue;
                }
            } else if (objectClass.is(ObjectClass.GROUP_NAME)) {
                if (deltaObjectClass != DummyGroup.class) {
                    log.ok("Skipping delta {0} because of objectclass mismatch", delta);
                    continue;
                }
            }
            SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder();
            if (deltaObjectClass == DummyAccount.class) {
                deltaBuilder.setObjectClass(ObjectClass.ACCOUNT);
            } else if (deltaObjectClass == DummyGroup.class) {
                deltaBuilder.setObjectClass(ObjectClass.GROUP);
            } else if (deltaObjectClass == DummyPrivilege.class) {
                deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_PRIVILEGE_NAME));
            } else if (deltaObjectClass == DummyOrg.class) {
                deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_ORG_NAME));
            } else {
                throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
            }
            SyncDeltaType deltaType;
            if (delta.getType() == DummyDeltaType.ADD || delta.getType() == DummyDeltaType.MODIFY) {
                if (resource.getSyncStyle() == DummySyncStyle.DUMB) {
                    deltaType = SyncDeltaType.CREATE_OR_UPDATE;
                } else {
                    if (delta.getType() == DummyDeltaType.ADD) {
                        deltaType = SyncDeltaType.CREATE;
                    } else {
                        deltaType = SyncDeltaType.UPDATE;
                    }
                }
                if (deltaObjectClass == DummyAccount.class) {
                    DummyAccount account = resource.getAccountById(delta.getObjectId());
                    if (account == null) {
                        throw new IllegalStateException("We have delta for account '" + delta.getObjectId() + "' but such account does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(account, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else if (deltaObjectClass == DummyGroup.class) {
                    DummyGroup group = resource.getGroupById(delta.getObjectId());
                    if (group == null) {
                        throw new IllegalStateException("We have delta for group '" + delta.getObjectId() + "' but such group does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(group, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else if (deltaObjectClass == DummyPrivilege.class) {
                    DummyPrivilege privilege = resource.getPrivilegeById(delta.getObjectId());
                    if (privilege == null) {
                        throw new IllegalStateException("We have privilege for group '" + delta.getObjectId() + "' but such privilege does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(privilege, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else {
                    throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
                }
            } else if (delta.getType() == DummyDeltaType.DELETE) {
                deltaType = SyncDeltaType.DELETE;
            } else {
                throw new IllegalStateException("Unknown delta type " + delta.getType());
            }
            deltaBuilder.setDeltaType(deltaType);
            deltaBuilder.setToken(new SyncToken(delta.getSyncToken()));
            Uid uid;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                uid = new Uid(delta.getObjectName());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                if (nameHintChecksEnabled()) {
                    uid = new Uid(delta.getObjectId(), new Name(delta.getObjectName()));
                } else {
                    uid = new Uid(delta.getObjectId());
                }
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            deltaBuilder.setUid(uid);
            SyncDelta syncDelta = deltaBuilder.build();
            log.info("sync::handle {0}", syncDelta);
            handler.handle(syncDelta);
        }
    } catch (ConnectException e) {
        log.info("sync::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("sync::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("sync::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("sync::exception " + e);
        throw new AlreadyExistsException(e);
    }
    log.info("sync::end");
}
Also used : ConflictException(com.evolveum.icf.dummy.resource.ConflictException) DummyDelta(com.evolveum.icf.dummy.resource.DummyDelta) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException)

Aggregations

ConflictException (com.evolveum.icf.dummy.resource.ConflictException)1 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1 DummyDelta (com.evolveum.icf.dummy.resource.DummyDelta)1 DummyGroup (com.evolveum.icf.dummy.resource.DummyGroup)1 DummyObjectClass (com.evolveum.icf.dummy.resource.DummyObjectClass)1 DummyOrg (com.evolveum.icf.dummy.resource.DummyOrg)1 DummyPrivilege (com.evolveum.icf.dummy.resource.DummyPrivilege)1 ObjectAlreadyExistsException (com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException)1 SchemaViolationException (com.evolveum.icf.dummy.resource.SchemaViolationException)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 GuardedString (org.identityconnectors.common.security.GuardedString)1 AlreadyExistsException (org.identityconnectors.framework.common.exceptions.AlreadyExistsException)1 ConnectionFailedException (org.identityconnectors.framework.common.exceptions.ConnectionFailedException)1 ConnectorIOException (org.identityconnectors.framework.common.exceptions.ConnectorIOException)1 InvalidAttributeValueException (org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException)1