Search in sources :

Example 6 with PropertyAccessType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType in project midpoint by Evolveum.

the class SchemaTransformer method applyObjectTemplateItem.

private <IV extends PrismValue, ID extends ItemDefinition> void applyObjectTemplateItem(ID itemDef, ObjectTemplateItemDefinitionType templateItemDefType, String desc) throws SchemaException {
    if (itemDef == null) {
        throw new SchemaException("No definition for " + desc);
    }
    String displayName = templateItemDefType.getDisplayName();
    if (displayName != null) {
        ((ItemDefinitionImpl) itemDef).setDisplayName(displayName);
    }
    Integer displayOrder = templateItemDefType.getDisplayOrder();
    if (displayOrder != null) {
        ((ItemDefinitionImpl) itemDef).setDisplayOrder(displayOrder);
    }
    Boolean emphasized = templateItemDefType.isEmphasized();
    if (emphasized != null) {
        ((ItemDefinitionImpl) itemDef).setEmphasized(emphasized);
    }
    List<PropertyLimitationsType> limitations = templateItemDefType.getLimitations();
    if (limitations != null) {
        PropertyLimitationsType limitationsType = MiscSchemaUtil.getLimitationsType(limitations, LayerType.PRESENTATION);
        if (limitationsType != null) {
            if (limitationsType.getMinOccurs() != null) {
                ((ItemDefinitionImpl) itemDef).setMinOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMinOccurs()));
            }
            if (limitationsType.getMaxOccurs() != null) {
                ((ItemDefinitionImpl) itemDef).setMaxOccurs(XsdTypeMapper.multiplicityToInteger(limitationsType.getMaxOccurs()));
            }
            if (limitationsType.isIgnore() != null) {
                ((ItemDefinitionImpl) itemDef).setIgnored(limitationsType.isIgnore());
            }
            PropertyAccessType accessType = limitationsType.getAccess();
            if (accessType != null) {
                if (accessType.isAdd() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanAdd(accessType.isAdd());
                }
                if (accessType.isModify() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanModify(accessType.isModify());
                }
                if (accessType.isRead() != null) {
                    ((ItemDefinitionImpl) itemDef).setCanRead(accessType.isRead());
                }
            }
        }
    }
    ObjectReferenceType valueEnumerationRef = templateItemDefType.getValueEnumerationRef();
    if (valueEnumerationRef != null) {
        PrismReferenceValue valueEnumerationRVal = MiscSchemaUtil.objectReferenceTypeToReferenceValue(valueEnumerationRef);
        ((ItemDefinitionImpl) itemDef).setValueEnumerationRef(valueEnumerationRVal);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PropertyAccessType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType) PropertyLimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)

Example 7 with PropertyAccessType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType in project midpoint by Evolveum.

the class ReconciliationProcessor method reconcileProjectionAssociations.

