Search in sources :

Example 1 with InstanceRequest

use of org.apache.atlas.catalog.InstanceRequest in project incubator-atlas by apache.

the class EntityService method getEntity.

@GET
@Path("{entityId}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntity(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("entityId") String entityId) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntity(" + entityId + ")");
        }
        BaseRequest request = new InstanceRequest(Collections.<String, Object>singletonMap("id", entityId));
        Result result = getResource(entityResourceProvider, request);
        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) BaseRequest(org.apache.atlas.catalog.BaseRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Result(org.apache.atlas.catalog.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with InstanceRequest

use of org.apache.atlas.catalog.InstanceRequest in project incubator-atlas by apache.

the class EntityService method getEntityTag.

@GET
@Path("{entityId}/tags/{tag}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntityTag(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("entityId") String entityId, @PathParam("tag") String tagName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTag(" + entityId + ", " + tagName + ")");
        }
        Map<String, Object> properties = new HashMap<>();
        properties.put("id", entityId);
        properties.put("name", tagName);
        Result result = getResource(entityTagResourceProvider, new InstanceRequest(properties));
        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Result(org.apache.atlas.catalog.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with InstanceRequest

use of org.apache.atlas.catalog.InstanceRequest in project incubator-atlas by apache.

the class EntityService method deleteEntityTag.

@DELETE
@Path("{entityId}/tags/{tag}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response deleteEntityTag(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("entityId") String entityId, @PathParam("tag") String tagName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.deleteEntityTag()");
        }
        Map<String, Object> properties = new HashMap<>();
        properties.put("id", entityId);
        properties.put("name", tagName);
        deleteResource(entityTagResourceProvider, new InstanceRequest(properties));
        return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 4 with InstanceRequest

use of org.apache.atlas.catalog.InstanceRequest in project incubator-atlas by apache.

the class QueryFactoryTest method testCreateEntityTagQuery.

@Test
public void testCreateEntityTagQuery() throws Exception {
    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put("id", "entity_id");
    requestProps.put("name", "test_taxonomy.term1");
    Request request = new InstanceRequest(requestProps);
    QueryFactory factory = new QueryFactory();
    AtlasEntityTagQuery query = (AtlasEntityTagQuery) factory.createEntityTagQuery(request);
    QueryExpression queryExpression = query.getQueryExpression();
    assertEquals(queryExpression.getClass(), TermQueryExpression.class);
    assertEquals(queryExpression.getField(), "name");
    assertEquals(queryExpression.getExpectedValue(), "test_taxonomy.term1");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getClass(), EntityTagResourceDefinition.class);
}
Also used : HashMap(java.util.HashMap) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Example 5 with InstanceRequest

use of org.apache.atlas.catalog.InstanceRequest in project incubator-atlas by apache.

the class TaxonomyResourceDefinitionTest method testValidate_invalidProperty.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testValidate_invalidProperty() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("name", "foo");
    properties.put("unknownProperty", "value");
    Request request = new InstanceRequest(properties);
    ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition();
    taxonomyDefinition.validateCreatePayload(request);
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Aggregations

InstanceRequest (org.apache.atlas.catalog.InstanceRequest)24 CollectionRequest (org.apache.atlas.catalog.CollectionRequest)20 Request (org.apache.atlas.catalog.Request)20 Test (org.testng.annotations.Test)20 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 GET (javax.ws.rs.GET)2 Result (org.apache.atlas.catalog.Result)2 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 BaseRequest (org.apache.atlas.catalog.BaseRequest)1 TermPath (org.apache.atlas.catalog.TermPath)1