Search in sources :

Example 1 with SyncDeltaType

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

the class ConnectorInstanceConnIdImpl method getChangesFromSyncDeltas.

private List<Change> getChangesFromSyncDeltas(ObjectClass connIdObjClass, Collection<SyncDelta> connIdDeltas, PrismSchema schema, OperationResult parentResult) throws SchemaException, GenericFrameworkException {
    List<Change> changeList = new ArrayList<Change>();
    QName objectClass = connIdNameMapper.objectClassToQname(connIdObjClass, getSchemaNamespace(), legacySchema);
    ObjectClassComplexTypeDefinition objClassDefinition = null;
    if (objectClass != null) {
        objClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(objectClass);
    }
    Validate.notNull(connIdDeltas, "Sync result must not be null.");
    for (SyncDelta icfDelta : connIdDeltas) {
        ObjectClass deltaIcfObjClass = connIdObjClass;
        QName deltaObjectClass = objectClass;
        ObjectClassComplexTypeDefinition deltaObjClassDefinition = objClassDefinition;
        if (objectClass == null) {
            deltaIcfObjClass = icfDelta.getObjectClass();
            deltaObjectClass = connIdNameMapper.objectClassToQname(deltaIcfObjClass, getSchemaNamespace(), legacySchema);
            if (deltaIcfObjClass != null) {
                deltaObjClassDefinition = (ObjectClassComplexTypeDefinition) schema.findComplexTypeDefinition(deltaObjectClass);
            }
        }
        if (deltaObjClassDefinition == null) {
            if (icfDelta.getDeltaType() == SyncDeltaType.DELETE) {
            // tolerate this. E.g. LDAP changelogs do not have objectclass in delete deltas.
            } else {
                throw new SchemaException("Got delta with object class " + deltaObjectClass + " (" + deltaIcfObjClass + ") that has no definition in resource schema");
            }
        }
        SyncDeltaType icfDeltaType = icfDelta.getDeltaType();
        if (SyncDeltaType.DELETE.equals(icfDeltaType)) {
            LOGGER.trace("START creating delta of type DELETE");
            ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.DELETE, prismContext);
            Collection<ResourceAttribute<?>> identifiers = ConnIdUtil.convertToIdentifiers(icfDelta.getUid(), deltaObjClassDefinition, resourceSchema);
            Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type DELETE");
        } else if (SyncDeltaType.CREATE.equals(icfDeltaType)) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            LOGGER.trace("START creating delta of type CREATE");
            PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
            }
            Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
            ObjectDelta<ShadowType> objectDelta = new ObjectDelta<ShadowType>(ShadowType.class, ChangeType.ADD, prismContext);
            objectDelta.setObjectToAdd(currentShadow);
            Change change = new Change(identifiers, objectDelta, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type CREATE");
        } else if (SyncDeltaType.CREATE_OR_UPDATE.equals(icfDeltaType) || SyncDeltaType.UPDATE.equals(icfDeltaType)) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(deltaObjClassDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            LOGGER.trace("START creating delta of type {}", icfDeltaType);
            PrismObject<ShadowType> currentShadow = connIdConvertor.convertToResourceObject(icfDelta.getObject(), objectDefinition, false, caseIgnoreAttributeNames, legacySchema);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Got current shadow: {}", currentShadow.debugDump());
            }
            Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getAllIdentifiers(currentShadow);
            Change change = new Change(identifiers, currentShadow, getToken(icfDelta.getToken()));
            change.setObjectClassDefinition(deltaObjClassDefinition);
            changeList.add(change);
            LOGGER.trace("END creating delta of type {}:\n{}", icfDeltaType, change.debugDump());
        } else {
            throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
        }
    }
    return changeList;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) SyncDeltaType(org.identityconnectors.framework.common.objects.SyncDeltaType) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Change(com.evolveum.midpoint.provisioning.ucf.api.Change) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 Change (com.evolveum.midpoint.provisioning.ucf.api.Change)1 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 QName (javax.xml.namespace.QName)1 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)1 SyncDelta (org.identityconnectors.framework.common.objects.SyncDelta)1 SyncDeltaType (org.identityconnectors.framework.common.objects.SyncDeltaType)1