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