Search in sources :

Example 6 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class DiscoveryREST method searchUsingBasic.

/**
 * 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 {
    Servlets.validateQueryParamLength("typeName", typeName);
    Servlets.validateQueryParamLength("classification", classification);
    if (StringUtils.isNotEmpty(query) && query.length() > maxFullTextQueryLength) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_QUERY_LENGTH, Constants.MAX_FULLTEXT_QUERY_STR_LENGTH);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingBasic(" + query + "," + typeName + "," + classification + "," + limit + "," + offset + ")");
        }
        SearchParameters searchParameters = new SearchParameters();
        searchParameters.setTypeName(typeName);
        searchParameters.setClassification(classification);
        searchParameters.setQuery(query);
        searchParameters.setExcludeDeletedEntities(excludeDeletedEntities);
        searchParameters.setLimit(limit);
        searchParameters.setOffset(offset);
        return atlasDiscoveryService.searchWithParameters(searchParameters);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method verifyQueryConversionFromJSON.

@Test(dependsOnMethods = { "createsNewProfile", "savesMultipleQueriesForUser" })
public void verifyQueryConversionFromJSON() throws AtlasBaseException {
    List<AtlasUserSavedSearch> list = userProfileService.getSavedSearches("first-0");
    for (int i = 0; i < max_searches; i++) {
        SearchParameters sp = list.get(i).getSearchParameters();
        String json = AtlasType.toJson(sp);
        assertEquals(AtlasType.toJson(getActualSearchParameters()).replace("\n", "").replace(" ", ""), json);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 8 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method createUserWithSavedQueries.

private void createUserWithSavedQueries(String userName) throws AtlasBaseException {
    SearchParameters actualSearchParameter = getActualSearchParameters();
    saveQueries(userName, actualSearchParameter);
    for (int i = 0; i < max_searches; i++) {
        AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, getIndexBasedQueryName(i));
        assertEquals(savedSearch.getName(), getIndexBasedQueryName(i));
        assertEquals(savedSearch.getSearchParameters(), actualSearchParameter);
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch)

Example 9 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method updateSearch.

@Test(dependsOnMethods = { "createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryConversionFromJSON" })
public void updateSearch() throws AtlasBaseException {
    final String queryName = getIndexBasedQueryName(0);
    String userName = getIndexBasedUserName(0);
    AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
    assertNotNull(expected);
    SearchParameters sp = expected.getSearchParameters();
    sp.setClassification("new-classification");
    AtlasUserSavedSearch actual = userProfileService.updateSavedSearch(expected);
    assertNotNull(actual);
    assertNotNull(actual.getSearchParameters());
    assertEquals(actual.getSearchParameters().getClassification(), expected.getSearchParameters().getClassification());
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Aggregations

SearchParameters (org.apache.atlas.model.discovery.SearchParameters)9 AtlasUserSavedSearch (org.apache.atlas.model.profile.AtlasUserSavedSearch)6 Test (org.testng.annotations.Test)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AtlasClientV2 (org.apache.atlas.AtlasClientV2)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 SearchFilter (org.apache.atlas.model.SearchFilter)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)1