Search in sources :

Example 1 with QueryTerm

use of org.opencastproject.workflow.api.WorkflowQuery.QueryTerm in project opencast by opencast.

the class WorkflowServiceSolrIndex method appendMap.

/**
 * Appends query parameters from a {@link java.util.Map} to a solr query. The map
 *
 * @param sb
 *          The {@link StringBuilder} containing the query
 * @param key
 *          the key for this search parameter
 * @return the appended {@link StringBuilder}
 */
protected StringBuilder appendMap(StringBuilder sb, String key, List<QueryTerm> queryTerms) {
    if (queryTerms == null || queryTerms.isEmpty()) {
        return sb;
    }
    if (sb.length() > 0) {
        sb.append(" AND ");
    }
    // If we include only negatives inside parentheses, lucene won't return any results. So we need to add "*:*".
    // See
    // http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201011.mbox/%3CAANLkTinTJLo7Y-W2kt+yxAcESf98p8DD7z7mrs4CpNo-@mail.gmail.com%3E
    boolean positiveTerm = false;
    sb.append("(");
    for (int i = 0; i < queryTerms.size(); i++) {
        QueryTerm term = queryTerms.get(i);
        if (i > 0) {
            if (term.isInclude()) {
                sb.append(" OR ");
            } else {
                sb.append(" AND ");
            }
        }
        if (term.isInclude()) {
            positiveTerm = true;
        } else {
            sb.append("-");
        }
        sb.append(key);
        sb.append(":");
        sb.append(escapeQueryChars(term.getValue().toLowerCase()));
    }
    if (!positiveTerm) {
        sb.append(" AND *:*");
    }
    sb.append(")");
    return sb;
}
Also used : QueryTerm(org.opencastproject.workflow.api.WorkflowQuery.QueryTerm)

Example 2 with QueryTerm

use of org.opencastproject.workflow.api.WorkflowQuery.QueryTerm in project opencast by opencast.

the class WorkflowServiceRemoteImpl method getWorkflowInstances.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService
 *      #getWorkflowInstances(org.opencastproject.workflow.api.WorkflowQuery)
 */
@Override
public WorkflowSet getWorkflowInstances(WorkflowQuery query) throws WorkflowDatabaseException {
    List<NameValuePair> queryStringParams = new ArrayList<NameValuePair>();
    if (query.getText() != null)
        queryStringParams.add(new BasicNameValuePair("q", query.getText()));
    if (query.getStates() != null) {
        for (QueryTerm stateQueryTerm : query.getStates()) {
            String value = stateQueryTerm.isInclude() ? stateQueryTerm.getValue() : "-" + stateQueryTerm.getValue();
            queryStringParams.add(new BasicNameValuePair("state", value));
        }
    }
    if (query.getCurrentOperations() != null) {
        for (QueryTerm opQueryTerm : query.getCurrentOperations()) {
            String value = opQueryTerm.isInclude() ? opQueryTerm.getValue() : "-" + opQueryTerm.getValue();
            queryStringParams.add(new BasicNameValuePair("op", value));
        }
    }
    if (query.getSeriesId() != null)
        queryStringParams.add(new BasicNameValuePair("seriesId", query.getSeriesId()));
    if (query.getSeriesTitle() != null)
        queryStringParams.add(new BasicNameValuePair("seriesTitle", query.getSeriesTitle()));
    if (query.getMediaPackageId() != null)
        queryStringParams.add(new BasicNameValuePair("mp", query.getMediaPackageId()));
    if (query.getWorkflowDefinitionId() != null)
        queryStringParams.add(new BasicNameValuePair("workflowdefinition", query.getWorkflowDefinitionId()));
    if (query.getFromDate() != null)
        queryStringParams.add(new BasicNameValuePair("fromdate", SolrUtils.serializeDate(query.getFromDate())));
    if (query.getToDate() != null)
        queryStringParams.add(new BasicNameValuePair("todate", SolrUtils.serializeDate(query.getToDate())));
    if (query.getCreator() != null)
        queryStringParams.add(new BasicNameValuePair("creator", query.getCreator()));
    if (query.getContributor() != null)
        queryStringParams.add(new BasicNameValuePair("contributor", query.getContributor()));
    if (query.getLanguage() != null)
        queryStringParams.add(new BasicNameValuePair("language", query.getLanguage()));
    if (query.getLicense() != null)
        queryStringParams.add(new BasicNameValuePair("license", query.getLicense()));
    if (query.getTitle() != null)
        queryStringParams.add(new BasicNameValuePair("title", query.getTitle()));
    if (query.getSubject() != null)
        queryStringParams.add(new BasicNameValuePair("subject", query.getSubject()));
    if (query.getSort() != null) {
        String sort = query.getSort().toString();
        if (!query.isSortAscending()) {
            sort += "_DESC";
        }
        queryStringParams.add(new BasicNameValuePair("sort", sort));
    }
    if (query.getStartPage() > 0)
        queryStringParams.add(new BasicNameValuePair("startPage", Long.toString(query.getStartPage())));
    if (query.getCount() > 0)
        queryStringParams.add(new BasicNameValuePair("count", Long.toString(query.getCount())));
    StringBuilder url = new StringBuilder();
    url.append("/instances.xml");
    if (queryStringParams.size() > 0)
        url.append("?" + URLEncodedUtils.format(queryStringParams, "UTF-8"));
    HttpGet get = new HttpGet(url.toString());
    HttpResponse response = getResponse(get);
    try {
        if (response != null)
            return WorkflowParser.parseWorkflowSet(response.getEntity().getContent());
    } catch (Exception e) {
        throw new WorkflowDatabaseException(e);
    } finally {
        closeConnection(response);
    }
    throw new WorkflowDatabaseException("Workflow instances can not be loaded from a remote workflow service");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) QueryTerm(org.opencastproject.workflow.api.WorkflowQuery.QueryTerm) ParseException(org.apache.http.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

QueryTerm (org.opencastproject.workflow.api.WorkflowQuery.QueryTerm)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HttpResponse (org.apache.http.HttpResponse)1 NameValuePair (org.apache.http.NameValuePair)1 ParseException (org.apache.http.ParseException)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 NotFoundException (org.opencastproject.util.NotFoundException)1 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)1 WorkflowException (org.opencastproject.workflow.api.WorkflowException)1 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)1