Search in sources :

Example 16 with DatawaveWebApplicationException

use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method list.

/**
 * Lists queries for the current user with the given name.
 *
 * @param name
 *            the name of the query to locate (@Required)
 * @see datawave.webservice.query.runner.QueryExecutorBean#list(String) list(String) for the @Required definition
 *
 * @return datawave.webservice.result.QueryImplListResponse
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user, by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 *
 * @HTTP 200 success
 * @HTTP 404 if the query with {@code name} does not belong to caller, you will never see it
 * @HTTP 404 queries not found using {@code name}
 * @HTTP 400 if {@code name} parameter is not included
 * @HTTP 500 internal server error
 */
@GET
@Path("/list")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Override
@Timed(name = "dw.query.listQueryByName", absolute = true)
public QueryImplListResponse list(@Required("name") @QueryParam("name") String name) {
    QueryImplListResponse response = new QueryImplListResponse();
    List<Query> results = new ArrayList<>();
    try {
        List<RunningQuery> query = getQueryByName(name);
        if (null != query) {
            for (RunningQuery rq : query) results.add(rq.getSettings());
        }
        response.setQuery(results);
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.LIST_ERROR, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) CancellationException(java.util.concurrent.CancellationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) WebApplicationException(javax.ws.rs.WebApplicationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) JAXBException(javax.xml.bind.JAXBException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NoResultsException(datawave.webservice.common.exception.NoResultsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RollbackException(javax.transaction.RollbackException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 17 with DatawaveWebApplicationException

use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method get.

/**
 * Lists query info for the given id.
 *
 * @param id
 *            - the id of the query to locate (@Required)
 * @see datawave.webservice.query.runner.QueryExecutorBean#get(String) get(String) for the @Required definition
 *
 * @return datawave.webservice.result.QueryImplListResponse
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user, by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 *
 * @HTTP 200 success
 * @HTTP 404 queries not found using {@code id}
 * @HTTP 500 internal server error
 */
@GET
@Path("/{id}")
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@GZIP
@Interceptors({ RequiredInterceptor.class, ResponseInterceptor.class })
@Timed(name = "dw.query.listQueryByID", absolute = true)
public QueryImplListResponse get(@Required("id") @PathParam("id") String id) {
    QueryImplListResponse response = new QueryImplListResponse();
    List<Query> results = new ArrayList<>();
    try {
        RunningQuery query = getQueryById(id);
        if (null != query) {
            results.add(query.getSettings());
        }
        response.setQuery(results);
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.QUERY_GET_ERROR, e, MessageFormat.format("queryID: {0}", id));
        log.error(qe, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) CancellationException(java.util.concurrent.CancellationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) WebApplicationException(javax.ws.rs.WebApplicationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) JAXBException(javax.xml.bind.JAXBException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NoResultsException(datawave.webservice.common.exception.NoResultsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RollbackException(javax.transaction.RollbackException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 18 with DatawaveWebApplicationException

use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method remove.

/**
 * remove (delete) the query
 *
 * @param id
 *
 * @return datawave.webservice.result.VoidResponse
 * @RequestHeader X-ProxiedEntitiesChain use when proxying request for user, by specifying a chain of DNs of the identities to proxy
 * @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
 * @RequestHeader query-session-id session id value used for load balancing purposes. query-session-id can be placed in the request in a Cookie header or as
 *                a query parameter
 * @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
 *
 * @HTTP 200 success
 * @HTTP 404 queries not found using {@code id}
 * @HTTP 500 internal server error
 */
@DELETE
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/{id}/remove")
@GZIP
@Interceptors({ ResponseInterceptor.class, RequiredInterceptor.class })
@Override
@Timed(name = "dw.query.remove", absolute = true)
public VoidResponse remove(@Required("id") @PathParam("id") String id) {
    VoidResponse response = new VoidResponse();
    try {
        boolean connectionRequestCanceled = accumuloConnectionRequestBean.cancelConnectionRequest(id);
        try {
            RunningQuery query = getQueryById(id);
            close(query);
            persister.remove(query.getSettings());
        } catch (Exception e) {
            log.debug("Failed to remove " + id + ", checking if closed previously");
            // if this is a query that is in the closed query cache, then we have already successfully closed this query so ignore
            if (!closedQueryCache.exists(id)) {
                log.debug("Failed to remove " + id + ", checking if connection request was canceled");
                // if connection request was canceled, then the call was successful even if a RunningQuery was not found
                if (!connectionRequestCanceled) {
                    log.error("Failed to remove " + id, e);
                    throw e;
                }
            }
        }
        response.addMessage(id + " removed.");
        // no longer need to remember this query
        closedQueryCache.remove(id);
        return response;
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.QUERY_REMOVAL_ERROR, e, MessageFormat.format("query_id: {0}", id));
        log.error(qe, e);
        response.addException(qe.getBottomQueryException());
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) QueryException(datawave.webservice.query.exception.QueryException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) VoidResponse(datawave.webservice.result.VoidResponse) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) CancellationException(java.util.concurrent.CancellationException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) WebApplicationException(javax.ws.rs.WebApplicationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) NoResultsQueryException(datawave.webservice.query.exception.NoResultsQueryException) IOException(java.io.IOException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnauthorizedQueryException(datawave.webservice.query.exception.UnauthorizedQueryException) JAXBException(javax.xml.bind.JAXBException) UnauthorizedException(datawave.webservice.common.exception.UnauthorizedException) NoResultsException(datawave.webservice.common.exception.NoResultsException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RollbackException(javax.transaction.RollbackException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Interceptors(javax.interceptor.Interceptors) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 19 with DatawaveWebApplicationException

use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.

the class LookupUUIDUtil method lookupPagedContent.

private EventQueryResponseBase lookupPagedContent(final String queryName, final AbstractUUIDLookupCriteria validatedCriteria, final List<StringBuilder> batchedContentQueryStrings, final Date endDate, final Date expireDate, final String userAuths, boolean allEventMockResponse) {
    // Initialize the return value
    EventQueryResponseBase mergedContentQueryResponse = null;
    // Call the ContentQuery for one or more events
    DatawaveWebApplicationException noResultsException = null;
    for (final StringBuilder contentQuery : batchedContentQueryStrings) {
        // Submitted query should look like this:
        // 
        // DOCUMENT:shardId/datatype/uid [DOCUMENT:shardId/datatype/uid]*
        // 
        MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
        queryParameters.putAll(this.defaultOptionalParams);
        queryParameters.putSingle(QueryParameters.QUERY_NAME, queryName);
        queryParameters.putSingle(QueryParameters.QUERY_STRING, contentQuery.toString());
        try {
            queryParameters.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(this.beginAsDate));
        } catch (ParseException e1) {
            throw new RuntimeException("Error formatting begin date: " + this.beginAsDate);
        }
        try {
            queryParameters.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(endDate));
        } catch (ParseException e1) {
            throw new RuntimeException("Error formatting end date: " + endDate);
        }
        queryParameters.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, userAuths);
        try {
            queryParameters.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expireDate));
        } catch (ParseException e1) {
            throw new RuntimeException("Error formatting expr date: " + expireDate);
        }
        queryParameters.putSingle(QueryParameters.QUERY_PERSISTENCE, QueryPersistence.TRANSIENT.name());
        queryParameters.putSingle(QueryParameters.QUERY_TRACE, "false");
        for (String key : validatedCriteria.getQueryParameters().keySet()) {
            if (!queryParameters.containsKey(key)) {
                queryParameters.put(key, validatedCriteria.getQueryParameters().get(key));
            }
        }
        final GenericResponse<String> createResponse = this.queryExecutor.createQuery(CONTENT_QUERY, queryParameters);
        final String contentQueryId = createResponse.getResult();
        boolean preventCloseOfMergedQueryId = ((null == mergedContentQueryResponse) && allEventMockResponse);
        try {
            BaseQueryResponse contentQueryResponse = null;
            do {
                try {
                    // Get the first/next results
                    contentQueryResponse = this.queryExecutor.next(contentQueryId);
                    // Validate the response, which also checks for null
                    if (!(contentQueryResponse instanceof EventQueryResponseBase)) {
                        EventQueryResponseBase er = responseObjectFactory.getEventQueryResponse();
                        er.addMessage("Unhandled response type " + contentQueryResponse + " from ContentQuery");
                        throw new PreConditionFailedException(null, er);
                    }
                    // Prevent NPE due to attempted merge when total events is null
                    final EventQueryResponseBase eventQueryResponse = (EventQueryResponseBase) contentQueryResponse;
                    if (null == eventQueryResponse.getTotalEvents()) {
                        final Long returnedEvents = eventQueryResponse.getReturnedEvents();
                        eventQueryResponse.setTotalEvents((null != returnedEvents) ? returnedEvents : 0L);
                    }
                    // Assign the merged response if it hasn't been done yet
                    if (null == mergedContentQueryResponse) {
                        mergedContentQueryResponse = (EventQueryResponseBase) contentQueryResponse;
                    } else // If the merged content has already been assigned, merge into it, but keep the original
                    // query Id
                    {
                        final String queryId = mergedContentQueryResponse.getQueryId();
                        mergedContentQueryResponse.merge((EventQueryResponseBase) contentQueryResponse);
                        mergedContentQueryResponse.setQueryId(queryId);
                    }
                } catch (final NoResultsException e) {
                    contentQueryResponse = null;
                    noResultsException = e;
                }// in case.
                 catch (final EJBException e) {
                    final Throwable cause = e.getCause();
                    if (cause instanceof DatawaveWebApplicationException) {
                        DatawaveWebApplicationException nwae = (DatawaveWebApplicationException) cause;
                        if (nwae instanceof NoResultsException) {
                            contentQueryResponse = null;
                            noResultsException = nwae;
                        } else {
                            throw nwae;
                        }
                    }
                }
            } while (// Loop if more results are available
            null != contentQueryResponse);
        } finally {
            if (!preventCloseOfMergedQueryId) {
                this.queryExecutor.close(contentQueryId);
            }
        }
    }
    // Conditionally throw a NoResultsException
    if ((null == mergedContentQueryResponse) && (null != noResultsException)) {
        throw noResultsException;
    }
    return mergedContentQueryResponse;
}
Also used : NoResultsException(datawave.webservice.common.exception.NoResultsException) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase) PreConditionFailedException(datawave.webservice.common.exception.PreConditionFailedException) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) ParseException(java.text.ParseException) DateTimeParseException(java.time.format.DateTimeParseException) EJBException(javax.ejb.EJBException)

Example 20 with DatawaveWebApplicationException

use of datawave.webservice.common.exception.DatawaveWebApplicationException in project datawave by NationalSecurityAgency.

the class LookupUUIDUtil method validateUUIDTerm.

/*
     * Validate the specified token as a UUID lookup term, either as a LUCENE-formatted field/value or a UIDQuery field/value. Tokens missing the appropriate
     * delimiter are ignored and return with a null UUIDType.
     * 
     * @param uuidTypeValueTerm A token to evaluate as a possible UUID field/value term
     * 
     * @param logicName The existing assigned query logic name, if any
     * 
     * @return A valid UUIDType, or null if the specified token is obviously not a UUID field/value term
     */
private UUIDType validateUUIDTerm(final String possibleUUIDTerm, final String logicName) {
    // Declare the return value
    final UUIDType matchingUuidType;
    // Check for the expected type/value delimiter (i.e., UUIDType:UUID)
    if (possibleUUIDTerm.contains(UUID_TERM_DELIMITER)) {
        final String[] splitPair = possibleUUIDTerm.split(UUID_TERM_DELIMITER);
        final String uuidType = splitPair[0].trim().toUpperCase();
        final String uuid;
        if (splitPair.length > 1) {
            uuid = splitPair[1].trim();
        } else {
            uuid = null;
        }
        // Get the matching UUID type
        matchingUuidType = this.uuidTypes.get(uuidType.toUpperCase());
        // Validate UUID type
        if (null == matchingUuidType) {
            final String message = "Invalid type '" + uuidType + "' for UUID " + uuid + " not supported with the LuceneToJexlUUIDQueryParser";
            final GenericResponse<String> errorReponse = new GenericResponse<>();
            errorReponse.addMessage(message);
            throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse);
        } else // Validate the UUID value
        if ((null == uuid) || uuid.isEmpty()) {
            final String message = "Undefined UUID using type '" + uuidType + "' not supported with the LuceneToJexlUUIDQueryParser";
            final GenericResponse<String> errorReponse = new GenericResponse<>();
            errorReponse.addMessage(message);
            throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse);
        } else // Reject conflicting logic name
        if ((null != logicName) && !logicName.equals(matchingUuidType.getDefinedView())) {
            final String message = "Multiple UUID types '" + logicName + "' and '" + matchingUuidType.getDefinedView() + "' not " + " supported within the same lookup request";
            final GenericResponse<String> errorReponse = new GenericResponse<>();
            errorReponse.addMessage(message);
            throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse);
        }
    } else {
        matchingUuidType = null;
    }
    return matchingUuidType;
}
Also used : GenericResponse(datawave.webservice.result.GenericResponse) UUIDType(datawave.query.data.UUIDType) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException)

Aggregations

DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)72 QueryException (datawave.webservice.query.exception.QueryException)64 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)48 IOException (java.io.IOException)43 Produces (javax.ws.rs.Produces)43 NoResultsException (datawave.webservice.common.exception.NoResultsException)39 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)37 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)37 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)36 GZIP (org.jboss.resteasy.annotations.GZIP)34 Interceptors (javax.interceptor.Interceptors)33 BadRequestException (datawave.webservice.common.exception.BadRequestException)32 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)32 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)31 Path (javax.ws.rs.Path)27 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)26 Principal (java.security.Principal)26 WebApplicationException (javax.ws.rs.WebApplicationException)25 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)24 HeuristicMixedException (javax.transaction.HeuristicMixedException)24