Search in sources :

Example 1 with Result

use of org.apache.atlas.catalog.Result 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 Result

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

the class EntityService method getEntities.

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

Example 3 with Result

use of org.apache.atlas.catalog.Result 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 4 with Result

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

the class TaxonomyServiceTest method testGetTaxonomy.

@Test
public void testGetTaxonomy() throws Exception {
    String taxonomyName = "testTaxonomy";
    MetadataService metadataService = createStrictMock(MetadataService.class);
    AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
    ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
    UriInfo uriInfo = createNiceMock(UriInfo.class);
    JsonSerializer serializer = createStrictMock(JsonSerializer.class);
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
    Map<String, Object> propertyMap = new HashMap<>();
    propertyMap.put("name", "testTaxonomy");
    resultPropertyMaps.add(propertyMap);
    Result result = new Result(resultPropertyMaps);
    expect(taxonomyResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
    expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
    expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Get Response");
    replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
    TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
    Response response = service.getTaxonomy(null, uriInfo, taxonomyName);
    Request request = requestCapture.getValue();
    Map<String, Object> requestProperties = request.getQueryProperties();
    assertEquals(requestProperties.size(), 1);
    assertEquals(requestProperties.get("name"), taxonomyName);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getEntity(), "Taxonomy Get Response");
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 5 with Result

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

the class TaxonomyServiceTest method testGetSubTerms_collection.

@Test
public void testGetSubTerms_collection() throws Exception {
    MetadataService metadataService = createStrictMock(MetadataService.class);
    AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
    ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
    UriInfo uriInfo = createNiceMock(UriInfo.class);
    URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2/terms?name:testTaxonomy.testTerm.testTerm2.testTerm3");
    JsonSerializer serializer = createStrictMock(JsonSerializer.class);
    // would actually be more segments but at this time only the last segment is used
    PathSegment segment1 = createNiceMock(PathSegment.class);
    PathSegment segment2 = createNiceMock(PathSegment.class);
    PathSegment segment3 = createNiceMock(PathSegment.class);
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
    Map<String, Object> propertyMap = new HashMap<>();
    propertyMap.put("name", "testTaxonomy.testTerm.testTerm2.testTerm3");
    resultPropertyMaps.add(propertyMap);
    Result result = new Result(resultPropertyMaps);
    // set mock expectations
    expect(uriInfo.getRequestUri()).andReturn(uri);
    expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
    expect(segment3.getPath()).andReturn("terms");
    expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result);
    expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
    expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
    replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
    // instantiate service and invoke method being tested
    TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
    Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2/terms");
    Request request = requestCapture.getValue();
    assertEquals(request.getQueryProperties().size(), 1);
    TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
    assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2.");
    assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm.testTerm2.testTerm3");
    assertEquals(response.getStatus(), 200);
    assertEquals(response.getEntity(), "Taxonomy Term Get Response");
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) PathSegment(javax.ws.rs.core.PathSegment) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

Result (org.apache.atlas.catalog.Result)10 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Response (javax.ws.rs.core.Response)6 UriInfo (javax.ws.rs.core.UriInfo)6 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)6 Request (org.apache.atlas.catalog.Request)6 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)6 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)6 MetadataService (org.apache.atlas.services.MetadataService)6 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)6 Test (org.testng.annotations.Test)6 URI (java.net.URI)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 TermPath (org.apache.atlas.catalog.TermPath)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 Path (javax.ws.rs.Path)3 BaseRequest (org.apache.atlas.catalog.BaseRequest)3