Search in sources :

Example 26 with AtlasClassificationType

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

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

the class TestAtlasClassification method testClassificationSerDe.

@Test
public void testClassificationSerDe() throws AtlasBaseException {
    AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDef();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
    assertNotNull(classificationType);
    AtlasClassification ent1 = ModelTestUtil.newClassification(classificationDef, typeRegistry);
    String jsonString = AtlasType.toJson(ent1);
    AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
    classificationType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification");
}
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 28 with AtlasClassificationType

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

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

the class EntityNotificationTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    AtlasTypeRegistry typeRegistry = mock(AtlasTypeRegistry.class);
    String traitName = "MyTrait";
    Struct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    AtlasClassificationType traitType = mock(AtlasClassificationType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    AtlasClassificationType superTraitType = mock(AtlasClassificationType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeRegistry.getClassificationTypeByName(traitName)).thenReturn(traitType);
    when(typeRegistry.getClassificationTypeByName(superTraitName)).thenReturn(superTraitType);
    when(traitType.getAllSuperTypes()).thenReturn(superTypeNames);
    when(superTraitType.getAllSuperTypes()).thenReturn(superSuperTypeNames);
    EntityNotificationV1 entityNotification = new EntityNotificationV1(entity, OperationType.TRAIT_ADD, typeRegistry);
    List<Struct> allTraits = entityNotification.getAllTraits();
    assertEquals(2, allTraits.size());
    for (Struct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) 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 30 with AtlasClassificationType

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

the class AtlasEntityStoreV1 method validateAndNormalizeForUpdate.

private void validateAndNormalizeForUpdate(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.validateValueForUpdate(classification, classification.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }
    type.getNormalizedValueForUpdate(classification);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

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