org.apache.atlas.model.discovery.AtlasSearchResult Java Examples

The following examples show how to use org.apache.atlas.model.discovery.AtlasSearchResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchByMultiSystemAttributes() throws Exception {

    searchParameters = new SearchParameters();
    searchParameters.setTypeName("_ALL_ENTITY_TYPES");
    SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria();
    SearchParameters.FilterCriteria subFc1 = new SearchParameters.FilterCriteria();
    SearchParameters.FilterCriteria subFc2 = new SearchParameters.FilterCriteria();

    subFc1.setAttributeName(MODIFICATION_TIMESTAMP_PROPERTY_KEY);
    subFc1.setOperator(SearchParameters.Operator.LT);
    subFc1.setAttributeValue(String.valueOf(System.currentTimeMillis()));

    subFc2.setAttributeName(TIMESTAMP_PROPERTY_KEY);
    subFc2.setOperator(SearchParameters.Operator.LT);
    subFc2.setAttributeValue(String.valueOf(System.currentTimeMillis()));

    fc.setCriterion(Arrays.asList(subFc1, subFc2));
    fc.setCondition(AND);
    searchParameters.setEntityFilters(fc);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertTrue(res.getEntities().size() > 5);
}
 
Example #2
Source File: DiscoveryREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve data for the specified fulltext query
 * @param query Fulltext query
 * @param limit limit the result set to only include the specified number of entries
 * @param offset start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid fulltext or query parameters
 */
@GET
@Path("/fulltext")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingFullText(@QueryParam("query")  String query,
                                             @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
                                             @QueryParam("limit")  int    limit,
                                             @QueryParam("offset") int    offset) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingFullText(" + query + "," +
                                                           limit + "," + offset + ")");
        }

        return atlasDiscoveryService.searchUsingFullTextQuery(query, excludeDeletedEntities, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #3
Source File: AtlasAuditService.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<AtlasAuditEntry> toAtlasAuditEntries(AtlasSearchResult result) {
    List<AtlasAuditEntry> ret = new ArrayList<>();

    if(CollectionUtils.isNotEmpty(result.getEntities())) {
        for (AtlasEntityHeader entityHeader : result.getEntities()) {
            AtlasAuditEntry entry = AtlasAuditEntryDTO.from(entityHeader.getGuid(),
                    entityHeader.getAttributes());
            if (entry == null) {
                continue;
            }

            ret.add(entry);
        }
    }

    return ret;
}
 
Example #4
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchUsingDSL() throws Exception {
    String query = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
    AtlasSearchResult searchResult = atlasClientV2.dslSearch(query);
    assertNotNull(searchResult);

    assertEquals(searchResult.getQueryText(), query);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
    List<AtlasEntityHeader> entities = searchResult.getEntities();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);

    AtlasEntityHeader dbEntity = entities.get(0);
    assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
    assertEquals(dbEntity.getDisplayText(), dbName);
    assertEquals(dbEntity.getStatus(), Status.ACTIVE);

    assertNotNull(dbEntity.getGuid());
    assertNull(searchResult.getAttributes());
    assertNull(searchResult.getFullTextResult());
}
 
Example #5
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = "testSearchByMultiTags")
public void testSearchByTerms() throws Exception {

    // database - phi, felt_classification
    // table1 - phi, classification, term: term1 | table2 - classification, term:term2
    // column - phi
    assignTermTo(term1, tableEntity);
    assignTermTo(term1, tableEntity2);

    searchParameters = new SearchParameters();
    searchParameters.setTermName(term1.getName() + "@testSearchGlossary");
    searchParameters.setClassification(CLASSIFICATION);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    searchParameters.setClassification(PII);
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNull(res.getEntities());

    searchParameters.setClassification(PHI);
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 1);
}
 
Example #6
Source File: DiscoveryREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve data for the specified fulltext query
 * @param query Fulltext query
 * @param typeName limit the result to only entities of specified type or its sub-types
 * @param classification limit the result to only entities tagged with the given classification or or its sub-types
 * @param limit limit the result set to only include the specified number of entries
 * @param offset start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid fulltext or query parameters
 */
