private AtlasEntityDiffResult getDiffResult()

in repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityComparator.java [60:182]


    private AtlasEntityDiffResult getDiffResult(AtlasEntity updatedEntity, AtlasEntity storedEntity, AtlasVertex storedVertex, boolean findOnlyFirstDiff) throws AtlasBaseException {
        AtlasEntity                              diffEntity                       = new AtlasEntity(updatedEntity.getTypeName());
        AtlasEntityType                          entityType                       = typeRegistry.getEntityTypeByName(updatedEntity.getTypeName());
        Map<String, AtlasAttribute>              entityTypeAttributes             = entityType.getAllAttributes();
        Map<String, Map<String, AtlasAttribute>> entityTypeRelationshipAttributes = entityType.getRelationshipAttributes();

        int     sectionsWithDiff                = 0;
        boolean hasDiffInAttributes             = false;
        boolean hasDiffInRelationshipAttributes = false;
        boolean hasDiffInCustomAttributes       = false;
        boolean hasDiffInBusinessAttributes     = false;

        diffEntity.setGuid(updatedEntity.getGuid());

        if (MapUtils.isNotEmpty(updatedEntity.getAttributes())) { // check for attribute value change
            for (Map.Entry<String, Object> entry : updatedEntity.getAttributes().entrySet()) {
                String         attrName  = entry.getKey();
                AtlasAttribute attribute = entityTypeAttributes.get(attrName);

                if (attribute == null) { // no such attribute
                    continue;
                }

                Object newVal  = entry.getValue();
                Object currVal = (storedEntity != null) ? storedEntity.getAttribute(attrName) : entityRetriever.getEntityAttribute(storedVertex, attribute);

                if (!attribute.getAttributeType().areEqualValues(currVal, newVal, guidRefMap)) {
                    hasDiffInAttributes = true;

                    diffEntity.setAttribute(attrName, newVal);

                    if (findOnlyFirstDiff) {
                        return new AtlasEntityDiffResult(diffEntity, true, false, false);
                    }
                }
            }

            if (hasDiffInAttributes) {
                sectionsWithDiff++;
            }
        }

        if (MapUtils.isNotEmpty(updatedEntity.getRelationshipAttributes())) { // check for relationship-attribute value change
            for (Map.Entry<String, Object> entry : updatedEntity.getRelationshipAttributes().entrySet()) {
                String attrName = entry.getKey();

                if (!entityTypeRelationshipAttributes.containsKey(attrName)) {  // no such attribute
                    continue;
                }

                Object         newVal           = entry.getValue();
                String         relationshipType = AtlasEntityUtil.getRelationshipType(newVal);
                AtlasAttribute attribute        = entityType.getRelationshipAttribute(attrName, relationshipType);
                Object         currVal          = (storedEntity != null) ? storedEntity.getRelationshipAttribute(attrName) : entityRetriever.getEntityAttribute(storedVertex, attribute);

                if (!attribute.getAttributeType().areEqualValues(currVal, newVal, guidRefMap)) {
                    hasDiffInRelationshipAttributes = true;

                    diffEntity.setRelationshipAttribute(attrName, newVal);

                    if (findOnlyFirstDiff) {
                        return new AtlasEntityDiffResult(diffEntity, true, false, false);
                    }
                }
            }

            if (hasDiffInRelationshipAttributes) {
                sectionsWithDiff++;
            }
        }

        if (!skipClassificationCompare) {
            List<AtlasClassification> newVal  = updatedEntity.getClassifications();
            List<AtlasClassification> currVal = (storedEntity != null) ? storedEntity.getClassifications() : entityRetriever.getAllClassifications(storedVertex);

            if (!Objects.equals(currVal, newVal)) {
                diffEntity.setClassifications(newVal);

                sectionsWithDiff++;

                if (findOnlyFirstDiff) {
                    return new AtlasEntityDiffResult(diffEntity, true, false, false);
                }
            }
        }

        if (updatedEntity.getCustomAttributes() != null) {
            // event coming from hook does not have custom attributes, such events must not remove existing attributes
            // UI sends empty object in case of of intended removal.
            Map<String, String> newCustomAttributes  = updatedEntity.getCustomAttributes();
            Map<String, String> currCustomAttributes = (storedEntity != null) ? storedEntity.getCustomAttributes() : getCustomAttributes(storedVertex);

            if (!Objects.equals(currCustomAttributes, newCustomAttributes)) {
                diffEntity.setCustomAttributes(newCustomAttributes);

                hasDiffInCustomAttributes = true;
                sectionsWithDiff++;

                if (findOnlyFirstDiff && sectionsWithDiff > 1) {
                    return new AtlasEntityDiffResult(diffEntity, true, false, false);
                }
            }
        }

        if (!skipBusinessAttributeCompare) {
            Map<String, Map<String, Object>> newBusinessMetadata  = updatedEntity.getBusinessAttributes();
            Map<String, Map<String, Object>> currBusinessMetadata = (storedEntity != null) ? storedEntity.getBusinessAttributes() : entityRetriever.getBusinessMetadata(storedVertex);

            if (!Objects.equals(currBusinessMetadata, newBusinessMetadata)) {
                diffEntity.setBusinessAttributes(newBusinessMetadata);

                hasDiffInBusinessAttributes = true;

                sectionsWithDiff++;

                if (findOnlyFirstDiff && sectionsWithDiff > 1) {
                    return new AtlasEntityDiffResult(diffEntity, true, false, false);
                }
            }
        }

        return new AtlasEntityDiffResult(diffEntity, sectionsWithDiff > 0, sectionsWithDiff == 1 && hasDiffInCustomAttributes, sectionsWithDiff == 1 && hasDiffInBusinessAttributes);
    }