Search in sources :

Example 16 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.

the class EntityDiscoveryService method getClassificationFilter.

private static String getClassificationFilter(AtlasTypeRegistry typeRegistry, String classificationName, int maxTypesCountInIdxQuery) {
    AtlasClassificationType classification = typeRegistry.getClassificationTypeByName(classificationName);
    Set<String> typeAndSubTypes = classification != null ? classification.getTypeAndAllSubTypes() : null;
    if (CollectionUtils.isNotEmpty(typeAndSubTypes) && typeAndSubTypes.size() <= maxTypesCountInIdxQuery) {
        return String.format("(%s)", StringUtils.join(typeAndSubTypes, " "));
    }
    return "";
}
Also used : AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 17 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.

the class NotificationEntityChangeListenerTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    AtlasTypeRegistry typeSystem = mock(AtlasTypeRegistry.class);
    String traitName = "MyTrait";
    Struct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    AtlasClassificationType traitDef = mock(AtlasClassificationType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    AtlasClassificationType superTraitDef = mock(AtlasClassificationType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeSystem.getClassificationTypeByName(traitName)).thenReturn(traitDef);
    when(typeSystem.getClassificationTypeByName(superTraitName)).thenReturn(superTraitDef);
    when(traitDef.getAllSuperTypes()).thenReturn(superTypeNames);
    when(superTraitDef.getAllSuperTypes()).thenReturn(superSuperTypeNames);
    List<Struct> allTraits = NotificationEntityChangeListener.getAllTraits(entity, typeSystem);
    assertEquals(2, allTraits.size());
    for (Struct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 18 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.

the class ExportService method addType.

private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType) type;
        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType) type;
        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType) type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType) type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType) type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType) type, context);
    }
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 19 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.

the class NotificationEntityChangeListener method getAllTraits.

// ----- helper methods -------------------------------------------------
// ----- helper methods ----------------------------------------------------
@VisibleForTesting
public static List<Struct> getAllTraits(Referenceable entityDefinition, AtlasTypeRegistry typeRegistry) throws AtlasException {
    List<Struct> ret = new ArrayList<>();
    for (String traitName : entityDefinition.getTraitNames()) {
        Struct trait = entityDefinition.getTrait(traitName);
        AtlasClassificationType traitType = typeRegistry.getClassificationTypeByName(traitName);
        Set<String> superTypeNames = traitType != null ? traitType.getAllSuperTypes() : null;
        ret.add(trait);
        if (CollectionUtils.isNotEmpty(superTypeNames)) {
            for (String superTypeName : superTypeNames) {
                Struct superTypeTrait = new Struct(superTypeName);
                if (MapUtils.isNotEmpty(trait.getValues())) {
                    AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName);
                    if (superType != null && MapUtils.isNotEmpty(superType.getAllAttributes())) {
                        Map<String, Object> superTypeTraitAttributes = new HashMap<>();
                        for (Map.Entry<String, Object> attrEntry : trait.getValues().entrySet()) {
                            String attrName = attrEntry.getKey();
                            if (superType.getAllAttributes().containsKey(attrName)) {
                                superTypeTraitAttributes.put(attrName, attrEntry.getValue());
                            }
                        }
                        superTypeTrait.setValues(superTypeTraitAttributes);
                    }
                }
                ret.add(superTypeTrait);
            }
        }
    }
    return ret;
}
Also used : AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Struct(org.apache.atlas.v1.model.instance.Struct) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 20 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.

the class AtlasEntityStoreV1 method validateEntityAssociations.

/**
 * 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 = AtlasGraphUtilsV1.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);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)8 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)8 Test (org.testng.annotations.Test)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)6 Struct (org.apache.atlas.v1.model.instance.Struct)6 Map (java.util.Map)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)3 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ConverterContext (org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)2 AtlasEnumType (org.apache.atlas.type.AtlasEnumType)2 AtlasMapType (org.apache.atlas.type.AtlasMapType)2