Search in sources :

Example 31 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType 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)

Example 32 with AtlasEntityType

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

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonCompositeManyToOne.

@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream, false);
    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.manyA reference to a1 and a2
    // * set inverse a1.oneB reference to b
    // * set inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a3)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set b.manyA reference to a3
    // * set inverse a3.oneB reference to b
    // * disconnect inverse a1.oneB reference to b
    // * disconnect inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 4);
    init();
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), a3.getGuid(), b.getGuid()));
    verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid());
    verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 33 with AtlasEntityType

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

the class TestAtlasEntity method testEntitySerDeWithSuperType.

@Test
public void testEntitySerDeWithSuperType() throws AtlasBaseException {
    AtlasEntityDef entityDef = ModelTestUtil.getEntityDefWithSuperType();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
    assertNotNull(entityType);
    AtlasEntity ent1 = entityType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
    entityType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superType");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 34 with AtlasEntityType

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

the class TestAtlasEntity method testEntitySerDeWithSuperTypes.

@Test
public void testEntitySerDeWithSuperTypes() throws AtlasBaseException {
    AtlasEntityDef entityDef = ModelTestUtil.getEntityDefWithSuperTypes();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
    assertNotNull(entityType);
    AtlasEntity ent1 = entityType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
    entityType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity with superTypes");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 35 with AtlasEntityType

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

the class TestAtlasEntity method testEntitySerDe.

@Test
public void testEntitySerDe() throws AtlasBaseException {
    AtlasEntityDef entityDef = ModelTestUtil.getEntityDef();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
    assertNotNull(entityType);
    AtlasEntity ent1 = entityType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
    entityType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityType (org.apache.atlas.type.AtlasEntityType)45 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)6 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)6 AtlasType (org.apache.atlas.type.AtlasType)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)5 HashMap (java.util.HashMap)4 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)4 List (java.util.List)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3