Search in sources :

Example 1 with CollectionRequest

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

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

the class EntityService method tagEntities.

@POST
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response tagEntities(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntities()");
        }
        Map<String, Object> properties = parsePayload(body);
        if (properties.get("tags") == null || properties.size() != 1) {
            throw new CatalogException("Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400);
        }
        String queryString = decode(getQueryString(ui));
        Collection<String> createResults = createResources(entityTagResourceProvider, new CollectionRequest(properties, queryString));
        Collection<Results> result = new ArrayList<>();
        for (String relativeUrl : createResults) {
            result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201));
        }
        return Response.status(Response.Status.CREATED).entity(new GenericEntity<Collection<Results>>(result) {
        }).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) GenericEntity(javax.ws.rs.core.GenericEntity) CatalogException(org.apache.atlas.catalog.exception.CatalogException) ArrayList(java.util.ArrayList) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with CollectionRequest

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

the class QueryFactoryTest method testCollectionQuery_WildcardQuery.

@Test
public void testCollectionQuery_WildcardQuery() throws Exception {
    String queryString = "name:ta?onomy";
    Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString);
    QueryFactory factory = new QueryFactory();
    AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request);
    QueryExpression queryExpression = query.getQueryExpression();
    assertEquals(queryExpression.getClass(), WildcardQueryExpression.class);
    assertEquals(queryExpression.getField(), "name");
    assertEquals(queryExpression.getExpectedValue(), "ta?onomy");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy");
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Example 4 with CollectionRequest

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

the class TaxonomyResourceDefinitionTest method testFilterProperties_Collection.

@Test
public void testFilterProperties_Collection() {
    Map<String, Object> resourceProps = new HashMap<>();
    resourceProps.put("id", "111-222-333");
    resourceProps.put("name", "nameVal");
    resourceProps.put("type", "someType");
    resourceProps.put("foo", "fooVal");
    resourceProps.put("bar", "barVal");
    resourceProps.put("description", "desc");
    resourceProps.put("creation_time", "2016:10:10");
    Request request = new CollectionRequest(resourceProps, "someProperty:someValue");
    request.addAdditionalSelectProperties(Collections.singleton("foo"));
    ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition();
    Map<String, Object> filteredProps = taxonomyDefinition.filterProperties(request, resourceProps);
    assertEquals(filteredProps.size(), 3);
    // registered collection props
    assertTrue(filteredProps.containsKey("name"));
    assertTrue(filteredProps.containsKey("description"));
    // added prop
    assertTrue(filteredProps.containsKey("foo"));
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Example 5 with CollectionRequest

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

the class EntityResourceDefinitionTest method testFilterProperties_Collection.

@Test
public void testFilterProperties_Collection() {
    Map<String, Object> resourceProps = new HashMap<>();
    resourceProps.put("id", "111-222-333");
    resourceProps.put("name", "nameVal");
    resourceProps.put("type", "someType");
    resourceProps.put("foo", "fooVal");
    resourceProps.put("bar", "barVal");
    resourceProps.put("fooBar", "fooBarVal");
    resourceProps.put("other", "otherVal");
    Request request = new CollectionRequest(resourceProps, "someProperty:someValue");
    request.addAdditionalSelectProperties(Collections.singleton("foo"));
    ResourceDefinition entityDefinition = new EntityResourceDefinition();
    // no filtering should occur for entity instances
    Map<String, Object> filteredProps = entityDefinition.filterProperties(request, resourceProps);
    assertEquals(filteredProps.size(), 4);
    // registered collection props
    assertTrue(filteredProps.containsKey("name"));
    assertTrue(filteredProps.containsKey("id"));
    assertTrue(filteredProps.containsKey("type"));
    // added prop
    assertTrue(filteredProps.containsKey("foo"));
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) HashMap(java.util.HashMap) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Aggregations

CollectionRequest (org.apache.atlas.catalog.CollectionRequest)13 InstanceRequest (org.apache.atlas.catalog.InstanceRequest)10 Request (org.apache.atlas.catalog.Request)10 Test (org.testng.annotations.Test)10 Produces (javax.ws.rs.Produces)3 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)3 GET (javax.ws.rs.GET)2 BaseRequest (org.apache.atlas.catalog.BaseRequest)2 Result (org.apache.atlas.catalog.Result)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 CatalogException (org.apache.atlas.catalog.exception.CatalogException)1