@GET
@Path("/basic")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingBasic(@QueryParam("query")                  String  query,
                                          @QueryParam("typeName")               String  typeName,
                                          @QueryParam("classification")         String  classification,
                                          @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
                                          @QueryParam("limit")                  int     limit,
                                          @QueryParam("offset")                 int     offset) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingBasic(" + query + "," +
                                                typeName + "," + classification + "," + limit + "," + offset + ")");
        }

        return atlasDiscoveryService.searchUsingBasicQuery(query, typeName, classification, null, null,
                                                           excludeDeletedEntities, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #7
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchByDSL() throws Exception {
    String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";

    AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), dslQuery);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);

    List<AtlasEntityHeader> entities = searchResult.getEntities();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);

    AtlasEntityHeader dbEntity = entities.get(0);
    assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
    assertEquals(dbEntity.getDisplayText(), dbName);
    assertEquals(dbEntity.getStatus(), Status.ACTIVE);
    assertNotNull(dbEntity.getGuid());
    assertNull(searchResult.getAttributes());
    assertNull(searchResult.getFullTextResult());
}
 
Example #8
Source File: QuickStartV2.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");

    for (String dslQuery : getDSLQueries()) {
        AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);

        if (results != null) {
            List<AtlasEntityHeader>   entitiesResult  = results.getEntities();
            List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
            AttributeSearchResult     attribResult    = results.getAttributes();

            if (CollectionUtils.isNotEmpty(entitiesResult)) {
                System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
            } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
            } else if (attribResult != null) {
                System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
            }
        } else {
            System.out.println("query [" + dslQuery + "] failed, results:" + results);
        }
    }
}
 
Example #9
Source File: ExportImportAuditService.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<ExportImportAuditEntry> toExportImportAuditEntry(AtlasSearchResult result) {
    List<ExportImportAuditEntry> ret = new ArrayList<>();
    if(CollectionUtils.isEmpty(result.getEntities())) {
        return ret;
    }

    for (AtlasEntityHeader entityHeader : result.getEntities()) {
        ExportImportAuditEntry entry = ExportImportAuditEntryDTO.from(entityHeader.getGuid(),
                                                                        entityHeader.getAttributes());
        if(entry == null) {
            continue;
        }

        ret.add(entry);
    }

    return ret;
}
 
Example #10
Source File: QuickStartV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");

    for (String dslQuery : getDSLQueries()) {
        try {
            AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);

            if (results != null) {
                List<AtlasEntityHeader> entitiesResult = results.getEntities();
                List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
                AttributeSearchResult attribResult = results.getAttributes();

                if (CollectionUtils.isNotEmpty(entitiesResult)) {
                    System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
                } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                    System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
                } else if (attribResult != null) {
                    System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
                } else {
                    System.out.println("query [" + dslQuery + "] returned [ 0 ] rows.");
                }
            } else {
                System.out.println("query [" + dslQuery + "] failed, results:" + results);
            }
        } catch (Exception e) {
            System.out.println("query [" + dslQuery + "] execution failed!");
        }
    }
}
 
