Search in sources :

Example 56 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition 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)

Example 57 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class AbstractModificationConverter method covertAuxiliaryObjectClassValuesToConnId.

private <T> List<Object> covertAuxiliaryObjectClassValuesToConnId(Collection<PrismPropertyValue<QName>> pvals, QName midPointAttributeName, Map<QName, ResourceObjectDefinition> auxiliaryObjectClassMap) throws SchemaException {
    List<Object> connIdVals = new ArrayList<>(pvals.size());
    for (PrismPropertyValue<QName> pval : pvals) {
        QName auxQName = pval.getValue();
        ResourceObjectDefinition auxDef = resourceSchema.findDefinitionForObjectClass(auxQName);
        if (auxDef == null) {
            throw new SchemaException("Auxiliary object class " + auxQName + " not found in the schema");
        }
        auxiliaryObjectClassMap.put(auxQName, auxDef);
        ObjectClass icfOc = connIdNameMapper.objectClassToConnId(pval.getValue(), connectorType, false);
        connIdVals.add(icfOc.getObjectClassValue());
    }
    return connIdVals;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName)

Example 58 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class SyncDeltaConverter method getActualObjectDefinition.

@Nullable
private ResourceObjectDefinition getActualObjectDefinition(SyncDelta connIdDelta) throws SchemaException {
    if (requestedObjectDefinition != null) {
        return requestedObjectDefinition;
    }
    ObjectClass deltaConnIdObjectClass = connIdDelta.getObjectClass();
    QName deltaObjectClassName = nameMapper.objectClassToQname(deltaConnIdObjectClass, connectorInstance.isLegacySchema());
    ResourceObjectDefinition deltaObjectClass;
    if (deltaConnIdObjectClass != null) {
        deltaObjectClass = (ResourceObjectClassDefinition) connectorInstance.getRawResourceSchema().findComplexTypeDefinitionByType(deltaObjectClassName);
    } else {
        deltaObjectClass = null;
    }
    if (deltaObjectClass == null) {
        if (connIdDelta.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 " + deltaObjectClassName + " (" + deltaConnIdObjectClass + ") that has no definition in resource schema");
        }
    }
    return deltaObjectClass;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class SyncDeltaConverter method createChange.

@NotNull
UcfLiveSyncChange createChange(int localSequenceNumber, SyncDelta connIdDelta, OperationResult result) {
    // The following should not throw any exception. And if it does, we are lost anyway, because
    // we need this information to create even "errored" change object.
    // For non-nullability of these variables see the code of SyncDelta.
    @NotNull SyncDeltaType icfDeltaType = connIdDelta.getDeltaType();
    @NotNull Uid uid = connIdDelta.getUid();
    @NotNull String uidValue = uid.getUidValue();
    @NotNull UcfSyncToken token = toUcf(connIdDelta.getToken());
    Collection<ResourceAttribute<?>> identifiers = new ArrayList<>();
    ResourceObjectDefinition actualObjectDefinition = null;
    ObjectDelta<ShadowType> objectDelta = null;
    PrismObject<ShadowType> resourceObject = null;
    LOGGER.trace("START creating delta of type {}", icfDeltaType);
    UcfErrorState errorState;
    try {
        actualObjectDefinition = getActualObjectDefinition(connIdDelta);
        assert actualObjectDefinition != null || icfDeltaType == SyncDeltaType.DELETE;
        if (icfDeltaType == SyncDeltaType.DELETE) {
            identifiers.addAll(ConnIdUtil.convertToIdentifiers(uid, actualObjectDefinition, connectorInstance.getRawResourceSchema()));
            objectDelta = prismContext.deltaFactory().object().create(ShadowType.class, ChangeType.DELETE);
        } else if (icfDeltaType == SyncDeltaType.CREATE || icfDeltaType == SyncDeltaType.CREATE_OR_UPDATE || icfDeltaType == SyncDeltaType.UPDATE) {
            PrismObjectDefinition<ShadowType> objectDefinition = toShadowDefinition(actualObjectDefinition);
            LOGGER.trace("Object definition: {}", objectDefinition);
            // We can consider using "fetch result" error reporting method here, and go along with a partial object.
            resourceObject = connIdConvertor.convertToUcfObject(connIdDelta.getObject(), objectDefinition, false, connectorInstance.isCaseIgnoreAttributeNames(), connectorInstance.isLegacySchema(), UcfFetchErrorReportingMethod.EXCEPTION, result).getResourceObject();
            LOGGER.trace("Got (current) resource object: {}", resourceObject.debugDumpLazily());
            identifiers.addAll(emptyIfNull(ShadowUtil.getAllIdentifiers(resourceObject)));
            if (icfDeltaType == SyncDeltaType.CREATE) {
                objectDelta = prismContext.deltaFactory().object().create(ShadowType.class, ChangeType.ADD);
                objectDelta.setObjectToAdd(resourceObject);
            }
        } else {
            throw new GenericFrameworkException("Unexpected sync delta type " + icfDeltaType);
        }
        if (identifiers.isEmpty()) {
            throw new SchemaException("No identifiers in sync delta " + connIdDelta);
        }
        errorState = UcfErrorState.success();
    } catch (Exception e) {
        result.recordFatalError(e);
        errorState = UcfErrorState.error(e);
    }
    UcfLiveSyncChange change = new UcfLiveSyncChange(localSequenceNumber, uidValue, identifiers, actualObjectDefinition, objectDelta, resourceObject, token, errorState);
    LOGGER.trace("END creating change of type {}:\n{}", icfDeltaType, change.debugDumpLazily());
    return change;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SyncDeltaType(org.identityconnectors.framework.common.objects.SyncDeltaType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Uid(org.identityconnectors.framework.common.objects.Uid) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) NotNull(org.jetbrains.annotations.NotNull)

Example 60 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class RefinedResourceSchemaAsserter method objectClass.

public ResourceObjectDefinitionAsserter<RefinedResourceSchemaAsserter<RA>> objectClass(String ocName) {
    ResourceObjectDefinition objectClassDefinition = getSchema().findDefinitionForObjectClass(new QName(MidPointConstants.NS_RI, ocName));
    ResourceObjectDefinitionAsserter<RefinedResourceSchemaAsserter<RA>> asserter = new ResourceObjectDefinitionAsserter<>(objectClassDefinition, this, desc());
    copySetupTo(asserter);
    return asserter;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) QName(javax.xml.namespace.QName)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2