Java Code Examples for org.apache.atlas.model.instance.EntityMutationResponse#getMutatedEntities()

The following examples show how to use org.apache.atlas.model.instance.EntityMutationResponse#getMutatedEntities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultValueForPrimitiveTypes() throws Exception  {

    init();

    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(primitiveEntity), false);
    List<AtlasEntityHeader> entitiesCreatedResponse = response.getEntitiesByOperation(EntityOperation.CREATE);
    final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities();
    List<AtlasEntityHeader> entitiesCreatedwithdefault = entitiesMutated.get(EntityOperation.CREATE);

    AtlasEntity entityCreated   = getEntityFromStore(entitiesCreatedResponse.get(0));


    Map attributesMap = entityCreated.getAttributes();
    String description = (String) attributesMap.get("description");
    String check = (String) attributesMap.get("check");
    String   sourceCode =  (String) attributesMap.get("sourcecode");
    float   diskUsage =  (float) attributesMap.get("diskUsage");
    boolean   isstoreUse =  (boolean) attributesMap.get("isstoreUse");
    int cost = (int)attributesMap.get("Cost");


    assertEquals(description,"test");
    assertEquals(check,"check");

    //defaultValue
    assertEquals(diskUsage,70.5f);
    assertEquals(isstoreUse,true);
    assertEquals(sourceCode,"Hello World");
    assertEquals(cost,30);
}
 
Example 2
Source File: AtlasInstanceConverter.java    From atlas with Apache License 2.0 4 votes vote down vote up
public CreateUpdateEntitiesResult toCreateUpdateEntitiesResult(EntityMutationResponse reponse) {
    CreateUpdateEntitiesResult ret = null;

    if (reponse != null) {
        Map<EntityOperation, List<AtlasEntityHeader>> mutatedEntities = reponse.getMutatedEntities();
        Map<String, String>                           guidAssignments = reponse.getGuidAssignments();

        ret = new CreateUpdateEntitiesResult();

        if (MapUtils.isNotEmpty(guidAssignments)) {
            ret.setGuidMapping(new GuidMapping(guidAssignments));
        }

        if (MapUtils.isNotEmpty(mutatedEntities)) {
            EntityResult entityResult = new EntityResult();

            for (Map.Entry<EntityOperation, List<AtlasEntityHeader>> e : mutatedEntities.entrySet()) {
                switch (e.getKey()) {
                    case CREATE:
                        List<AtlasEntityHeader> createdEntities = mutatedEntities.get(EntityOperation.CREATE);
                        if (CollectionUtils.isNotEmpty(createdEntities)) {
                            Collections.reverse(createdEntities);
                            entityResult.set(EntityResult.OP_CREATED, getGuids(createdEntities));
                        }
                        break;
                    case UPDATE:
                        List<AtlasEntityHeader> updatedEntities = mutatedEntities.get(EntityOperation.UPDATE);
                        if (CollectionUtils.isNotEmpty(updatedEntities)) {
                            Collections.reverse(updatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(updatedEntities));
                        }
                        break;
                    case PARTIAL_UPDATE:
                        List<AtlasEntityHeader> partialUpdatedEntities = mutatedEntities.get(EntityOperation.PARTIAL_UPDATE);
                        if (CollectionUtils.isNotEmpty(partialUpdatedEntities)) {
                            Collections.reverse(partialUpdatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(partialUpdatedEntities));
                        }
                        break;
                    case DELETE:
                        List<AtlasEntityHeader> deletedEntities = mutatedEntities.get(EntityOperation.DELETE);
                        if (CollectionUtils.isNotEmpty(deletedEntities)) {
                            Collections.reverse(deletedEntities);
                            entityResult.set(EntityResult.OP_DELETED, getGuids(deletedEntities));
                        }
                        break;
                }

            }

            ret.setEntityResult(entityResult);
        }
    }

    return ret;
}
 
Example 3
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test(priority = -1)
public void testCreate() throws Exception {
    init();

    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
    validateMutationResponse(response, EntityOperation.CREATE, 5);

    AtlasEntityHeader dept1 = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DEPARTMENT_TYPE);
    validateEntity(deptEntity, getEntityFromStore(dept1), deptEntity.getEntities().get(0));

    final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities();
    List<AtlasEntityHeader> entitiesCreated = entitiesMutated.get(EntityOperation.CREATE);

    assertTrue(entitiesCreated.size() >= deptEntity.getEntities().size());

    for (int i = 0; i < deptEntity.getEntities().size(); i++) {
        AtlasEntity expected = deptEntity.getEntities().get(i);
        AtlasEntity actual   = getEntityFromStore(entitiesCreated.get(i));

        validateEntity(deptEntity, actual, expected);
    }

    //Create DB
    init();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    validateMutationResponse(dbCreationResponse, EntityOperation.CREATE, 1);
    dbEntityGuid = dbCreationResponse.getCreatedEntities().get(0).getGuid();

    AtlasEntityHeader db1 = dbCreationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE);
    validateEntity(dbEntity, getEntityFromStore(db1));

    //Create Table
    //Update DB guid
    AtlasObjectId dbObjectId = (AtlasObjectId) tblEntity.getEntity().getAttribute("database");
    dbObjectId.setGuid(db1.getGuid());
    tblEntity.addReferredEntity(dbEntity.getEntity());

    init();
    EntityMutationResponse tableCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false);
    validateMutationResponse(tableCreationResponse, EntityOperation.CREATE, 1);
    tblEntityGuid = tableCreationResponse.getCreatedEntities().get(0).getGuid();

    AtlasEntityHeader tableEntity = tableCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE);
    validateEntity(tblEntity, getEntityFromStore(tableEntity));

    //Create nested-collection attribute entity
    init();
    EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(nestedCollectionAttrEntity), false);
    validateMutationResponse(entityMutationResponse, EntityOperation.CREATE, 1);

    AtlasEntityHeader createdEntity = entityMutationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.ENTITY_TYPE_WITH_NESTED_COLLECTION_ATTR);
    validateEntity(nestedCollectionAttrEntity, getEntityFromStore(createdEntity));
}
 
