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