Search in sources :

Example 26 with AtlasQuery

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

the class EntityTagResourceProvider method createResources.

//todo: response for case mixed case where some subset of creations fail
@Override
public Collection<String> createResources(Request request) throws InvalidQueryException, ResourceNotFoundException, ResourceAlreadyExistsException {
    Collection<String> relativeUrls = new ArrayList<>();
    AtlasQuery atlasQuery = queryFactory.createEntityQuery(request);
    Collection<String> guids = new ArrayList<>();
    for (Map<String, Object> entityMap : atlasQuery.execute()) {
        guids.add(String.valueOf(entityMap.get("id")));
    }
    Collection<Map<String, String>> tagMaps = request.getProperty("tags");
    for (Map<String, String> tagMap : tagMaps) {
        Result termResult = getTermQueryResult(tagMap.get("name"));
        relativeUrls.addAll(tagEntities(guids, termResult.getPropertyMaps().iterator().next()));
    }
    return relativeUrls;
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery)

Example 27 with AtlasQuery

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

the class EntityResourceProvider method getResourceById.

@Override
public Result getResourceById(Request request) throws ResourceNotFoundException {
    AtlasQuery atlasQuery;
    try {
        atlasQuery = queryFactory.createEntityQuery(request);
    } catch (InvalidQueryException e) {
        throw new CatalogRuntimeException("Unable to compile internal Entity query: " + e, e);
    }
    Collection<Map<String, Object>> results = atlasQuery.execute();
    if (results.isEmpty()) {
        throw new ResourceNotFoundException(String.format("Entity '%s' not found.", request.getProperty(resourceDefinition.getIdPropertyName())));
    }
    return new Result(results);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery)

Example 28 with AtlasQuery

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

the class EntityResourceProviderTest method testGetResources_noResults.

@Test
public void testGetResources_noResults() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    // empty result shouldn't result in exception for collection query
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createEntityQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:entity*");
    Result result = provider.getResources(userRequest);
    assertEquals(0, result.getPropertyMaps().size());
    Request request = requestCapture.getValue();
    assertEquals("name:entity*", request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    assertEquals(0, request.getQueryProperties().size());
    verify(typeSystem, queryFactory, query);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 29 with AtlasQuery

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

the class EntityResourceProviderTest method testGetResources.

@Test
public void testGetResources() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow1 = new HashMap<>();
    queryResult.add(queryResultRow1);
    queryResultRow1.put("mame", "entity1");
    queryResultRow1.put("description", "test entity description");
    queryResultRow1.put("creation_time", "04/20/2016");
    Map<String, Object> queryResultRow2 = new HashMap<>();
    queryResult.add(queryResultRow2);
    queryResultRow2.put("mame", "entity2");
    queryResultRow2.put("description", "test entity description 2");
    queryResultRow2.put("creation_time", "04/21/2016");
    // mock expectations
    expect(queryFactory.createEntityQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:entity*");
    Result result = provider.getResources(userRequest);
    assertEquals(2, result.getPropertyMaps().size());
    assertTrue(result.getPropertyMaps().contains(queryResultRow1));
    assertTrue(result.getPropertyMaps().contains(queryResultRow2));
    Request request = requestCapture.getValue();
    assertEquals("name:entity*", request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    assertEquals(0, request.getQueryProperties().size());
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 30 with AtlasQuery

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

the class TermResourceProvider method getResources.

public Result getResources(Request request) throws InvalidQueryException, ResourceNotFoundException {
    TermPath termPath = request.getProperty("termPath");
    String queryString = doQueryStringConversions(termPath, request.getQueryString());
    Request queryRequest = new CollectionRequest(request.getQueryProperties(), queryString);
    AtlasQuery atlasQuery = queryFactory.createTermQuery(queryRequest);
    Collection<Map<String, Object>> result = atlasQuery.execute();
    return new Result(result);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery)

Aggregations

AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)47 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)38 Test (org.testng.annotations.Test)38 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)5 TaxonomyResourceDefinition (org.apache.atlas.catalog.definition.TaxonomyResourceDefinition)3 ResourceAlreadyExistsException (org.apache.atlas.catalog.exception.ResourceAlreadyExistsException)2 ResourceNotFoundException (org.apache.atlas.catalog.exception.ResourceNotFoundException)1