void resolveReferencesPhase3()

in intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java [333:463]


    void resolveReferencesPhase3(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
        for (AtlasAttributeDef attributeDef : getStructDef().getAttributeDefs()) {
            String          attributeName       = attributeDef.getName();
            AtlasType       attributeType       = typeRegistry.getType(attributeDef.getTypeName());
            AtlasEntityType attributeEntityType = getReferencedEntityType(attributeType);

            // validate if RelationshipDefs is defined for all entityDefs
            if (attributeEntityType != null && !hasRelationshipAttribute(attributeName)) {
                typeRegistry.reportMissingRelationshipDef(getTypeName(), attributeEntityType.getTypeName(), attributeName);
            }
        }

        for (String superTypeName : allSuperTypes) {
            if (INTERNAL_TYPENAME.equals(superTypeName)) {
                isInternalType = true;
            }

            AtlasEntityType                          superType                       = typeRegistry.getEntityTypeByName(superTypeName);
            Map<String, Map<String, AtlasAttribute>> superTypeRelationshipAttributes = superType.getRelationshipAttributes();

            if (MapUtils.isNotEmpty(superTypeRelationshipAttributes)) {
                for (String attrName : superTypeRelationshipAttributes.keySet()) {
                    Map<String, AtlasAttribute> superTypeAttributes = superTypeRelationshipAttributes.get(attrName);

                    if (MapUtils.isNotEmpty(superTypeAttributes)) {
                        Map<String, AtlasAttribute> attributes = relationshipAttributes.computeIfAbsent(attrName, k -> new HashMap<>());

                        for (String relationshipType : superTypeAttributes.keySet()) {
                            if (!attributes.containsKey(relationshipType)) {
                                attributes.put(relationshipType, superTypeAttributes.get(relationshipType));
                            }
                        }
                    }
                }
            }

            Map<String, Map<String, AtlasBusinessAttribute>> superTypeBusinessMetadata = superType.getBusinessAttributes();

            if (MapUtils.isNotEmpty(superTypeBusinessMetadata)) {
                for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : superTypeBusinessMetadata.entrySet()) {
                    String                              bmName           = entry.getKey();
                    Map<String, AtlasBusinessAttribute> superTypeBmAttrs = entry.getValue();
                    Map<String, AtlasBusinessAttribute> bmAttrs          = businessAttributes.computeIfAbsent(bmName, k -> new HashMap<>());

                    bmAttrs.putAll(superTypeBmAttrs);
                }
            }

            tagPropagationEdges.addAll(superType.tagPropagationEdges);
        }

        ownedRefAttributes = new ArrayList<>();

        for (AtlasAttribute attribute : allAttributes.values()) {
            if (attribute.isOwnedRef()) {
                ownedRefAttributes.add(attribute);
            }
        }

        for (Map<String, AtlasAttribute> attributes : relationshipAttributes.values()) {
            for (AtlasAttribute attribute : attributes.values()) {
                if (attribute.isOwnedRef()) {
                    ownedRefAttributes.add(attribute);
                }
            }
        }

        subTypes                 = Collections.unmodifiableSet(subTypes);
        allSubTypes              = Collections.unmodifiableSet(allSubTypes);
        typeAndAllSubTypes       = Collections.unmodifiableSet(typeAndAllSubTypes);
        typeAndAllSubTypesQryStr = ""; // will be computed on next access
        relationshipAttributes   = Collections.unmodifiableMap(relationshipAttributes);
        businessAttributes       = Collections.unmodifiableMap(businessAttributes);
        ownedRefAttributes       = Collections.unmodifiableList(ownedRefAttributes);
        tagPropagationEdges      = Collections.unmodifiableSet(tagPropagationEdges);

        entityDef.setSubTypes(subTypes);

        List<AtlasRelationshipAttributeDef> relationshipAttrDefs = new ArrayList<>();

        for (Map.Entry<String, Map<String, AtlasAttribute>> attrEntry : relationshipAttributes.entrySet()) {
            Map<String, AtlasAttribute> relations = attrEntry.getValue();

            for (Map.Entry<String, AtlasAttribute> relationsEntry : relations.entrySet()) {
                String         relationshipType = relationsEntry.getKey();
                AtlasAttribute relationshipAttr = relationsEntry.getValue();

                AtlasRelationshipAttributeDef relationshipAttributeDef = new AtlasRelationshipAttributeDef(relationshipType, relationshipAttr.isLegacyAttribute(), relationshipAttr.getAttributeDef());

                updateRelationshipAttrDefForPartialUpdate(relationshipAttributeDef, entityDef);

                relationshipAttrDefs.add(relationshipAttributeDef);
            }
        }

        entityDef.setRelationshipAttributeDefs(Collections.unmodifiableList(relationshipAttrDefs));

        Map<String, List<AtlasAttributeDef>> bmAttributeDefs = new HashMap<>();

        for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : businessAttributes.entrySet()) {
            String                              bmName     = entry.getKey();
            Map<String, AtlasBusinessAttribute> bmAttrs    = entry.getValue();
            List<AtlasAttributeDef>             bmAttrDefs = new ArrayList<>();

            for (AtlasBusinessAttribute bmAttr : bmAttrs.values()) {
                bmAttrDefs.add(bmAttr.getAttributeDef());
            }

            bmAttributeDefs.put(bmName, bmAttrDefs);
        }

        entityDef.setBusinessAttributeDefs(bmAttributeDefs);

        if (this.displayTextAttribute == null) {
            for (String superTypeName : allSuperTypes) { // find displayTextAttribute in all superTypes
                AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);

                this.displayTextAttribute = superType.getDisplayTextAttribute();

                if (this.displayTextAttribute != null) {
                    break;
                }
            }
        }

        this.parsedTemplates = parseDynAttributeTemplates();

        populateDynFlagsInfo();

        LOG.debug("resolveReferencesPhase3({}): tagPropagationEdges={}", getTypeName(), tagPropagationEdges);
    }