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

The following examples show how to use org.apache.atlas.model.instance.EntityMutationResponse#getCreatedEntityByTypeNameAndAttribute() . 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: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetObjectIdAttrToNull() throws Exception {
    final AtlasEntity dbEntity  = TestUtilsV2.createDBEntity();
    final AtlasEntity db2Entity = TestUtilsV2.createDBEntity();

    entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    entityStore.createOrUpdate(new AtlasEntityStream(db2Entity), false);

    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);

    tableEntity.setAttribute("databaseComposite", AtlasTypeUtil.getAtlasObjectId(db2Entity));

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false);
    final AtlasEntityHeader      createdTblHeader    = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity            createdTblEntity    = getEntityFromStore(createdTblHeader);

    init();

    createdTblEntity.setAttribute("databaseComposite", null);

    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true);
    final AtlasEntityHeader      updatedTblHeader  = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity            updatedTblEntity  = getEntityFromStore(updatedTblHeader);
    final AtlasEntity            deletedDb2Entity  = getEntityFromStore(db2Entity.getGuid());

    assertEquals(deletedDb2Entity.getStatus(), AtlasEntity.Status.DELETED);
}
 
Example 2
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetObjectIdAttrToNull() throws Exception {
    final AtlasEntity dbEntity  = TestUtilsV2.createDBEntity();
    final AtlasEntity db2Entity = TestUtilsV2.createDBEntity();

    entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    entityStore.createOrUpdate(new AtlasEntityStream(db2Entity), false);

    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);

    tableEntity.setAttribute("databaseComposite", AtlasTypeUtil.getAtlasObjectId(db2Entity));

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false);
    final AtlasEntityHeader      createdTblHeader    = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity            createdTblEntity    = getEntityFromStore(createdTblHeader);

    init();

    createdTblEntity.setAttribute("databaseComposite", null);

    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true);
    final AtlasEntityHeader      updatedTblHeader  = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity            updatedTblEntity  = getEntityFromStore(updatedTblHeader);
    final AtlasEntity            deletedDb2Entity  = getEntityFromStore(db2Entity.getGuid());

    assertEquals(deletedDb2Entity.getStatus(), AtlasEntity.Status.DELETED);
}
 
Example 3
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testPartialUpdateArrayAttr() throws Exception {
    // Create a table entity, with 3 reference column entities
    init();
    final AtlasEntity      dbEntity           = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);

    final AtlasEntity        tableEntity      = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntitiesWithExtInfo entitiesInfo     = new AtlasEntitiesWithExtInfo(tableEntity);

    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity1.setAttribute("description", "desc for col1");
    entitiesInfo.addReferredEntity(columnEntity1);

    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity2.setAttribute("description", "desc for col2");
    entitiesInfo.addReferredEntity(columnEntity2);

    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity3.setAttribute("description", "desc for col3");
    entitiesInfo.addReferredEntity(columnEntity3);

    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity2),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity3)));

    init();

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    final AtlasEntityHeader      createdTblHeader    = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity            createdTblEntity    = getEntityFromStore(createdTblHeader);

    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));

    // update only description attribute of all 3 columns
    AtlasEntity col1 = new AtlasEntity(COLUMN_TYPE);
    col1.setGuid(column1Created.getGuid());
    col1.setAttribute("description", "desc for col1:updated");

    AtlasEntity col2 = new AtlasEntity(COLUMN_TYPE);
    col2.setGuid(column2Created.getGuid());
    col2.setAttribute("description", "desc for col2:updated");

    AtlasEntity col3 = new AtlasEntity(COLUMN_TYPE);
    col3.setGuid(column3Created.getGuid());
    col3.setAttribute("description", "desc for col3:updated");

    final AtlasEntity tableEntity1 = new AtlasEntity(TABLE_TYPE);
    tableEntity1.setGuid(createdTblHeader.getGuid());
    tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(col1),
            AtlasTypeUtil.getAtlasObjectId(col2),
            AtlasTypeUtil.getAtlasObjectId(col3)));
    AtlasEntitiesWithExtInfo tableInfo = new AtlasEntitiesWithExtInfo(tableEntity1);
    tableInfo.addReferredEntity(col1.getGuid(), col1);
    tableInfo.addReferredEntity(col2.getGuid(), col2);
    tableInfo.addReferredEntity(col3.getGuid(), col3);

    init();

    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableInfo), true);
    final AtlasEntityHeader      updatedTblHeader  = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity            updatedTblEntity2 = getEntityFromStore(updatedTblHeader);
    List<AtlasEntityHeader>      updatedColHeaders = tblUpdateResponse.getPartialUpdatedEntitiesByTypeName(COLUMN_TYPE);

    final AtlasEntity updatedCol1Entity = getEntityFromStore(updatedColHeaders.get(0));
    final AtlasEntity updatedCol2Entity = getEntityFromStore(updatedColHeaders.get(1));
    final AtlasEntity updatedCol3Entity = getEntityFromStore(updatedColHeaders.get(2));

    assertEquals(col1.getAttribute("description"), updatedCol1Entity.getAttribute("description"));
    assertEquals(col2.getAttribute("description"), updatedCol2Entity.getAttribute("description"));
    assertEquals(col3.getAttribute("description"), updatedCol3Entity.getAttribute("description"));
}
 
