Java Code Examples for org.apache.atlas.AtlasErrorCode#INVALID_QUERY_LENGTH

The following examples show how to use org.apache.atlas.AtlasErrorCode#INVALID_QUERY_LENGTH . 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: DiscoveryREST.java    From 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")
public AtlasSearchResult searchUsingFullText(@QueryParam("query")                  String  query,
                                             @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
                                             @QueryParam("limit")                  int     limit,
                                             @QueryParam("offset")                 int     offset) throws AtlasBaseException {
    // Validate FullText query for max allowed length
    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.searchUsingFullText(" + query + "," +
                    limit + "," + offset + ")");
        }

        return discoveryService.searchUsingFullTextQuery(query, excludeDeletedEntities, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 2
Source File: DiscoveryREST.java    From 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")
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 {
    Servlets.validateQueryParamLength("typeName", typeName);
    Servlets.validateQueryParamLength("classification", classification);

    if (StringUtils.isNotEmpty(query) && query.length() > maxDslQueryLength) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_QUERY_LENGTH, Constants.MAX_DSL_QUERY_STR_LENGTH);
    }

    AtlasPerfTracer perf = null;

    try {

        query = Servlets.decodeQueryString(query);

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

        String queryStr = discoveryService.getDslQueryUsingTypeNameClassification(query, typeName, classification);

        return discoveryService.searchUsingDslQuery(queryStr, limit, offset);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 3
Source File: DiscoveryREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Attribute based search for entities satisfying the 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("/quick")
@GET
public AtlasQuickSearchResult quickSearch(@QueryParam("query")                  String  query,
                                          @QueryParam("typeName")               String  typeName,
                                          @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
                                          @QueryParam("offset")                 int     offset,
                                          @QueryParam("limit")                  int     limit) throws AtlasBaseException {



    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.quick(" + query + "," +
                    "excludeDeletedEntities:" + excludeDeletedEntities + "," + limit + "," + offset + ")");
        }

        QuickSearchParameters quickSearchParameters = new QuickSearchParameters(query,
                                                                                typeName,
                                                                                null,  // entityFilters
                                                                                false, // includeSubTypes
                                                                                excludeDeletedEntities,
                                                                                offset,
                                                                                limit,
                                                                                null); // attributes

        return discoveryService.quickSearch(quickSearchParameters);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
 
Example 4
Source File: DiscoveryREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void validateSearchParameters(SearchParameters parameters) throws AtlasBaseException {
    if (parameters != null) {
        Servlets.validateQueryParamLength("typeName", parameters.getTypeName());
        Servlets.validateQueryParamLength("classification", parameters.getClassification());
        Servlets.validateQueryParamLength("sortBy", parameters.getSortBy());
        if (StringUtils.isNotEmpty(parameters.getQuery()) && parameters.getQuery().length() > maxFullTextQueryLength) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_QUERY_LENGTH, Constants.MAX_FULLTEXT_QUERY_STR_LENGTH);
        }

    }
}
 
Example 5
Source File: DiscoveryREST.java    From atlas with Apache License 2.0 4 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")
public AtlasSearchResult searchUsingBasic(@QueryParam("query")                  String  query,
                                          @QueryParam("typeName")               String  typeName,
                                          @QueryParam("classification")         String  classification,
                                          @QueryParam("sortBy")                 String    sortByAttribute,
                                          @QueryParam("sortOrder")              SortOrder sortOrder,
                                          @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
                                          @QueryParam("limit")                  int     limit,
                                          @QueryParam("offset")                 int     offset) throws AtlasBaseException {
    Servlets.validateQueryParamLength("typeName", typeName);
    Servlets.validateQueryParamLength("classification", classification);
    Servlets.validateQueryParamLength("sortBy", sortByAttribute);
    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);
        searchParameters.setSortBy(sortByAttribute);
        searchParameters.setSortOrder(sortOrder);

        return discoveryService.searchWithParameters(searchParameters);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}