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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations