/** * Validate if classification is not already associated with the entities * * @param guid unique entity id * @param classifications list of classifications to be associated */ private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException { List<String> entityClassifications = getClassificationNames(guid); String entityTypeName = AtlasGraphUtilsV2.getTypeNameFromGuid(guid); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); for (AtlasClassification classification : classifications) { String newClassification = classification.getTypeName(); if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid + ", already associated with classification: " + newClassification); } // for each classification, check whether there are entities it should be restricted to AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(newClassification); if (!classificationType.canApplyToEntityType(entityType)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_ENTITY_FOR_CLASSIFICATION, guid, entityTypeName, newClassification); } } }
/** * Validate if classification is not already associated with the entities * * @param guid unique entity id * @param classifications list of classifications to be associated */ private void validateEntityAssociations(String guid, List<AtlasClassification> classifications) throws AtlasBaseException { List<String> entityClassifications = getClassificationNames(guid); String entityTypeName = AtlasGraphUtilsV2.getTypeNameFromGuid(guid); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); for (AtlasClassification classification : classifications) { String newClassification = classification.getTypeName(); if (CollectionUtils.isNotEmpty(entityClassifications) && entityClassifications.contains(newClassification)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entity: " + guid + ", already associated with classification: " + newClassification); } // for each classification, check whether there are entities it should be restricted to AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(newClassification); if (!classificationType.canApplyToEntityType(entityType)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_ENTITY_FOR_CLASSIFICATION, guid, entityTypeName, newClassification); } } }
String entityGuid = getGuid(propagatedEntityVertex); if (!classificationType.canApplyToEntityType(entityType)) { if (LOG.isDebugEnabled()) { LOG.debug(" --> Not creating propagated classification edge from [{}] --> [{}][{}], classification is not applicable for entity type",
assertTrue(classifyType1.canApplyToEntityType(entityTypeA)); // Classify1 has EntityA as an allowed type assertFalse(classifyType1.canApplyToEntityType(entityTypeB)); // Classify1 neither has EntityB as an allowed type nor any of super-types of EntityB assertTrue(classifyType1.canApplyToEntityType(entityTypeC)); // Classify1 has EntityA as an allowed type and EntityC is a sub-type of EntityA assertTrue(classifyType1.canApplyToEntityType(entityTypeD)); // Classify1 has EntityA as an allowed type and EntityD is a grand-sub-type of EntityA (via EntityC) assertTrue(classifyType2.canApplyToEntityType(entityTypeA)); // EntityA is allowed in Classify2 assertTrue(classifyType2.canApplyToEntityType(entityTypeB)); // EntityB is allowed in Classify2 assertTrue(classifyType2.canApplyToEntityType(entityTypeC)); // EntityC is allowed in Classify2 assertTrue(classifyType2.canApplyToEntityType(entityTypeD)); // EntityD is allowed in Classify2 assertTrue(classifyType3.canApplyToEntityType(entityTypeA)); // EntityA is allowed in Classify3, since it is allowed in Classify1 assertFalse(classifyType3.canApplyToEntityType(entityTypeB)); // EntityB is not an allowed type in Classify3 and Classify1 assertTrue(classifyType3.canApplyToEntityType(entityTypeC)); // EntityC is allowed in Classify3, since its super-type EntityA is allowed in Classify1 assertTrue(classifyType3.canApplyToEntityType(entityTypeD)); // EntityD is allowed in Classify3. since its grand-super-type EntityA is allowed in Classify1 assertFalse(classifyType4.canApplyToEntityType(entityTypeA)); // EntityA is not allowed in Classify4, though it is allowed in its super-types assertFalse(classifyType4.canApplyToEntityType(entityTypeB)); // EntityB is not an allowed type in Classify4 assertFalse(classifyType4.canApplyToEntityType(entityTypeC)); // EntityC is allowed in Classify4, though it is allowed in its super-types assertTrue(classifyType4.canApplyToEntityType(entityTypeD)); // EntityD is allowed in Classify4 assertTrue(classifyType6.canApplyToEntityType(entityTypeF)); // EntityF can be classified by Classify6 assertTrue(classifyType9.canApplyToEntityType(entityTypeF)); // EntityF can be classified by Classify9 assertTrue(classifyType5.canApplyToEntityType(entityTypeA)); // EntityA can be classified by Classify5 assertTrue(classifyType5.canApplyToEntityType(entityTypeC)); // EntityC can be classified by Classify5 assertTrue(classifyType10.canApplyToEntityType(entityTypeA)); // EntityA can be classified by Classify10 assertTrue(classifyType10.canApplyToEntityType(entityTypeC)); // EntityC can be classified by Classify10