Search in sources :

Example 6 with Operation

use of com.evolveum.midpoint.provisioning.ucf.api.Operation in project midpoint by Evolveum.

the class AbstractModificationConverter method convert.

public void convert() throws SchemaException {
    PropertyDelta<QName> auxiliaryObjectClassDelta = determineAuxilaryObjectClassDelta(changes);
    ResourceObjectDefinition structuralObjectClassDefinition = resourceSchema.findDefinitionForObjectClass(objectDefinition.getTypeName());
    if (structuralObjectClassDefinition == null) {
        throw new SchemaException("No definition of structural object class " + objectDefinition.getTypeName() + " in " + connectorDescription);
    }
    Map<QName, ResourceObjectDefinition> auxiliaryObjectClassMap = new HashMap<>();
    if (auxiliaryObjectClassDelta != null) {
        // Auxiliary object class change means modification of __AUXILIARY_OBJECT_CLASS__ attribute
        collect(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME, auxiliaryObjectClassDelta, null, (pvals, midPointAttributeName) -> covertAuxiliaryObjectClassValuesToConnId(pvals, midPointAttributeName, auxiliaryObjectClassMap));
    }
    for (Operation operation : changes) {
        if (operation instanceof PropertyModificationOperation) {
            PropertyModificationOperation change = (PropertyModificationOperation) operation;
            PropertyDelta<?> delta = change.getPropertyDelta();
            if (delta.getParentPath().equivalent(ShadowType.F_ATTRIBUTES)) {
                if (delta.getDefinition() == null || !(delta.getDefinition() instanceof ResourceAttributeDefinition)) {
                    ResourceAttributeDefinition def = objectDefinition.findAttributeDefinition(delta.getElementName());
                    if (def == null) {
                        String message = "No definition for attribute " + delta.getElementName() + " used in modification delta";
                        throw new SchemaException(message);
                    }
                    try {
                        delta.applyDefinition(def);
                    } catch (SchemaException e) {
                        throw e;
                    }
                }
                PlusMinusZero isInModifiedAuxilaryClass = null;
                ResourceAttributeDefinition<?> structAttrDef = structuralObjectClassDefinition.findAttributeDefinition(delta.getElementName());
                // aux object class, we cannot add/remove it with the object class unless it is normally requested
                if (structAttrDef == null) {
                    if (auxiliaryObjectClassDelta != null && auxiliaryObjectClassDelta.isDelete()) {
                        // is removed, the attributes must be removed as well.
                        for (PrismPropertyValue<QName> auxPval : auxiliaryObjectClassDelta.getValuesToDelete()) {
                            ResourceObjectDefinition auxDef = auxiliaryObjectClassMap.get(auxPval.getValue());
                            ResourceAttributeDefinition<?> attrDef = auxDef.findAttributeDefinition(delta.getElementName());
                            if (attrDef != null) {
                                // means: is in removed auxiliary class
                                isInModifiedAuxilaryClass = PlusMinusZero.MINUS;
                                break;
                            }
                        }
                    }
                    if (auxiliaryObjectClassDelta != null && auxiliaryObjectClassDelta.isAdd()) {
                        // is added, the attributes must be added as well.
                        for (PrismPropertyValue<QName> auxPval : auxiliaryObjectClassDelta.getValuesToAdd()) {
                            ResourceObjectDefinition auxOcDef = auxiliaryObjectClassMap.get(auxPval.getValue());
                            ResourceAttributeDefinition<?> auxAttrDef = auxOcDef.findAttributeDefinition(delta.getElementName());
                            if (auxAttrDef != null) {
                                // means: is in added auxiliary class
                                isInModifiedAuxilaryClass = PlusMinusZero.PLUS;
                                break;
                            }
                        }
                    }
                }
                // Change in (ordinary) attributes. Transform to the ConnId attributes.
                String connIdAttrName = connIdNameMapper.convertAttributeNameToConnId(delta, objectDefinition);
                collect(connIdAttrName, delta, isInModifiedAuxilaryClass);
            } else if (delta.getParentPath().equivalent(ShadowType.F_ACTIVATION)) {
                convertFromActivation(delta);
            } else if (delta.getParentPath().equivalent(SchemaConstants.PATH_PASSWORD)) {
                convertFromPassword((PropertyDelta<ProtectedStringType>) delta);
            } else if (delta.getPath().equivalent(ShadowType.F_AUXILIARY_OBJECT_CLASS)) {
            // already processed
            } else {
                throw new SchemaException("Change of unknown attribute " + delta.getPath());
            }
        } else {
            throw new IllegalArgumentException("Unknown operation type " + operation.getClass().getName() + ": " + operation);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) Operation(com.evolveum.midpoint.provisioning.ucf.api.Operation) PropertyModificationOperation(com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation) GuardedString(org.identityconnectors.common.security.GuardedString) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) PropertyModificationOperation(com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Aggregations

Operation (com.evolveum.midpoint.provisioning.ucf.api.Operation)6 PropertyModificationOperation (com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 QName (javax.xml.namespace.QName)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ExecuteProvisioningScriptOperation (com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation)2 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)2 PasswordChangeOperation (com.evolveum.midpoint.provisioning.ucf.api.PasswordChangeOperation)2 ConnectorTestOperation (com.evolveum.midpoint.schema.constants.ConnectorTestOperation)2 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)2 ProvisioningOperation (com.evolveum.midpoint.schema.statistics.ProvisioningOperation)2 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)2 GuardedString (org.identityconnectors.common.security.GuardedString)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PlusMinusZero (com.evolveum.midpoint.prism.delta.PlusMinusZero)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 GenericConnectorException (com.evolveum.midpoint.provisioning.api.GenericConnectorException)1