Example 4
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testPartialUpdateArrayAttr() throws Exception {
    // Create a table entity, with 3 reference column entities
    init();
    final AtlasEntity      dbEntity           = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);

    final AtlasEntity        tableEntity      = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntitiesWithExtInfo entitiesInfo     = new AtlasEntitiesWithExtInfo(tableEntity);

    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity1.setAttribute("description", "desc for col1");
    entitiesInfo.addReferredEntity(columnEntity1);

    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity2.setAttribute("description", "desc for col2");
    entitiesInfo.addReferredEntity(columnEntity2);

    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    columnEntity3.setAttribute("description", "desc for col3");
    entitiesInfo.addReferredEntity(columnEntity3);

    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity2),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity3)));

    init();

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    final AtlasEntityHeader      createdTblHeader    = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    final AtlasEntity            createdTblEntity    = getEntityFromStore(createdTblHeader);

    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));

    // update only description attribute of all 3 columns
    AtlasEntity col1 = new AtlasEntity(COLUMN_TYPE);
    col1.setGuid(column1Created.getGuid());
    col1.setAttribute("description", "desc for col1:updated");

    AtlasEntity col2 = new AtlasEntity(COLUMN_TYPE);
    col2.setGuid(column2Created.getGuid());
    col2.setAttribute("description", "desc for col2:updated");

    AtlasEntity col3 = new AtlasEntity(COLUMN_TYPE);
    col3.setGuid(column3Created.getGuid());
    col3.setAttribute("description", "desc for col3:updated");

    final AtlasEntity tableEntity1 = new AtlasEntity(TABLE_TYPE);
    tableEntity1.setGuid(createdTblHeader.getGuid());
    tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(col1),
            AtlasTypeUtil.getAtlasObjectId(col2),
            AtlasTypeUtil.getAtlasObjectId(col3)));
    AtlasEntitiesWithExtInfo tableInfo = new AtlasEntitiesWithExtInfo(tableEntity1);
    tableInfo.addReferredEntity(col1.getGuid(), col1);
    tableInfo.addReferredEntity(col2.getGuid(), col2);
    tableInfo.addReferredEntity(col3.getGuid(), col3);

    init();

    final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableInfo), true);
    final AtlasEntityHeader      updatedTblHeader  = tblUpdateResponse.getFirstEntityPartialUpdated();
    final AtlasEntity            updatedTblEntity2 = getEntityFromStore(updatedTblHeader);
    List<AtlasEntityHeader>      updatedColHeaders = tblUpdateResponse.getPartialUpdatedEntitiesByTypeName(COLUMN_TYPE);

    final AtlasEntity updatedCol1Entity = getEntityFromStore(updatedColHeaders.get(0));
    final AtlasEntity updatedCol2Entity = getEntityFromStore(updatedColHeaders.get(1));
    final AtlasEntity updatedCol3Entity = getEntityFromStore(updatedColHeaders.get(2));

    assertEquals(col1.getAttribute("description"), updatedCol1Entity.getAttribute("description"));
    assertEquals(col2.getAttribute("description"), updatedCol2Entity.getAttribute("description"));
    assertEquals(col3.getAttribute("description"), updatedCol3Entity.getAttribute("description"));
}
 
