Search in sources :

Example 6 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class ContentQueryTable method initialize.

@Override
public GenericQueryConfiguration initialize(final Connector connection, final Query settings, final Set<Authorizations> auths) throws Exception {
    // Initialize the config and scanner factory
    final ContentQueryConfiguration config = new ContentQueryConfiguration(this, settings);
    this.scannerFactory = new ScannerFactory(connection);
    config.setConnector(connection);
    config.setAuthorizations(auths);
    // Re-assign the view name if specified via params
    Parameter p = settings.findParameter(QueryParameters.CONTENT_VIEW_NAME);
    if (null != p && !StringUtils.isEmpty(p.getParameterValue())) {
        this.viewName = p.getParameterValue();
    }
    // Decide whether or not to include the content of child events
    String end;
    p = settings.findParameter(QueryParameters.CONTENT_VIEW_ALL);
    if ((null != p) && (null != p.getParameterValue()) && StringUtils.isNotBlank(p.getParameterValue())) {
        end = ALL;
    } else {
        end = PARENT_ONLY;
    }
    // Configure ranges
    final Collection<Range> ranges = this.createRanges(settings, end);
    config.setRanges(ranges);
    return config;
}
Also used : ContentQueryConfiguration(datawave.query.config.ContentQueryConfiguration) Parameter(datawave.webservice.query.QueryImpl.Parameter) ScannerFactory(datawave.query.tables.ScannerFactory) Range(org.apache.accumulo.core.data.Range)

Example 7 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class EventQueryTransformerSupport method setEventQueryDataDecoratorTransformer.

