Search in sources :

Example 1 with WorkflowSetImpl

use of org.opencastproject.workflow.api.WorkflowSetImpl in project opencast by opencast.

the class WorkflowServiceSolrIndex method getWorkflowInstances.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.impl.WorkflowServiceIndex#getWorkflowInstances(org.opencastproject.workflow.api.WorkflowQuery,
 *      String, boolean)
 */
@Override
public WorkflowSet getWorkflowInstances(WorkflowQuery query, String action, boolean applyPermissions) throws WorkflowDatabaseException {
    // default to 20 items if not specified
    int count = query.getCount() > 0 ? (int) query.getCount() : 20;
    int startIndex = query.getStartPage() > 0 ? (int) query.getStartPage() * count : (int) query.getStartIndex();
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setRows(count);
    solrQuery.setStart(startIndex);
    String solrQueryString = createQuery(query, action, applyPermissions);
    solrQuery.setQuery(solrQueryString);
    if (query.getSort() != null) {
        ORDER order = query.isSortAscending() ? ORDER.asc : ORDER.desc;
        solrQuery.addSortField(getSortField(query.getSort()) + "_sort", order);
    }
    if (!Sort.DATE_CREATED.equals(query.getSort())) {
        solrQuery.addSortField(getSortField(Sort.DATE_CREATED) + "_sort", ORDER.desc);
    }
    long totalHits;
    long time = System.currentTimeMillis();
    WorkflowSetImpl set = null;
    try {
        QueryResponse response = solrServer.query(solrQuery);
        SolrDocumentList items = response.getResults();
        long searchTime = System.currentTimeMillis() - time;
        totalHits = items.getNumFound();
        set = new WorkflowSetImpl();
        set.setPageSize(count);
        set.setTotalCount(totalHits);
        set.setStartPage(query.getStartPage());
        set.setSearchTime(searchTime);
        // Iterate through the results
        for (SolrDocument doc : items) {
            String xml = (String) doc.get(XML_KEY);
            try {
                set.addItem(WorkflowParser.parseWorkflowInstance(xml));
            } catch (Exception e) {
                throw new IllegalStateException("can not parse workflow xml", e);
            }
        }
    } catch (Exception e) {
        throw new WorkflowDatabaseException(e);
    }
    long totalTime = System.currentTimeMillis() - time;
    logger.debug("Workflow query took {} ms", totalTime);
    return set;
}
Also used : ORDER(org.apache.solr.client.solrj.SolrQuery.ORDER) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) WorkflowSetImpl(org.opencastproject.workflow.api.WorkflowSetImpl) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ServiceException(org.osgi.framework.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 ORDER (org.apache.solr.client.solrj.SolrQuery.ORDER)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)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 WorkflowSetImpl (org.opencastproject.workflow.api.WorkflowSetImpl)1 ServiceException (org.osgi.framework.ServiceException)1