Example 5
Source File: AtlasDeleteHandlerV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteEntities() throws Exception {
    // Create a table entity, with 3 composite column entities
    init();
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);

    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntity.AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntity.AtlasEntitiesWithExtInfo(tableEntity);

    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity1);
    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity2);
    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity3);

    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity2),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity3)));

    init();

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);

    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));

    // Retrieve the table entities from the Repository, to get their guids and the composite column guids.
    ITypedReferenceableInstance tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    List<IReferenceableInstance> columns = (List<IReferenceableInstance>) tableInstance.get(COLUMNS_ATTR_NAME);

    //Delete column
    String colId = columns.get(0).getId()._getId();
    String tableId = tableInstance.getId()._getId();

    init();

    EntityMutationResponse deletionResponse = entityStore.deleteById(colId);
    assertEquals(deletionResponse.getDeletedEntities().size(), 1);
    assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), colId);
    assertEquals(deletionResponse.getUpdatedEntities().size(), 1);
    assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableId);
    assertEntityDeleted(colId);

    final AtlasEntity.AtlasEntityWithExtInfo tableEntityCreated = entityStore.getById(tableId);
    assertDeletedColumn(tableEntityCreated);

    assertTestDisconnectUnidirectionalArrayReferenceFromClassType(
        (List<AtlasObjectId>) tableEntityCreated.getEntity().getAttribute(COLUMNS_ATTR_NAME), colId);

    //update by removing a column - col1
    final AtlasEntity tableEntity1 = TestUtilsV2.createTableEntity(dbEntity, (String) tableEntity.getAttribute(NAME));

    AtlasEntity.AtlasEntitiesWithExtInfo entitiesInfo1 = new AtlasEntity.AtlasEntitiesWithExtInfo(tableEntity1);
    final AtlasEntity columnEntity3New = TestUtilsV2.createColumnEntity(tableEntity1, (String) column3Created.getAttribute(NAME));
    tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity3New)));
    entitiesInfo1.addReferredEntity(columnEntity3New);

    init();
    deletionResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo1), false);

    assertEquals(deletionResponse.getDeletedEntities().size(), 1);
    assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), column2Created.getGuid());
    assertEntityDeleted(colId);

    // Delete the table entities.  The deletion should cascade to their composite columns.
    tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));

    init();
    EntityMutationResponse tblDeletionResponse = entityStore.deleteById(tableInstance.getId()._getId());
    assertEquals(tblDeletionResponse.getDeletedEntities().size(), 2);

    final AtlasEntityHeader tableDeleted = tblDeletionResponse.getFirstDeletedEntityByTypeName(TABLE_TYPE);
    final AtlasEntityHeader colDeleted = tblDeletionResponse.getFirstDeletedEntityByTypeName(COLUMN_TYPE);

    // Verify that deleteEntities() response has guids for tables and their composite columns.
    Assert.assertTrue(tableDeleted.getGuid().equals(tableInstance.getId()._getId()));
    Assert.assertTrue(colDeleted.getGuid().equals(column3Created.getGuid()));

    // Verify that tables and their composite columns have been deleted from the graph Repository.
    assertEntityDeleted(tableDeleted.getGuid());
    assertEntityDeleted(colDeleted.getGuid());

}
 