Example #11
Source File: AtlasClientV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(QUERY, query);
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(API_V2.DSL_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #12
Source File: AtlasClientV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(QUERY, query);
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(API_V2.FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #13
Source File: AtlasClientV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
                                     final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("typeName", typeName);
    queryParams.add("classification", classification);
    queryParams.add(QUERY, query);
    queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(API_V2.BASIC_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #14
Source File: DiscoveryREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve data for the specified DSL
 * @param query DSL query
 * @param typeName limit the result to only entities of specified type or its sub-types
 * @param classification limit the result to only entities tagged with the given classification or or its sub-types
 * @param limit limit the result set to only include the specified number of entries
 * @param offset start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful DSL execution with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid DSL or query parameters
 */
@GET
@Path("/dsl")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingDSL(@QueryParam("query")          String query,
                                        @QueryParam("typeName")       String typeName,
                                        @QueryParam("classification") String classification,
                                        @QueryParam("limit")          int    limit,
                                        @QueryParam("offset")         int    offset) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingDSL(" + query + "," + typeName
                                                        +  "," + classification + "," + limit + "," + offset + ")");
        }

        String queryStr = query == null ? "" : query;

        if (StringUtils.isNoneEmpty(typeName)) {
            queryStr = escapeTypeName(typeName) + " " + queryStr;
        }

        if (StringUtils.isNoneEmpty(classification)) {
            // isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query
            if (StringUtils.isEmpty(query)) {
                queryStr += (" isa " + classification);
            }
        }

        return atlasDiscoveryService.searchUsingDslQuery(queryStr, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #15
Source File: DiscoveryREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve data for the specified attribute search query
 * @param attrName  Attribute name
 * @param attrValuePrefix Attibute value to search on
 * @param typeName limit the result to only entities of specified type or its sub-types
 * @param limit limit the result set to only include the specified number of entries
 * @param offset start offset of the result set (useful for pagination)
 * @return Search results
 * @throws AtlasBaseException
 * @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded
 * without any results
 * @HTTP 400 Invalid wildcard or query parameters
 */
@GET
@Path("/attribute")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchUsingAttribute(@QueryParam("attrName")        String attrName,
                                              @QueryParam("attrValuePrefix") String attrValuePrefix,
                                              @QueryParam("typeName")        String typeName,
                                              @QueryParam("limit")           int    limit,
                                              @QueryParam("offset")          int    offset) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingAttribute(" + attrName + "," +
                    attrValuePrefix + "," + typeName + "," + limit + "," + offset + ")");
        }

        if (StringUtils.isEmpty(attrName) && StringUtils.isEmpty(attrValuePrefix)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS,
                    String.format("attrName : {0}, attrValue: {1} for attribute search.", attrName, attrValuePrefix));
        }

        return atlasDiscoveryService.searchUsingBasicQuery(null, typeName, null, attrName, attrValuePrefix, true, limit, offset);

    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #16
Source File: DiscoveryREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Attribute based search for entities satisfying the search parameters
 * @param parameters Search parameters
 * @return Atlas search result
 * @throws AtlasBaseException
 *
 * @HTTP 200 On successful search
 * @HTTP 400 Tag/Entity doesn't exist or Tag/entity filter is present without tag/type name
 */
@Path("basic")
@POST
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasSearchResult searchWithParameters(SearchParameters parameters) throws AtlasBaseException {
    AtlasPerfTracer perf = null;

    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchWithParameters("+ parameters + ")");
        }

        if (parameters.getLimit() < 0 || parameters.getOffset() < 0) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Limit/offset should be non-negative");
        }

        if (StringUtils.isEmpty(parameters.getTypeName()) && !isEmpty(parameters.getEntityFilters())) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "EntityFilters specified without Type name");
        }

        if (StringUtils.isEmpty(parameters.getClassification()) && !isEmpty(parameters.getTagFilters())) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "TagFilters specified without tag name");
        }

        return atlasDiscoveryService.searchWithParameters(parameters);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example #17
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchDSLLimits() throws Exception {
    String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
    AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
    assertNotNull(searchResult);

    //higher limit, all results returned
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
    assertEquals(searchResult.getEntities().size(), 1);

    //default limit and offset -1, all results returned
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, -1, -1);
    assertEquals(searchResult.getEntities().size(), 1);

    //uses the limit parameter passed
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 1, 0);
    assertEquals(searchResult.getEntities().size(), 1);

    //uses the offset parameter passed
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 1);
    assertNull(searchResult.getEntities());

    //limit > 0
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 0, 10);
    assertNull(searchResult.getEntities());

    //limit > maxlimit
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10);
    assertNull(searchResult.getEntities());

    //offset >= 0
    searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, -2);
    assertEquals(searchResult.getEntities().size(), 1);
}
 