private void reconcileProjectionAssociations(LensProjectionContext projCtx, Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>>> squeezedAssociations, RefinedObjectClassDefinition accountDefinition, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    PrismObject<ShadowType> shadowNew = projCtx.getObjectNew();
    PrismContainer associationsContainer = shadowNew.findContainer(ShadowType.F_ASSOCIATION);
    Collection<QName> associationNames = squeezedAssociations != null ? MiscUtil.union(squeezedAssociations.keySet(), accountDefinition.getNamesOfAssociations()) : accountDefinition.getNamesOfAssociations();
    for (QName assocName : associationNames) {
        LOGGER.trace("Association reconciliation processing association {}", assocName);
        RefinedAssociationDefinition associationDefinition = accountDefinition.findAssociationDefinition(assocName);
        if (associationDefinition == null) {
            throw new SchemaException("No definition for association " + assocName + " in " + projCtx.getResourceShadowDiscriminator());
        }
        DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> cvwoTriple = squeezedAssociations != null ? squeezedAssociations.get(assocName) : null;
        // note: actually isIgnored is not implemented yet
        if (associationDefinition.isIgnored()) {
            LOGGER.trace("Skipping reconciliation of association {} because it is ignored", assocName);
            continue;
        }
        // TODO implement limitations
        //            PropertyLimitations limitations = associationDefinition.getLimitations(LayerType.MODEL);
        //            if (limitations != null) {
        //                PropertyAccessType access = limitations.getAccess();
        //                if (access != null) {
        //                    if (projCtx.isAdd() && (access.isAdd() == null || !access.isAdd())) {
        //                        LOGGER.trace("Skipping reconciliation of attribute {} because it is non-createable",
        //                                attrName);
        //                        continue;
        //                    }
        //                    if (projCtx.isModify() && (access.isModify() == null || !access.isModify())) {
        //                        LOGGER.trace("Skipping reconciliation of attribute {} because it is non-updateable",
        //                                attrName);
        //                        continue;
        //                    }
        //                }
        //            }
        Collection<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> shouldBeCValues;
        if (cvwoTriple == null) {
            shouldBeCValues = new HashSet<>();
        } else {
            shouldBeCValues = new HashSet<>(cvwoTriple.getNonNegativeValues());
        }
        // TODO what about equality checks? There will be probably duplicates there.
        // We consider values explicitly requested by user to be among "should be values".
        addContainerValuesFromDelta(shouldBeCValues, projCtx.getPrimaryDelta(), assocName);
        // But we DO NOT take values from sync delta (because they just reflect what's on the resource),
        // nor from secondary delta (because these got there from mappings).
        // values in shouldBeCValues are parent-less
        // to be able to make Containerable out of them, we provide them a (fake) parent
        // (and we clone them not to mess anything)
        PrismContainer<ShadowAssociationType> fakeParent = prismContext.getSchemaRegistry().findContainerDefinitionByCompileTimeClass(ShadowAssociationType.class).instantiate();
        for (ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> cvwo : shouldBeCValues) {
            PrismContainerValue<ShadowAssociationType> cvalue = cvwo.getItemValue().clone();
            cvalue.setParent(fakeParent);
            cvwo.setItemValue(cvalue);
        }
        boolean hasStrongShouldBeCValue = false;
        for (ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> shouldBeCValue : shouldBeCValues) {
            if (shouldBeCValue.getMapping() != null && shouldBeCValue.getMapping().getStrength() == MappingStrengthType.STRONG) {
                hasStrongShouldBeCValue = true;
                break;
            }
        }
        Collection<PrismContainerValue<ShadowAssociationType>> areCValues = new HashSet<>();
        if (associationsContainer != null) {
            for (Object o : associationsContainer.getValues()) {
                PrismContainerValue<ShadowAssociationType> existingAssocValue = (PrismContainerValue<ShadowAssociationType>) o;
                if (existingAssocValue.getValue().getName().equals(assocName)) {
                    areCValues.add(existingAssocValue);
                }
            }
        } else {
            areCValues = new HashSet<>();
        }
        // todo comment this logging code out eventually
        //			if (LOGGER.isTraceEnabled()) {
        //				StringBuilder sb = new StringBuilder();
        //				sb.append("Reconciliation\nASSOCIATION: ").append(PrettyPrinter.prettyPrint(assocName));
        //				sb.append("\n  Should be:");
        //				for (ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>,PrismContainerDefinition<ShadowAssociationType>> shouldBeCValue : shouldBeCValues) {
        //					sb.append("\n    ");
        //					sb.append(shouldBeCValue.getItemValue());
        //					PrismValueDeltaSetTripleProducer<?,?> shouldBeMapping = shouldBeCValue.getMapping();
        //					if (shouldBeMapping != null && shouldBeMapping.getStrength() == MappingStrengthType.STRONG) {
        //						sb.append(" STRONG");
        //					}
        //					if (shouldBeMapping != null && shouldBeMapping.getStrength() == MappingStrengthType.WEAK) {
        //						sb.append(" WEAK");
        //					}
        //					if (!shouldBeCValue.isValid()) {
        //						sb.append(" INVALID");
        //					}
        //				}
        //				sb.append("\n  Is:");
        //				for (PrismContainerValue<ShadowAssociationType> isCVal : areCValues) {
        //					sb.append("\n    ");
        //					sb.append(isCVal);
        //				}
        //				LOGGER.trace("{}", sb.toString());
        //			}
        ValueMatcher associationValueMatcher = new ValueMatcher(null) {

            // todo is this correct? [med]
            @Override
            public boolean match(Object realA, Object realB) {
                checkType(realA);
                checkType(realB);
                if (realA == null) {
                    return realB == null;
                } else if (realB == null) {
                    return false;
                } else {
                    ShadowAssociationType a = (ShadowAssociationType) realA;
                    ShadowAssociationType b = (ShadowAssociationType) realB;
                    checkName(a);
                    checkName(b);
                    if (!a.getName().equals(b.getName())) {
                        return false;
                    }
                    if (a.getShadowRef() != null && a.getShadowRef().getOid() != null && b.getShadowRef() != null && b.getShadowRef().getOid() != null) {
                        return a.getShadowRef().getOid().equals(b.getShadowRef().getOid());
                    }
                    LOGGER.warn("Comparing association values without shadowRefs: {} and {}", a, b);
                    return false;
                }
            }

            private void checkName(ShadowAssociationType s) {
                if (s.getName() == null) {
                    throw new IllegalStateException("No name for association " + s);
                }
            }

            @Override
            public boolean matches(Object realValue, String regex) {
                throw new UnsupportedOperationException();
            }

            @Override
            public boolean hasRealValue(PrismProperty property, PrismPropertyValue pValue) {
                throw new UnsupportedOperationException();
            }

            @Override
            public boolean isRealValueToAdd(PropertyDelta delta, PrismPropertyValue pValue) {
                throw new UnsupportedOperationException();
            }

            private void checkType(Object o) {
                if (o != null && !(o instanceof ShadowAssociationType)) {
                    throw new IllegalStateException("Object is not a ShadowAssociationType, it is " + o.getClass() + " instead");
                }
            }
        };
        for (ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> shouldBeCvwo : shouldBeCValues) {
            PrismValueDeltaSetTripleProducer<?, ?> shouldBeMapping = shouldBeCvwo.getMapping();
            if (shouldBeMapping == null) {
                continue;
            }
            if (shouldBeMapping.getStrength() != MappingStrengthType.STRONG && (!areCValues.isEmpty() || hasStrongShouldBeCValue)) {
                // changed directly on the projection resource object
                continue;
            }
            ShadowAssociationType shouldBeRealValue = shouldBeCvwo.getItemValue().getValue();
            if (shouldBeCvwo.isValid() && !isInAssociationValues(associationValueMatcher, shouldBeRealValue, areCValues)) {
                recordAssociationDelta(associationValueMatcher, projCtx, associationDefinition, ModificationType.ADD, shouldBeRealValue, shouldBeCvwo.getSource(), "it is given by a mapping");
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Before decideIfTolerateAssociation:");
            LOGGER.trace("areCValues:\n{}", DebugUtil.debugDump(areCValues));
            LOGGER.trace("shouldBeCValues:\n{}", DebugUtil.debugDump(shouldBeCValues));
        }
        decideIfTolerateAssociation(projCtx, associationDefinition, areCValues, shouldBeCValues, associationValueMatcher, task, result);
    }
}
Also used : RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) HashSet(java.util.HashSet) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PropertyAccessType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType)6 PropertyLimitations (com.evolveum.midpoint.common.refinery.PropertyLimitations)4 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 QName (javax.xml.namespace.QName)3 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 RefinedAssociationDefinition (com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)1 PropertyLimitationsTypeDto (com.evolveum.midpoint.web.component.wizard.resource.dto.PropertyLimitationsTypeDto)1 LayerType (com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 PropertyLimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType)1 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1