Example 6
Source File: AtlasDeleteHandlerV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testUpdateEntity_MultiplicityOneNonCompositeReference() throws Exception {
    AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
    init();

    RequestContextV1.clear();
    final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);
    final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstUpdatedEntityByTypeName(DEPARTMENT_TYPE);
    final AtlasEntityHeader maxEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max");
    final AtlasEntityHeader johnEmployeeCreated = hrDeptCreationResponse.getUpdatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");
    final AtlasEntityHeader janeEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane");
    final AtlasEntityHeader juliusEmployeeCreated = hrDeptCreationResponse.getUpdatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius");

    ITypedReferenceableInstance max = metadataService.getEntityDefinition(maxEmployeeCreated.getGuid());
    String maxGuid = max.getId()._getId();
    AtlasVertex vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long creationTimestamp = GraphHelper.getSingleValuedProperty(vertex, Constants.TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(creationTimestamp);

    Long modificationTimestampPreUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPreUpdate);

    AtlasEntity maxEmployee = getEmployeeByName(hrDept, "Max");
    maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(johnEmployeeCreated));
    maxEmployee.setAttribute("department", AtlasTypeUtil.getAtlasObjectId(deptCreated));
    maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));

    init();
    EntityMutationResponse entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);

    assertEquals(entityResult.getUpdatedEntities().size(), 1);
    assertTrue(extractGuids(entityResult.getUpdatedEntities()).contains(maxGuid));

    // Verify the update was applied correctly - john should now be max's mentor.
    max = metadataService.getEntityDefinition(maxGuid);
    ITypedReferenceableInstance refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), johnEmployeeCreated.getGuid());

    // Verify modification timestamp was updated.
    vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long modificationTimestampPostUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPostUpdate);
    Assert.assertTrue(creationTimestamp < modificationTimestampPostUpdate);

    // Update max's mentor reference to jane.
    maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));
    init();
    entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
    assertEquals(entityResult.getUpdatedEntities().size(), 1);
    assertTrue(extractGuids(entityResult.getUpdatedEntities()).contains(maxGuid));

    // Verify the update was applied correctly - jane should now be max's mentor.
    max = metadataService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("mentor");
    Assert.assertEquals(refTarget.getId()._getId(), janeEmployeeCreated.getGuid());

    // Verify modification timestamp was updated.
    vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid);
    Long modificationTimestampPost2ndUpdate = GraphHelper.getSingleValuedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
    Assert.assertNotNull(modificationTimestampPost2ndUpdate);
    Assert.assertTrue(modificationTimestampPostUpdate < modificationTimestampPost2ndUpdate);

    ITypedReferenceableInstance julius = metadataService.getEntityDefinition(juliusEmployeeCreated.getGuid());
    Id juliusId = julius.getId();

    init();
    maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(juliusEmployeeCreated));
    entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
    assertEquals(entityResult.getUpdatedEntities().size(), 3);
    List<String> updatedGuids = extractGuids(entityResult.getUpdatedEntities());
    assertTrue(updatedGuids.contains(maxGuid));
    assertTrue(updatedGuids.contains(janeEmployeeCreated.getGuid()));
    // Should have updated julius to add max in subordinates list.
    assertTrue(updatedGuids.contains(juliusEmployeeCreated.getGuid()));

    // Verify the update was applied correctly - julius should now be max's manager and max should be julius' subordinate.
    max = metadataService.getEntityDefinition(maxGuid);
    refTarget = (ITypedReferenceableInstance) max.get("manager");
    Assert.assertEquals(refTarget.getId()._getId(), juliusId._getId());
    julius = metadataService.getEntityDefinition(juliusId._getId());
    Object value = julius.get("subordinates");
    Assert.assertTrue(value instanceof List);
    List<ITypedReferenceableInstance> refList = (List<ITypedReferenceableInstance>) value;
    Assert.assertEquals(refList.size(), 1);
    Assert.assertEquals(refList.get(0).getId()._getId(), maxGuid);

    assertTestUpdateEntity_MultiplicityOneNonCompositeReference(janeEmployeeCreated.getGuid());
}
 
Example 7
Source File: AtlasDeleteHandlerV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
/**
 * Verify deleting an entity which is contained by another
 * entity through a bi-directional composite reference.
 *
 * @throws Exception
 */
