Search in sources :

Example 1 with ConstraintViolationConfirmer

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

the class ShadowConstraintsChecker method check.

public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition projOcDef = projectionContext.getCompositeObjectClassDefinition();
    PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
    if (projectionNew == null) {
        // This must be delete
        LOGGER.trace("No new object in projection context. Current shadow satisfy constraints");
        satisfiesConstraints = true;
        return;
    }
    PrismContainer<?> attributesContainer = projectionNew.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // No attributes no constraint violations
        LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
        satisfiesConstraints = true;
        return;
    }
    ConstraintViolationConfirmer confirmer = new ConstraintViolationConfirmer() {

        @Override
        public boolean confirmViolation(String oid) {
            boolean violation = true;
            LensProjectionContext foundContext = context.findProjectionContextByOid(oid);
            if (foundContext != null) {
                if (foundContext.getResourceShadowDiscriminator() != null) {
                    if (foundContext.getResourceShadowDiscriminator().isThombstone()) {
                        violation = false;
                    }
                    LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
                }
            }
            return violation;
        }
    };
    constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, task, result);
    if (constraintsCheckingResult.isSatisfiesConstraints()) {
        satisfiesConstraints = true;
        return;
    }
    for (QName checkedAttributeName : constraintsCheckingResult.getCheckedAttributes()) {
        if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) {
            if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) {
                throw new ObjectAlreadyExistsException("Attribute " + checkedAttributeName + " conflicts with existing object (and it is present in primary " + "account delta therefore no iteration is performed)");
            }
        }
    }
    if (projectionContext.getResourceShadowDiscriminator() != null && projectionContext.getResourceShadowDiscriminator().isThombstone()) {
        satisfiesConstraints = true;
    } else {
        satisfiesConstraints = false;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 ConstraintViolationConfirmer (com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 QName (javax.xml.namespace.QName)1