Example #18
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchFullTextOnDSLFailure() throws Exception {
    String query = "*";
    AtlasSearchResult searchResult = atlasClientV2.fullTextSearch(query);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), query);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
}
 
Example #19
Source File: EntityDiscoveryService.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public AtlasSearchResult searchUsingFullTextQuery(String fullTextQuery, boolean excludeDeletedEntities, int limit, int offset)
                                                  throws AtlasBaseException {
    AtlasSearchResult ret      = new AtlasSearchResult(fullTextQuery, AtlasQueryType.FULL_TEXT);
    QueryParams       params   = validateSearchParams(limit, offset);
    AtlasIndexQuery   idxQuery = toAtlasIndexQuery(fullTextQuery);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Executing Full text query: {}", fullTextQuery);
    }
    ret.setFullTextResult(getIndexQueryResults(idxQuery, params, excludeDeletedEntities));

    return ret;
}
 
Example #20
Source File: AtlasClientV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(QUERY, query);
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #21
Source File: AtlasClientV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add(QUERY, query);
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #22
Source File: AtlasClientV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
                                     final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("typeName", typeName);
    queryParams.add("classification", classification);
    queryParams.add(QUERY, query);
    queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
    queryParams.add(LIMIT, String.valueOf(limit));
    queryParams.add(OFFSET, String.valueOf(offset));

    return callAPI(BASIC_SEARCH, AtlasSearchResult.class, queryParams);
}
 
Example #23
Source File: AtlasAPIV2ServerEmulator.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    final AtlasSearchResult result = new AtlasSearchResult();
    result.setEntities(atlasEntitiesByTypedQname.values().stream()
            .map(entity -> new AtlasEntityHeader(entity.getTypeName(), entity.getAttributes())).collect(Collectors.toList()));
    respondWithJson(resp, result);
}
 
Example #24
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testSearchByMultiTags")
public void testSearchByOtherSystemAttributes() throws Exception {

    // database - phi, felt_classification
    // table1 - phi, classification, table2 - classification,
    // col1 - phi,  col2 - phi
    searchParameters = new SearchParameters();
    searchParameters.setTypeName("_ALL_ENTITY_TYPES");
    SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria();

    fc.setAttributeName(CLASSIFICATION_NAMES_KEY);
    fc.setOperator(SearchParameters.Operator.EQ);
    fc.setAttributeValue(CLASSIFICATION);

    searchParameters.setEntityFilters(fc);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    fc.setOperator(SearchParameters.Operator.CONTAINS);
    fc.setAttributeValue("cla");

    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 3);

    fc.setOperator(SearchParameters.Operator.CONTAINS);
    fc.setAttributeValue(PHI);

    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 4);
}
 
Example #25
Source File: BasicSearchIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "basicSearchJSONNames")
public void testDiscoveryWithSearchParameters(String jsonFile) {
    try {
        BasicSearchParametersWithExpectation[] testExpectations =
                TestResourceFileUtils.readObjectFromJson(jsonFile, BasicSearchParametersWithExpectation[].class);
        assertNotNull(testExpectations);

        for (BasicSearchParametersWithExpectation testExpectation : testExpectations) {
            LOG.info("TestDescription  :{}", testExpectation.testDescription);
            LOG.info("SearchParameters :{}", testExpectation.searchParameters);

            AtlasSearchResult searchResult = atlasClientV2.facetedSearch(testExpectation.searchParameters);
            if (testExpectation.expectedCount > 0) {
                assertNotNull(searchResult.getEntities());
                assertEquals(searchResult.getEntities().size(), testExpectation.expectedCount);
            }

            if (testExpectation.searchParameters.getSortBy() != null && !testExpectation.searchParameters.getSortBy().isEmpty()) {
                assertNotNull(searchResult.getEntities());
                assertEquals(searchResult.getEntities().get(0).getAttribute("name"),
                        "testtable_3");
            }
        }
    } catch (IOException | AtlasServiceException e) {
        fail(e.getMessage());
    }
}
 
