Search in sources :

Example 6 with RefinedAssociationDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition 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++;
        }
        RefinedResourceSchema schema = dataModel.getRefinedResourceSchema(resource.getOid());
        for (RefinedObjectClassDefinition def : schema.getRefinedDefinitions()) {
            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), new ItemPath(attrDef.getName()));
                previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, item);
            }
            for (RefinedAssociationDefinition assocDef : def.getAssociationDefinitions()) {
                if (assocDef.isIgnored()) {
                    continue;
                }
                ResourceDataItem item = dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(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), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, DataModelVisualizerImpl.ACTIVATION_EXISTENCE)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
            previousNodeName = addResourceItem(itemsShown, indent, sb1, previousNodeName, dataModel.findResourceItem(resource.getOid(), def.getKind(), def.getIntent(), getObjectClassName(def), new ItemPath(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 : ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with RefinedAssociationDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition 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)

Example 8 with RefinedAssociationDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition in project midpoint by Evolveum.

the class TestDummyExtra method assertSchemaSanity.

@Override
protected void assertSchemaSanity(ResourceSchema resourceSchema, ResourceType resourceType) throws Exception {
    // schema is extended, displayOrders are changed
    dummyResourceCtl.assertDummyResourceSchemaSanityExtended(resourceSchema, resourceType, false, 18);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
    RefinedObjectClassDefinition accountRDef = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    Collection<RefinedAssociationDefinition> associationDefinitions = accountRDef.getAssociationDefinitions();
    assertEquals("Wrong number of association defs", 3, associationDefinitions.size());
    RefinedAssociationDefinition crewAssociationDef = accountRDef.findAssociationDefinition(ASSOCIATION_CREW_NAME);
    assertNotNull("No definitin for crew assocation", crewAssociationDef);
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)

Aggregations

RefinedAssociationDefinition (com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)8 QName (javax.xml.namespace.QName)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)3 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)2 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2 CompositeRefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.CompositeRefinedObjectClassDefinition)1 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)1 Construction (com.evolveum.midpoint.model.impl.lens.Construction)1 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1