public void setEventQueryDataDecoratorTransformer(EventQueryDataDecoratorTransformer eventQueryDataDecoratorTransformer) {
    this.eventQueryDataDecoratorTransformer = eventQueryDataDecoratorTransformer;
    Set<Parameter> parameters = this.settings.getParameters();
    if (eventQueryDataDecoratorTransformer != null && parameters != null) {
        List<String> requestedDecorators = new ArrayList<>();
        for (Parameter p : parameters) {
            if (p.getParameterName().equals("data.decorators")) {
                String decoratorString = p.getParameterValue();
                if (decoratorString != null) {
                    requestedDecorators.addAll(Arrays.asList(decoratorString.split(",")));
                    this.eventQueryDataDecoratorTransformer.setRequestedDecorators(requestedDecorators);
                }
            }
        }
        // Otherwise, NPE will ensue...
        if (!requestedDecorators.isEmpty() && this.eventQueryDataDecoratorTransformer.getDataDecorators() != null) {
            for (String requestedDecorator : requestedDecorators) {
                if (this.eventQueryDataDecoratorTransformer.getDataDecorators().containsKey(requestedDecorator)) {
                    EventQueryDataDecorator edd = this.eventQueryDataDecoratorTransformer.getDataDecorators().get(requestedDecorator);
                    if (edd.getResponseObjectFactory() == null) {
                        edd.setResponseObjectFactory(this.responseObjectFactory);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Parameter(datawave.webservice.query.QueryImpl.Parameter)

Example 8 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class TermFrequencyQueryTable method initialize.

@Override
public GenericQueryConfiguration initialize(Connector connection, Query settings, Set<Authorizations> auths) throws Exception {
    TermFrequencyQueryConfiguration config = new TermFrequencyQueryConfiguration(this, settings);
    config.setConnector(connection);
    config.setAuthorizations(auths);
    int pos = settings.getQuery().indexOf(':');
    String term = null;
    if (pos > 0) {
        term = settings.getQuery().substring(pos + 1);
    } else {
        term = settings.getQuery();
    }
    // TODO: Handle other parameters here
    String[] parts = StringUtils.split(term, '/');
    if (parts.length != 3) {
        throw new IllegalArgumentException("Query does not specify all necessary parts: " + settings.getQuery() + ". Should be of the form 'DOCUMENT:shardId/datatype/uid'.");
    } else {
        String shardId = parts[0];
        String datatype = parts[1];
        String uid = parts[2];
        log.debug("Received identifier: " + shardId + "," + datatype + "," + uid);
        String END = PARENT_ONLY;
        Parameter p = settings.findParameter(QueryParameters.CONTENT_VIEW_ALL);
        if (p != null && Boolean.parseBoolean(p.getParameterValue())) {
            END = ALL;
        }
        final String tf = ExtendedDataTypeHandler.TERM_FREQUENCY_COLUMN_FAMILY.toString();
        Key startKey = new Key(shardId, tf, datatype + NULL + uid + NULL);
        Key endKey = new Key(shardId, tf, datatype + NULL + uid + END);
        Range r = new Range(startKey, true, endKey, false);
        config.setRange(r);
        log.debug("Setting range: " + r);
    }
    return config;
}
Also used : TermFrequencyQueryConfiguration(datawave.query.config.TermFrequencyQueryConfiguration) Parameter(datawave.webservice.query.QueryImpl.Parameter) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 9 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class TestQueryImpl method testFindParameter.

@Test
public void testFindParameter() {
    Set<Parameter> parameters = new HashSet<Parameter>();
    parameters.add(new Parameter(QUERY_SYNTAX, "LUCENE"));
    parameters.add(new Parameter(NON_EVENT_KEY_PREFIXES, "value2"));
    parameters.add(new Parameter(BLACKLISTED_FIELDS, "value3"));
    parameters.add(new Parameter(RETURN_FIELDS, "value4"));
    parameters.add(new Parameter(INCLUDE_DATATYPE_AS_FIELD, "value5"));
    q.setParameters(parameters);
    q.addParameter(QUERY_SYNTAX, "JEXL");
    Assert.assertEquals("JEXL", q.findParameter(QUERY_SYNTAX).getParameterValue());
}
Also used : Parameter(datawave.webservice.query.QueryImpl.Parameter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Parameter

use of datawave.webservice.query.QueryImpl.Parameter in project datawave by NationalSecurityAgency.

the class QueryExecutorBean method duplicateQuery.

/**
 * Duplicates a query and allows modification of optional properties
 *
 * @param id
 *            - the ID of the query to copy (required)
 * @param newQueryName
 *            - name of the new query (@Required)
 * @param newQueryLogicName
 *            - defaults to old logic, name of class that this query should be run with (optional)
 * @param newQuery
 *            - defaults to old query, string used in lookup (optional, auditing required if changed)
 * @param newColumnVisibility
 *            - defaults to old column visibility, for query AND justification (optional, auditing required if changed)
 * @param newBeginDate
 *            - defaults to old begin date, begin range for the query (optional, auditing required if changed)
 * @param newEndDate
 *            - defaults to old end date, end range for the query (optional, auditing required if changed)
 * @param newQueryAuthorizations
 *            - defaults to old authorizations, use in the query (optional, auditing required if changed)
 * @param newExpirationDate
 *            - defaults to old expiration, meaningless if transient (optional)
 * @param newPagesize
 *            - defaults to old pagesize, number of results to return on each call to next() (optional)
 * @param newPageTimeout
 *            - specify timeout (in minutes) for each call to next(), defaults to -1 indicating disabled (optional)
 * @param newMaxResultsOverride
 *            - specify max results (optional)
 * @param newPersistenceMode
 *            - defaults to PERSISTENT, indicates whether or not the query is persistent (optional)
 * @param newParameters
 *            - defaults to old, optional parameters to the query, a semi-colon separated list name=value pairs (optional, auditing required if changed)
 * @param trace
 *            - optional (defaults to {@code false}) indication of whether or not the query should be traced using the distributed tracing mechanism
 * @see datawave.webservice.query.runner.QueryExecutorBean#duplicateQuery(String, String, String, String, String, Date, Date, String, Date, Integer,
 *      Integer, Long, QueryPersistence, String, boolean)
 *
 * @return {@code datawave.webservice.result.GenericResponse<String>}
 * @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 400 if invalid params or missing queryName param
 * @HTTP 404 if query not found
 * @HTTP 500 internal server error
 */
@POST
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/{id}/duplicate")
@GZIP
@Interceptors({ ResponseInterceptor.class, RequiredInterceptor.class })
@Override
@Timed(name = "dw.query.duplicateQuery", absolute = true)
public GenericResponse<String> duplicateQuery(@PathParam("id") String id, @Required("queryName") @FormParam("queryName") String newQueryName, @FormParam("logicName") String newQueryLogicName, @FormParam("query") String newQuery, @FormParam("columnVisibility") String newColumnVisibility, @FormParam("begin") @DateFormat(defaultTime = "000000", defaultMillisec = "000") Date newBeginDate, @FormParam("end") @DateFormat(defaultTime = "235959", defaultMillisec = "999") Date newEndDate, @FormParam("auths") String newQueryAuthorizations, @FormParam("expiration") @DateFormat(defaultTime = "235959", defaultMillisec = "999") Date newExpirationDate, @FormParam("pagesize") Integer newPagesize, @FormParam("pageTimeout") Integer newPageTimeout, @FormParam("maxResultsOverride") Long newMaxResultsOverride, @FormParam("persistence") QueryPersistence newPersistenceMode, @FormParam("params") String newParameters, @FormParam("trace") @DefaultValue("false") boolean trace) {
    GenericResponse<String> response = new GenericResponse<>();
    try {
        if (null == newQueryName || newQueryName.length() < 1) {
            throw new BadRequestQueryException(DatawaveErrorCode.QUERY_NAME_REQUIRED);
        }
        RunningQuery templateQuery = getQueryById(id);
        Query q = templateQuery.getSettings().duplicate(newQueryName);
        // default value
        QueryPersistence persistence = QueryPersistence.PERSISTENT;
        // TODO: figure out a way to set this to the same as the existing query
        if (null != newPersistenceMode) {
            persistence = newPersistenceMode;
        }
        // maybe set variables instead of stuffing in query
        if (newQueryLogicName != null) {
            q.setQueryLogicName(queryLogicFactory.getQueryLogic(newQueryLogicName, ctx.getCallerPrincipal()).getLogicName());
        }
        if (newQuery != null) {
            q.setQuery(newQuery);
        }
        if (newBeginDate != null) {
            q.setBeginDate(newBeginDate);
        }
        if (newEndDate != null) {
            q.setEndDate(newEndDate);
        }
        if (newQueryAuthorizations != null) {
            q.setQueryAuthorizations(newQueryAuthorizations);
        }
        if (newExpirationDate != null) {
            q.setExpirationDate(newExpirationDate);
        }
        if (newPagesize != null) {
            q.setPagesize(newPagesize);
        }
        if (newMaxResultsOverride != null) {
            q.setMaxResultsOverride(newMaxResultsOverride);
        }
        if (newPageTimeout != null) {
            q.setPageTimeout(newPageTimeout);
        }
        Set<Parameter> params = new HashSet<>();
        if (newParameters != null) {
            String[] param = newParameters.split(QueryImpl.PARAMETER_SEPARATOR);
            for (String yyy : param) {
                String[] parts = yyy.split(QueryImpl.PARAMETER_NAME_VALUE_SEPARATOR);
                if (parts.length == 2) {
                    params.add(new Parameter(parts[0], parts[1]));
                }
            }
        }
        MultivaluedMap<String, String> newSettings = new MultivaluedMapImpl<>();
        newSettings.putAll(q.toMap());
        newSettings.putSingle(QueryParameters.QUERY_PERSISTENCE, persistence.name());
        return createQuery(q.getQueryLogicName(), newSettings);
    } catch (DatawaveWebApplicationException e) {
        throw e;
    } catch (Exception e) {
        QueryException qe = new QueryException(DatawaveErrorCode.QUERY_DUPLICATION_ERROR, e);
        log.error(qe, e);
        response.addException(qe.getBottomQueryException());
        if (e.getClass() == IllegalArgumentException.class) {
            throw new BadRequestException(qe, response);
        }
        int statusCode = qe.getBottomQueryException().getStatusCode();
        throw new DatawaveWebApplicationException(qe, response, statusCode);
    }
}
Also used : Query(datawave.webservice.query.Query) GenericResponse(datawave.webservice.result.GenericResponse) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) 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) 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) QueryPersistence(datawave.webservice.query.QueryPersistence) Parameter(datawave.webservice.query.QueryImpl.Parameter) DatawaveWebApplicationException(datawave.webservice.common.exception.DatawaveWebApplicationException) BadRequestException(datawave.webservice.common.exception.BadRequestException) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

Parameter (datawave.webservice.query.QueryImpl.Parameter)17 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)3 BadRequestException (datawave.webservice.common.exception.BadRequestException)3 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)3 NoResultsException (datawave.webservice.common.exception.NoResultsException)3 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)3 Query (datawave.webservice.query.Query)3 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)3 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)3 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)3 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)3 QueryException (datawave.webservice.query.exception.QueryException)3 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)3 IOException (java.io.IOException)3 CancellationException (java.util.concurrent.CancellationException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 HeuristicMixedException (javax.transaction.HeuristicMixedException)3 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)3