Example 4
Source File: AtlasInstanceConverter.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public CreateUpdateEntitiesResult toCreateUpdateEntitiesResult(EntityMutationResponse reponse) {
    CreateUpdateEntitiesResult ret = null;

    if (reponse != null) {
        Map<EntityOperation, List<AtlasEntityHeader>> mutatedEntities = reponse.getMutatedEntities();
        Map<String, String>                           guidAssignments = reponse.getGuidAssignments();

        ret = new CreateUpdateEntitiesResult();

        if (MapUtils.isNotEmpty(guidAssignments)) {
            ret.setGuidMapping(new GuidMapping(guidAssignments));
        }

        if (MapUtils.isNotEmpty(mutatedEntities)) {
            EntityResult entityResult = new EntityResult();

            for (Map.Entry<EntityOperation, List<AtlasEntityHeader>> e : mutatedEntities.entrySet()) {
                switch (e.getKey()) {
                    case CREATE:
                        List<AtlasEntityHeader> createdEntities = mutatedEntities.get(EntityOperation.CREATE);
                        if (CollectionUtils.isNotEmpty(createdEntities)) {
                            Collections.reverse(createdEntities);
                            entityResult.set(EntityResult.OP_CREATED, getGuids(createdEntities));
                        }
                        break;
                    case UPDATE:
                        List<AtlasEntityHeader> updatedEntities = mutatedEntities.get(EntityOperation.UPDATE);
                        if (CollectionUtils.isNotEmpty(updatedEntities)) {
                            Collections.reverse(updatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(updatedEntities));
                        }
                        break;
                    case PARTIAL_UPDATE:
                        List<AtlasEntityHeader> partialUpdatedEntities = mutatedEntities.get(EntityOperation.PARTIAL_UPDATE);
                        if (CollectionUtils.isNotEmpty(partialUpdatedEntities)) {
                            Collections.reverse(partialUpdatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(partialUpdatedEntities));
                        }
                        break;
                    case DELETE:
                        List<AtlasEntityHeader> deletedEntities = mutatedEntities.get(EntityOperation.DELETE);
                        if (CollectionUtils.isNotEmpty(deletedEntities)) {
                            Collections.reverse(deletedEntities);
                            entityResult.set(EntityResult.OP_DELETED, getGuids(deletedEntities));
                        }
                        break;
                }

            }

            ret.setEntityResult(entityResult);
        }
    }

    return ret;
}
 
Example 5
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreate() throws Exception {
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);

    validateMutationResponse(response, EntityOperation.CREATE, 5);
    AtlasEntityHeader dept1 = response.getFirstCreatedEntityByTypeName(TestUtilsV2.DEPARTMENT_TYPE);
    validateEntity(deptEntity, getEntityFromStore(dept1), deptEntity.getEntities().get(0));

    final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities();
    List<AtlasEntityHeader> entitiesCreated = entitiesMutated.get(EntityOperation.CREATE);

    Assert.assertTrue(entitiesCreated.size() >= deptEntity.getEntities().size());

    for (int i = 0; i < deptEntity.getEntities().size(); i++) {
        AtlasEntity expected = deptEntity.getEntities().get(i);
        AtlasEntity actual   = getEntityFromStore(entitiesCreated.get(i));

        validateEntity(deptEntity, actual, expected);
    }

    //Create DB
    init();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    validateMutationResponse(dbCreationResponse, EntityOperation.CREATE, 1);

    AtlasEntityHeader db1 = dbCreationResponse.getFirstCreatedEntityByTypeName(TestUtilsV2.DATABASE_TYPE);
    validateEntity(dbEntity, getEntityFromStore(db1));

    //Create Table
    //Update DB guid
    AtlasObjectId dbObjectId = (AtlasObjectId) tblEntity.getEntity().getAttribute("database");
    dbObjectId.setGuid(db1.getGuid());
    tblEntity.addReferredEntity(dbEntity.getEntity());

    init();
    EntityMutationResponse tableCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tblEntity), false);
    validateMutationResponse(tableCreationResponse, EntityOperation.CREATE, 1);

    AtlasEntityHeader tableEntity = tableCreationResponse.getFirstCreatedEntityByTypeName(TABLE_TYPE);
    validateEntity(tblEntity, getEntityFromStore(tableEntity));
}