Search in sources :

Example 31 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method updateEntityAttributeByGuid.

@Override
@GraphTransaction
public EntityMutationResponse updateEntityAttributeByGuid(String guid, String attrName, Object attrValue) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntityAttributeByGuid({}, {}, {})", guid, attrName, attrValue);
    }
    AtlasEntityWithExtInfo entityInfo = getById(guid);
    if (entityInfo == null || entityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    AtlasEntity entity = entityInfo.getEntity();
    AtlasEntityType entityType = (AtlasEntityType) typeRegistry.getType(entity.getTypeName());
    AtlasAttribute attr = entityType.getAttribute(attrName);
    if (attr == null) {
        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, entity.getTypeName());
    }
    AtlasType attrType = attr.getAttributeType();
    AtlasEntity updateEntity = new AtlasEntity();
    updateEntity.setGuid(guid);
    updateEntity.setTypeName(entity.getTypeName());
    switch(attrType.getTypeCategory()) {
        case PRIMITIVE:
            updateEntity.setAttribute(attrName, attrValue);
            break;
        case OBJECT_ID_TYPE:
            AtlasObjectId objId;
            if (attrValue instanceof String) {
                objId = new AtlasObjectId((String) attrValue, attr.getAttributeDef().getTypeName());
            } else {
                objId = (AtlasObjectId) attrType.getNormalizedValue(attrValue);
            }
            updateEntity.setAttribute(attrName, objId);
            break;
        default:
            throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_UPDATE_NOT_SUPPORTED, attrName, attrType.getTypeName());
    }
    return createOrUpdate(new AtlasEntityStream(updateEntity), true);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasType(org.apache.atlas.type.AtlasType) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 32 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo in project incubator-atlas by apache.

the class TestEntityREST method testGetEntityById.

@Test
public void testGetEntityById() throws Exception {
    createTestEntity();
    AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid());
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.getEntity());
    TestEntitiesREST.verifyAttributes(response.getEntity().getAttributes(), dbEntity.getAttributes());
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) Test(org.testng.annotations.Test)

Example 33 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo in project incubator-atlas by apache.

the class TestEntityREST method testUpdateGetDeleteEntityByUniqueAttribute.

@Test
public void testUpdateGetDeleteEntityByUniqueAttribute() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
    String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
    Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));
    final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
    final String updatedDBName = prevDBName + ":updated";
    dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
    response = entityREST.partialUpdateEntityByUniqueAttrs(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, prevDBName), new AtlasEntityWithExtInfo(dbEntity));
    Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
    //Get By unique attribute
    AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
    Assert.assertNotNull(entity);
    Assert.assertNotNull(entity.getEntity().getGuid());
    Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
    TestEntitiesREST.verifyAttributes(entity.getEntity().getAttributes(), dbEntity.getAttributes());
    final EntityMutationResponse deleteResponse = entityREST.deleteByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, (String) dbEntity.getAttribute(TestUtilsV2.NAME)));
    Assert.assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).get(0).getGuid(), dbGuid);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Test(org.testng.annotations.Test)

Example 34 with AtlasEntityWithExtInfo

use of org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo in project incubator-atlas by apache.

the class TestEntityREST method testPartialUpdateByUniqueAttribute.

@Test
public void testPartialUpdateByUniqueAttribute() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
    String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
    Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));
    final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
    final String updatedDBName = prevDBName + ":updated";
    Map<String, Object> dbAttrs = dbEntity.getAttributes();
    // partial update only db name
    dbEntity = new AtlasEntity(TestUtilsV2.DATABASE_TYPE);
    dbEntity.setGuid(dbGuid);
    dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);
    dbAttrs.putAll(dbEntity.getAttributes());
    response = entityREST.partialUpdateEntityByUniqueAttrs(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, prevDBName), new AtlasEntityWithExtInfo(dbEntity));
    Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);
    //Get By unique attribute
    AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
    Assert.assertNotNull(entity);
    Assert.assertNotNull(entity.getEntity().getGuid());
    Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
    TestEntitiesREST.verifyAttributes(entity.getEntity().getAttributes(), dbAttrs);
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)34 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)24 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)18 Test (org.testng.annotations.Test)17 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 HashMap (java.util.HashMap)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)5 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)4 BeforeTest (org.testng.annotations.BeforeTest)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)2 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2