Search in sources :

Example 31 with AtlasEntityHeader

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

the class AtlasInstanceConverter method toCreateUpdateEntitiesResult.

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;
}
Also used : EntityOperation(org.apache.atlas.model.instance.EntityMutations.EntityOperation) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) ArrayList(java.util.ArrayList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Map(java.util.Map) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Example 32 with AtlasEntityHeader

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

the class EntityGraphRetriever method mapVertexToAtlasEntityHeader.

private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex) throws AtlasBaseException {
    AtlasEntityHeader ret = new AtlasEntityHeader();
    String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
    String guid = entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
    ret.setTypeName(typeName);
    ret.setGuid(guid);
    ret.setStatus(GraphHelper.getStatus(entityVertex));
    ret.setClassificationNames(GraphHelper.getTraitNames(entityVertex));
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
    if (entityType != null) {
        for (AtlasAttribute uniqueAttribute : entityType.getUniqAttributes().values()) {
            Object attrValue = getVertexAttribute(entityVertex, uniqueAttribute);
            if (attrValue != null) {
                ret.setAttribute(uniqueAttribute.getName(), attrValue);
            }
        }
        Object name = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME));
        Object description = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.DESCRIPTION));
        Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.OWNER));
        Object displayText = name != null ? name : ret.getAttribute(AtlasClient.QUALIFIED_NAME);
        ret.setAttribute(AtlasClient.NAME, name);
        ret.setAttribute(AtlasClient.DESCRIPTION, description);
        ret.setAttribute(AtlasClient.OWNER, owner);
        if (displayText != null) {
            ret.setDisplayText(displayText.toString());
        }
    }
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Example 33 with AtlasEntityHeader

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

the class EntityV2JerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(classType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(classTypeDef);
    createType(atlasTypesDef);
    AtlasEntity instance = new AtlasEntity(classType);
    instance.setAttribute(attrName, attrValue);
    AtlasEntityHeader entity = createEntity(instance);
    assertNotNull(entity);
    assertNotNull(entity.getGuid());
    AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
    assertEquals(entityByGuid.getAttribute(attrName), attrValue);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 34 with AtlasEntityHeader

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

the class EntityV2JerseyResourceIT method testDeleteEntities.

@Test
public void testDeleteEntities() throws Exception {
    // Create 2 database entities
    AtlasEntity db1 = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName1 = randomString();
    db1.setAttribute("name", dbName1);
    db1.setAttribute(NAME, dbName1);
    db1.setAttribute("clusterName", randomString());
    db1.setAttribute("description", randomString());
    AtlasEntityHeader entity1Header = createEntity(db1);
    AtlasEntity db2 = new AtlasEntity(DATABASE_TYPE_V2);
    String dbName2 = randomString();
    db2.setAttribute("name", dbName2);
    db2.setAttribute(NAME, dbName2);
    db2.setAttribute("clusterName", randomString());
    db2.setAttribute("description", randomString());
    AtlasEntityHeader entity2Header = createEntity(db2);
    // Delete the database entities
    EntityMutationResponse deleteResponse = atlasClientV2.deleteEntitiesByGuids(ImmutableList.of(entity1Header.getGuid(), entity2Header.getGuid()));
    // Verify that deleteEntities() response has database entity guids
    assertNotNull(deleteResponse);
    assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
// Verify entities were deleted from the repository.
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 35 with AtlasEntityHeader

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

the class EntityResourceTest method testDeleteEntitiesDoesNotLookupDeletedEntity.

@Test
public void testDeleteEntitiesDoesNotLookupDeletedEntity() throws Exception {
    List<String> guids = Collections.singletonList(DELETED_GUID);
    List<AtlasEntityHeader> deletedEntities = Collections.singletonList(new AtlasEntityHeader(null, DELETED_GUID, null));
    // Create EntityResult with a deleted guid and no other guids.
    EntityMutationResponse resp = new EntityMutationResponse();
    List<AtlasEntityHeader> headers = toAtlasEntityHeaders(guids);
    if (CollectionUtils.isNotEmpty(headers)) {
        for (AtlasEntityHeader entity : headers) {
            resp.addEntity(EntityMutations.EntityOperation.DELETE, entity);
        }
    }
    when(entitiesStore.deleteByIds(guids)).thenReturn(resp);
    EntityMutationResponse response = entitiesStore.deleteByIds(guids);
    List<AtlasEntityHeader> responseDeletedEntities = response.getDeletedEntities();
    Assert.assertEquals(responseDeletedEntities, deletedEntities);
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)65 Test (org.testng.annotations.Test)46 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)38 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)15 ArrayList (java.util.ArrayList)14 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)14 HashMap (java.util.HashMap)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)12 List (java.util.List)10 Map (java.util.Map)8 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)6 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)5