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 "";
}
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));
}
}
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);
}
}
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;
}
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);
}
}
}
Aggregations