@Test
public void testDisconnectBidirectionalReferences() throws Exception {
    AtlasEntity.AtlasEntitiesWithExtInfo hrDept = TestUtilsV2.createDeptEg2();
    init();
    final EntityMutationResponse hrDeptCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(hrDept), false);

    final AtlasEntityHeader deptCreated = hrDeptCreationResponse.getFirstCreatedEntityByTypeName(DEPARTMENT_TYPE);
    final AtlasEntityHeader maxEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "Max");
    final AtlasEntityHeader johnEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");
    final AtlasEntityHeader janeEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane");
    final AtlasEntityHeader juliusEmployee = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius");

    ITypedReferenceableInstance hrDeptInstance = metadataService.getEntityDefinition(deptCreated.getGuid());
    Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDeptInstance);

    // Verify that Max is one of Jane's subordinates.
    ITypedReferenceableInstance jane = metadataService.getEntityDefinition(janeEmployee.getGuid());
    Object refValue = jane.get("subordinates");
    Assert.assertTrue(refValue instanceof List);
    List<Object> subordinates = (List<Object>)refValue;
    Assert.assertEquals(subordinates.size(), 2);
    List<String> subordinateIds = new ArrayList<>(2);
    for (Object listValue : subordinates) {
        Assert.assertTrue(listValue instanceof ITypedReferenceableInstance);
        ITypedReferenceableInstance employee = (ITypedReferenceableInstance) listValue;
        subordinateIds.add(employee.getId()._getId());
    }
    Assert.assertTrue(subordinateIds.contains(maxEmployee.getGuid()));

    init();
    EntityMutationResponse entityResult = entityStore.deleteById(maxEmployee.getGuid());
    ITypedReferenceableInstance john = metadataService.getEntityDefinitionReference(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John");

    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), maxEmployee.getGuid());
    assertEquals(entityResult.getUpdatedEntities().size(), 3);

    assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(janeEmployee.getGuid(), deptCreated.getGuid(), johnEmployee.getGuid()));
    assertEntityDeleted(maxEmployee.getGuid());

    assertMaxForTestDisconnectBidirectionalReferences(nameGuidMap);

    // Now delete jane - this should disconnect the manager reference from her
    // subordinate.
    init();
    entityResult = entityStore.deleteById(janeEmployee.getGuid());
    assertEquals(entityResult.getDeletedEntities().size(), 1);
    assertEquals(entityResult.getDeletedEntities().get(0).getGuid(), janeEmployee.getGuid());
    assertEquals(entityResult.getUpdatedEntities().size(), 2);
    assertEquals(extractGuids(entityResult.getUpdatedEntities()), Arrays.asList(deptCreated.getGuid(), johnEmployee.getGuid()));

    assertEntityDeleted(janeEmployee.getGuid());

    final AtlasEntity.AtlasEntityWithExtInfo johnUpdated = entityStore.getById(johnEmployee.getGuid());
    assertJohnForTestDisconnectBidirectionalReferences(johnUpdated, janeEmployee.getGuid());
}
 
Example 8
Source File: AtlasDeleteHandlerV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteByUniqueAttribute() throws Exception {
    // Create a table entity, with 3 composite column entities
    init();
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);

    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntity.AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntity.AtlasEntitiesWithExtInfo(tableEntity);

    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity1);
    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity2);
    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity3);

    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity2),
                                                              AtlasTypeUtil.getAtlasObjectId(columnEntity3)));

    init();

    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);

    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));

    // Retrieve the table entities from the Repository, to get their guids and the composite column guids.
    ITypedReferenceableInstance tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    List<IReferenceableInstance> columns = (List<IReferenceableInstance>) tableInstance.get(COLUMNS_ATTR_NAME);

    //Delete column
    String colId = columns.get(0).getId()._getId();
    String tableId = tableInstance.getId()._getId();

    init();

    Map<String, Object> uniqueAttrs = new HashMap<>();
    uniqueAttrs.put(NAME, column1Created.getAttribute(NAME));

    AtlasEntityType columnType = typeRegistry.getEntityTypeByName(COLUMN_TYPE);
    EntityMutationResponse deletionResponse = entityStore.deleteByUniqueAttributes(columnType, uniqueAttrs);
    assertEquals(deletionResponse.getDeletedEntities().size(), 1);
    assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), colId);
    assertEquals(deletionResponse.getUpdatedEntities().size(), 1);
    assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableId);
    assertEntityDeleted(colId);
}