Search in sources :

Example 26 with ResourceAttributeDefinition

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

the class ShadowUpdater method extractRepoShadowChanges.

@SuppressWarnings("rawtypes")
@NotNull
private Collection<? extends ItemDelta<?, ?>> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    // If type is not present, OC def is fine
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    Collection<ItemDelta<?, ?>> repoChanges = new ArrayList<>();
    for (ItemDelta itemDelta : objectChange) {
        if (ShadowType.F_ATTRIBUTES.equivalent(itemDelta.getParentPath())) {
            QName attrName = itemDelta.getElementName();
            if (objectDefinition.isSecondaryIdentifier(attrName) || (objectDefinition.getAllIdentifiers().size() == 1 && objectDefinition.isPrimaryIdentifier(attrName))) {
                // Change of secondary identifier, or primary identifier when it is only one, means object rename. We also need to change $shadow/name
                // TODO: change this to displayName attribute later
                String newName = null;
                if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
                } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
                }
                PropertyDelta<PolyString> nameDelta = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
                repoChanges.add(nameDelta);
            }
            if (objectDefinition.isPrimaryIdentifier(attrName)) {
                // Change of primary identifier $shadow/primaryIdentifier.
                String newPrimaryIdentifier = null;
                if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
                    newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
                } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
                    newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
                }
                ResourceAttribute<String> primaryIdentifier = helper.getPrimaryIdentifier(shadow);
                // noinspection unchecked
                ResourceAttributeDefinition<String> rDef = (ResourceAttributeDefinition<String>) objectDefinition.findAttributeDefinitionRequired(primaryIdentifier.getElementName());
                String normalizedNewPrimaryIdentifier = helper.getNormalizedAttributeValue(rDef, newPrimaryIdentifier);
                PropertyDelta<String> primaryIdentifierDelta = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_PRIMARY_IDENTIFIER_VALUE, normalizedNewPrimaryIdentifier);
                repoChanges.add(primaryIdentifierDelta);
            }
            if (!ProvisioningUtil.shouldStoreAttributeInShadow(objectDefinition, attrName, cachingStrategy)) {
                continue;
            }
        } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getParentPath())) {
            if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
                continue;
            }
        } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getPath())) {
            // should not occur, but for completeness...
            if (((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd() != null) {
                for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
                    ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
                }
            }
            if (((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace() != null) {
                for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
                    ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
                }
            }
        } else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            addPasswordDelta(repoChanges, itemDelta, objectDefinition);
            continue;
        }
        helper.normalizeDelta(itemDelta, objectDefinition);
        repoChanges.add(itemDelta);
    }
    return repoChanges;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with ResourceAttributeDefinition

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

the class ShadowCaretaker method applyAttributeDefinition.

private <V extends PrismValue, D extends ItemDefinition> void applyAttributeDefinition(ProvisioningContext ctx, ObjectDelta<ShadowType> delta, ItemDelta<V, D> itemDelta) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    if (!SchemaConstants.PATH_ATTRIBUTES.equivalent(itemDelta.getParentPath())) {
        // just to be sure
        return;
    }
    D itemDef = itemDelta.getDefinition();
    if (!(itemDef instanceof ResourceAttributeDefinition)) {
        QName attributeName = itemDelta.getElementName();
        ResourceAttributeDefinition<?> attributeDefinition = ctx.findAttributeDefinitionRequired(attributeName, () -> " in object delta " + delta);
        if (itemDef != null) {
            // some basic checks first
            if (!QNameUtil.match(itemDef.getTypeName(), attributeDefinition.getTypeName())) {
                throw new SchemaException("The value of type " + itemDef.getTypeName() + " cannot be applied to attribute " + attributeName + " which is of type " + attributeDefinition.getTypeName());
            }
        }
        // noinspection unchecked
        itemDelta.applyDefinition((D) attributeDefinition);
    }
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName)

Example 28 with ResourceAttributeDefinition

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

the class ShadowIntegrityCheckItemProcessor method checkShadow.

