Search in sources :

Example 31 with AtlasClassificationType

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

the class AtlasEntityStoreV1 method validateAndNormalize.

private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());
    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }
    List<String> messages = new ArrayList<>();
    type.validateValue(classification, classification.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }
    type.getNormalizedValue(classification);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 32 with AtlasClassificationType

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

the class AtlasClassificationFormatConverter method fromV1ToV2.

@Override
public AtlasClassification fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    AtlasClassification ret = null;
    if (v1Obj != null) {
        AtlasClassificationType classificationType = (AtlasClassificationType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
            } else {
                ret = new AtlasClassification(type.getTypeName());
            }
        } else if (v1Obj instanceof IStruct) {
            IStruct struct = (IStruct) v1Obj;
            Map<String, Object> v1Attribs = null;
            try {
                v1Attribs = struct.getValuesMap();
            } catch (AtlasException excp) {
                LOG.error("IStruct.getValuesMap() failed", excp);
            }
            ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasException(org.apache.atlas.AtlasException) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 33 with AtlasClassificationType

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

the class TestAtlasClassification method testClassificationSerDeWithSuperTypes.

@Test
public void testClassificationSerDeWithSuperTypes() throws AtlasBaseException {
    AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDefWithSuperTypes();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
    assertNotNull(classificationType);
    AtlasClassification ent1 = classificationType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
    classificationType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superTypes");
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Test(org.testng.annotations.Test)

Example 34 with AtlasClassificationType

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

the class TestAtlasClassification method testClassificationSerDeWithSuperType.

@Test
public void testClassificationSerDeWithSuperType() throws AtlasBaseException {
    AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDefWithSuperType();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
    assertNotNull(classificationType);
    AtlasClassification ent1 = classificationType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
    classificationType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superType");
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Test(org.testng.annotations.Test)

Example 35 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-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)

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