Example #26
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSearch() throws Exception {
    // search entities with classification named classification
    searchParameters = new SearchParameters();
    searchParameters.setIncludeSubClassifications(true);
    searchParameters.setClassification(TestUtilsV2.CLASSIFICATION);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);
}
 
Example #27
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testWildCardBasicSearch() throws Exception {

    //table - classification
    searchParameters = new SearchParameters();

    searchParameters.setClassification("*");
    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    searchParameters.setClassification("_CLASSIFIED");
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    // Test wildcard usage of basic search
    searchParameters.setClassification("cl*");
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    searchParameters.setClassification("*ion");
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    searchParameters.setClassification("*l*");
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    searchParameters.setClassification("_NOT_CLASSIFIED");
    searchParameters.setTypeName(DATABASE_TYPE);
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 1);
}
 
Example #28
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testBasicSearchWithAttr")
public void testBasicSearchWithSubTypes() throws Exception{

    // table - classification
    // column - phi
    searchParameters = new SearchParameters();
    searchParameters.setClassification(TestUtilsV2.CLASSIFICATION);
    searchParameters.setIncludeSubClassifications(true);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);

    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    // table - classification
    // database - fetl_classification
    // column - phi
    addTagTo(FETL_CLASSIFICATION, DATABASE_TYPE);

    final AtlasClassification result_tag = entityREST.getClassification(createdGuids.get(DATABASE_TYPE).get(0), TestUtilsV2.FETL_CLASSIFICATION);
    Assert.assertNotNull(result_tag);
    Assert.assertEquals(result_tag.getTypeName(), FETL_CLASSIFICATION);

    // basic search with subtypes
    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 3);

    // basic search without subtypes
    searchParameters.setIncludeSubClassifications(false);
    res = discoveryREST.searchWithParameters(searchParameters);

    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);
}
 
Example #29
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testGraphQueryFilter")
public void testSearchByMultiTags() throws Exception {

    addTagTo(PHI, DATABASE_TYPE);

    // database - phi, felt_classification
    // table1 - phi, classification, table2 - classification,
    // column - phi
    searchParameters = new SearchParameters();
    searchParameters.setIncludeSubClassifications(false);
    searchParameters.setTypeName("_ALL_ENTITY_TYPES");
    SearchParameters.FilterCriteria fc = new SearchParameters.FilterCriteria();
    SearchParameters.FilterCriteria subFc1 = new SearchParameters.FilterCriteria();
    SearchParameters.FilterCriteria subFc2 = new SearchParameters.FilterCriteria();

    subFc1.setAttributeName(CLASSIFICATION_NAMES_KEY);
    subFc1.setOperator(SearchParameters.Operator.CONTAINS);
    subFc1.setAttributeValue(PHI);

    subFc2.setAttributeName(CLASSIFICATION_NAMES_KEY);
    subFc2.setOperator(SearchParameters.Operator.CONTAINS);
    subFc2.setAttributeValue(CLASSIFICATION);

    fc.setCriterion(Arrays.asList(subFc1, subFc2));
    fc.setCondition(AND);
    searchParameters.setEntityFilters(fc);

    AtlasSearchResult res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 2);

    subFc2.setAttributeValue(FETL_CLASSIFICATION);

    res = discoveryREST.searchWithParameters(searchParameters);
    Assert.assertNotNull(res.getEntities());
    Assert.assertEquals(res.getEntities().size(), 1);
}
 
Example #30
Source File: DSLQueriesTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertSearchResult(AtlasSearchResult searchResult, int expected, String query) {
    assertNotNull(searchResult);
    if(expected == 0) {
        assertTrue(searchResult.getAttributes() == null || CollectionUtils.isEmpty(searchResult.getAttributes().getValues()));
        assertNull(searchResult.getEntities(), query);
    } else if(searchResult.getEntities() != null) {
        assertEquals(searchResult.getEntities().size(), expected, query);
    } else {
        assertNotNull(searchResult.getAttributes());
        assertNotNull(searchResult.getAttributes().getValues());
        assertEquals(searchResult.getAttributes().getValues().size(), expected, query);
    }
}