private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
    ShadowCheckConfiguration cfg = activityRun.getConfiguration();
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = shadowType.getResourceRef();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
    }
    getStats().incrementShadows();
    if (resourceRef == null) {
        checkResult.recordError(ShadowStatistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
        fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    String resourceOid = resourceRef.getOid();
    if (resourceOid == null) {
        checkResult.recordError(ShadowStatistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
        fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    PrismObject<ResourceType> resource = getCachedResource(resourceOid);
    if (resource == null) {
        getStats().incrementResources();
        try {
            resource = getProvisioningService().getObject(ResourceType.class, resourceOid, null, workerTask, result);
        } catch (ObjectNotFoundException e) {
            checkResult.recordError(ShadowStatistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
            fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE);
            applyFixes(checkResult, shadow, workerTask, result);
            return;
        } catch (SchemaException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
            return;
        } catch (CommonException | RuntimeException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
            return;
        }
        cacheResource(resource);
    }
    checkResult.setResource(resource);
    ShadowKindType kind = shadowType.getKind();
    if (kind == null) {
        // TODO or simply assume account?
        checkResult.recordError(ShadowStatistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
        return;
    }
    if (cfg.checkExtraData) {
        checkOrFixShadowActivationConsistency(checkResult, shadow);
    }
    PrismObject<ShadowType> fetchedShadow = null;
    if (cfg.checkFetch) {
        fetchedShadow = fetchShadow(checkResult, shadow, workerTask, result);
        if (fetchedShadow != null) {
            shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
        }
    }
    if (cfg.checkOwners) {
        List<PrismObject<FocusType>> owners = activityRun.searchOwners(shadow, result);
        if (owners != null) {
            shadow.setUserData(KEY_OWNERS, owners);
            if (owners.size() > 1) {
                checkResult.recordError(ShadowStatistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
            }
        }
        if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
            checkResult.recordError(ShadowStatistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
        }
        if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
            checkResult.recordError(ShadowStatistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
        }
    }
    String intent = shadowType.getIntent();
    if (cfg.checkIntents && (intent == null || intent.isEmpty())) {
        checkResult.recordWarning(ShadowStatistics.NO_INTENT_SPECIFIED, "None or empty intent");
    }
    if (cfg.fixIntents && (intent == null || intent.isEmpty())) {
        doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
    }
    QName objectClassName = shadowType.getObjectClass();
    if (objectClassName == null) {
        checkResult.recordError(ShadowStatistics.NO_OBJECT_CLASS_SPECIFIED, new SchemaException("No object class specified"));
        return;
    }
    ContextMapKey key = new ContextMapKey(resourceOid, objectClassName);
    ObjectTypeContext context = activityRun.getObjectTypeContext(key);
    if (context == null) {
        context = new ObjectTypeContext();
        context.setResource(resource);
        ResourceSchema refinedSchema;
        try {
            refinedSchema = ResourceSchemaFactory.getCompleteSchema(context.getResource(), LayerType.MODEL);
        } catch (SchemaException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
            return;
        }
        if (refinedSchema == null) {
            checkResult.recordError(ShadowStatistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
            return;
        }
        ResourceObjectDefinition objectDefinition = refinedSchema.findObjectDefinition(kind, ShadowUtil.getIntent(shadow));
        if (objectDefinition instanceof ResourceObjectTypeDefinition) {
            context.setObjectTypeDefinition((ResourceObjectTypeDefinition) objectDefinition);
        } else {
            // TODO or warning only?
            checkResult.recordError(ShadowStatistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
            return;
        }
        activityRun.putObjectTypeContext(key, context);
    }
    try {
        getProvisioningService().applyDefinition(shadow, workerTask, result);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
        return;
    }
    Set<ResourceAttributeDefinition<?>> identifiers = new HashSet<>();
    Collection<? extends ResourceAttributeDefinition<?>> primaryIdentifiers = context.getObjectTypeDefinition().getPrimaryIdentifiers();
    identifiers.addAll(primaryIdentifiers);
    identifiers.addAll(context.getObjectTypeDefinition().getSecondaryIdentifiers());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // might happen on unfinished shadows?
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("No attributes container"));
        return;
    }
    for (ResourceAttributeDefinition<?> identifier : identifiers) {
        PrismProperty<String> property = attributesContainer.getValue().findProperty(identifier.getItemName());
        if (property == null || property.size() == 0) {
            checkResult.recordWarning(ShadowStatistics.OTHER_FAILURE, "No value for identifier " + identifier.getItemName());
            continue;
        }
        if (property.size() > 1) {
            // we don't expect multi-valued identifiers
            checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getItemName() + " with values " + property.getValues()));
            continue;
        }
        // size == 1
        String value = property.getValue().getValue();
        if (value == null) {
            checkResult.recordWarning(ShadowStatistics.OTHER_FAILURE, "Null value for identifier " + identifier.getItemName());
            continue;
        }
        if (cfg.checkUniqueness) {
            if (!cfg.checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
                addIdentifierValue(context, identifier.getItemName(), value, shadow);
            }
        }
        if (cfg.checkNormalization) {
            doCheckNormalization(checkResult, identifier, value);
        }
    }
    applyFixes(checkResult, shadow, workerTask, result);
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) QName(javax.xml.namespace.QName) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)

Example 29 with ResourceAttributeDefinition

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

the class DotModel method exportDot.

public String exportDot() {
    StringBuilder sb = new StringBuilder();
    sb.append("digraph G {\n");
    Set<DataItem> itemsShown = new HashSet<>();
    int clusterNumber = 1;
    int indent = 1;
    for (PrismObject<ResourceType> resource : dataModel.getResources().values()) {
        if (subgraphsForResources) {
            sb.append(indent(indent)).append("subgraph cluster_").append(clusterNumber++).append(" {\n");
            sb.append(indent(indent + 1)).append("label=\"").append(resource.getName()).append("\";\n");
            // TODO style for resource label
            indent++;
        }
        ResourceSchema schema = dataModel.getRefinedResourceSchema(resource.getOid());
        for (ResourceObjectTypeDefinition def : schema.getObjectTypeDefinitions()) {
            StringBuilder sb1 = new StringBuilder();
            sb1.append(indent(indent)).append("subgraph cluster_").append(clusterNumber++).append(" {\n");
            String typeName = "";
            if (!subgraphsForResources && dataModel.getResources().size() > 1) {
                typeName = PolyString.getOrig(resource.getName()) + LF;
            }
            typeName += getObjectTypeName(def, true);
            sb1.append(indent(indent + 1)).append("label=\"").append(typeName).append("\";\n");
            sb1.append(indent(indent + 1)).append("fontname=\"times-bold\";\n\n");
            String previousNodeName = null;
            indent++;
            for (ResourceAttributeDefinition attrDef : def.getAttributeDefinitions()) {
                if (attrDef.isIgnored()) {
                    continue;
                }
                ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), attrDef.getItemName());
                previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
            }
            for (ResourceAssociationDefinition assocDef : def.getAssociationDefinitions()) {
                if (assocDef.isIgnored()) {
                    continue;
                }
                ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), assocDef.getName());
                previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
            }
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_ACTIVATION, DataModelVisualizerImpl.ACTIVATION_EXISTENCE)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), ItemPath.create(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
            indent--;
            sb1.append(indent(indent)).append("}\n");
            if (previousNodeName != null) {
                sb.append(sb1.toString());
            }
        }
        if (subgraphsForResources) {
            sb.append(indent(indent)).append("}\n");
            indent--;
        }
    }
    sb.append("\n");
    int mappingNode = 1;
    for (Relation relation : dataModel.getRelations()) {
        showNodesIfNeeded(sb, indent, itemsShown, relation.getSources());
        showNodeIfNeeded(sb, indent, itemsShown, relation.getTarget());
        DotRelation dotRelation = getDotRelation(relation);
        if (relation.getSources().size() == 1 && relation.getTarget() != null) {
            DataItem sourceItem = relation.getSources().get(0);
            DataItem targetItem = relation.getTarget();
            DotDataItem dotSourceItem = getDotDataItem(sourceItem);
            DotDataItem dotTargetItem = getDotDataItem(targetItem);
            sb.append(indent(indent)).append(dotSourceItem.getNodeName());
            sb.append(" -> ").append(dotTargetItem.getNodeName());
            sb.append(" [label=\"").append(dotRelation.getEdgeLabel()).append("\"");
            sb.append(", style=").append(dotRelation.getEdgeStyle());
            sb.append(", tooltip=\"").append(dotRelation.getEdgeTooltip()).append("\"");
            sb.append(", labeltooltip=\"").append(dotRelation.getEdgeTooltip()).append("\"");
            sb.append("];").append("\n");
        } else {
            String mappingName = "m" + (mappingNode++);
            String nodeLabel = dotRelation.getNodeLabel(mappingName);
            if (nodeLabel != null) {
                sb.append(indent(indent)).append(mappingName).append(" [label=\"").append(nodeLabel).append("\"");
                String styles = dotRelation.getNodeStyleAttributes();
                if (StringUtils.isNotEmpty(styles)) {
                    sb.append(", ").append(styles);
                }
                sb.append(", tooltip=\"").append(dotRelation.getNodeTooltip()).append("\"");
                sb.append("];\n");
            }
            for (DataItem src : relation.getSources()) {
                DotDataItem dotSrc = getDotDataItem(src);
                sb.append(indent(indent)).append(dotSrc.getNodeName()).append(" -> ").append(mappingName).append(" [style=").append(dotRelation.getEdgeStyle()).append("]\n");
            }
            if (relation.getTarget() != null) {
                DotDataItem dotTarget = getDotDataItem(relation.getTarget());
                sb.append(indent(indent)).append(mappingName).append(" -> ").append(dotTarget.getNodeName()).append(" [style=").append(dotRelation.getEdgeStyle()).append("]\n");
            }
        }
    }
    sb.append("}");
    String dot = sb.toString();
    LOGGER.debug("Resulting DOT:\n{}", dot);
    return dot;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 30 with ResourceAttributeDefinition

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

ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)32 QName (javax.xml.namespace.QName)19 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)8 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)7 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 Task (com.evolveum.midpoint.task.api.Task)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ArrayList (java.util.ArrayList)6 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)5 Entry (org.apache.directory.api.ldap.model.entry.Entry)5 Test (org.testng.annotations.Test)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)3 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)2 Containerable (com.evolveum.midpoint.prism.Containerable)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2