Search in sources :

Example 71 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.

the class TypesREST method getEntityDefByGuid.

/**
 * Get the Entity definition for the given guid
 * @param guid entity guid
 * @return Entity definition
 * @throws AtlasBaseException
 * @HTTP 200 On successful lookup of the the entity definition by it's guid
 * @HTTP 404 On Failed lookup for the given guid
 */
@GET
@Path("/entitydef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasEntityDef ret = typeDefStore.getEntityDefByGuid(guid);
    return ret;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef)

Example 72 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.

the class TypesREST method getEntityDefByName.

/**
 * Get the entity definition by it's name (unique)
 * @param name entity name
 * @return Entity definition
 * @throws AtlasBaseException
 * @HTTP 200 On successful lookup of the the entity definition by it's name
 * @HTTP 404 On Failed lookup for the given name
 */
@GET
@Path("/entitydef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByName(@PathParam("name") String name) throws AtlasBaseException {
    Servlets.validateQueryParamLength("name", name);
    AtlasEntityDef ret = typeDefStore.getEntityDefByName(name);
    return ret;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef)

Example 73 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.

the class EntityV2JerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.

@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
    // create type
    AtlasEntityDef entityDef = AtlasTypeUtil.createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entityDef);
    AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    assertNotNull(created.getEntityDefs());
    assertEquals(created.getEntityDefs().size(), 1);
    // create entity for the type
    AtlasEntity instance = new AtlasEntity(entityDef.getName());
    instance.setAttribute("name", randomString());
    EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
    assertNotNull(mutationResponse);
    assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
    assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 1);
    String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
    // update type - add attribute
    entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
    typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entityDef);
    AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
    assertNotNull(updated);
    assertNotNull(updated.getEntityDefs());
    assertEquals(updated.getEntityDefs().size(), 1);
    // Get definition after type update - new attributes should be null
    AtlasEntity entityByGuid = getEntityByGuid(guid);
    assertNull(entityByGuid.getAttribute("description"));
    assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 74 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.

the class TypedefsJerseyResourceIT method testInvalidGets.

@Test
public void testInvalidGets() throws Exception {
    try {
        AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byName = clientV2.getStructDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) Test(org.testng.annotations.Test)

Example 75 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.

the class TypedefsJerseyResourceIT method testDuplicateCreate.

@Test
public void testDuplicateCreate() throws Exception {
    AtlasEntityDef type = createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(type);
    AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    try {
        created = clientV2.createAtlasTypeDefs(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)141 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)55 Test (org.testng.annotations.Test)51 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)40 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)37 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)31 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)31 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)30 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)21 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)14 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)13 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)13 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)9 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)8