use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.
the class WorkflowServiceSolrIndexTest method testBuildNegativeStateQuery.
/**
* Tests whether the query is built using *:* when supplying a single excluded state
*/
@Test
public void testBuildNegativeStateQuery() throws Exception {
WorkflowQuery q = new WorkflowQuery().withSeriesId("series1").withoutState(WorkflowState.RUNNING);
String solrQuery = dao.createQuery(q, Permissions.Action.READ.toString(), true);
String expected = "oc_org:mh_default_org AND seriesid:series1 AND (-state:running AND *:*)";
assertEquals(expected, solrQuery);
}
use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.
the class WorkflowServiceSolrIndexTest method testNonAdminQuery.
/**
* Tests whether a simple query is built correctly with the authentication fragment
*/
@Test
public void testNonAdminQuery() throws Exception {
String userRole = "ROLE_USER";
User nonAdminUser = new JaxbUser("noAdmin", "test", new DefaultOrganization(), new JaxbRole(userRole, new DefaultOrganization()));
// security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(nonAdminUser).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
dao.setSecurityService(securityService);
WorkflowQuery q = new WorkflowQuery().withMediaPackage("123").withSeriesId("series1");
String solrQuery = dao.createQuery(q, Permissions.Action.READ.toString(), true);
String expected = "oc_org:mh_default_org AND mediapackageid:123 AND seriesid:series1 AND oc_org:" + DefaultOrganization.DEFAULT_ORGANIZATION_ID + " AND (oc_creator:" + nonAdminUser.getUsername() + " OR oc_acl_read:" + userRole + ")";
assertEquals(expected, solrQuery);
}
use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.
the class WorkflowServiceSolrIndexTest method testBuildSimpleQuery.
/**
* Tests whether a simple query is built correctly
*/
@Test
public void testBuildSimpleQuery() throws Exception {
WorkflowQuery q = new WorkflowQuery().withMediaPackage("123").withSeriesId("series1");
String solrQuery = dao.createQuery(q, Permissions.Action.READ.toString(), true);
String expected = "oc_org:mh_default_org AND mediapackageid:123 AND seriesid:series1";
assertEquals(expected, solrQuery);
}
use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.
the class WorkflowServiceSolrIndexTest method testBuildMultiStateQuery.
/**
* Tests whether the query is built properly, using OR rather than AND, when supplying multiple inclusive states
*/
@Test
public void testBuildMultiStateQuery() throws Exception {
WorkflowQuery q = new WorkflowQuery().withSeriesId("series1").withState(WorkflowState.RUNNING).withState(WorkflowState.PAUSED);
String solrQuery = dao.createQuery(q, Permissions.Action.READ.toString(), true);
String expected = "oc_org:mh_default_org AND seriesid:series1 AND (state:running OR state:paused)";
assertEquals(expected, solrQuery);
}
use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.
the class WorkflowRestService method getWorkflowsAsXml.
@GET
@Produces(MediaType.TEXT_XML)
@Path("instances.xml")
@RestQuery(name = "workflowsasxml", description = "List all workflow instances matching the query parameters", returnDescription = "An XML representation of the set of workflows matching these query parameters", restParameters = { @RestParameter(name = "state", isRequired = false, description = "Filter results by workflows' current state", type = STRING), @RestParameter(name = "q", isRequired = false, description = "Filter results by free text query", type = STRING), @RestParameter(name = "seriesId", isRequired = false, description = "Filter results by series identifier", type = STRING), @RestParameter(name = "seriesTitle", isRequired = false, description = "Filter results by series title", type = STRING), @RestParameter(name = "creator", isRequired = false, description = "Filter results by the mediapackage's creator", type = STRING), @RestParameter(name = "contributor", isRequired = false, description = "Filter results by the mediapackage's contributor", type = STRING), @RestParameter(name = "fromdate", isRequired = false, description = "Filter results by workflow start date.", type = STRING), @RestParameter(name = "todate", isRequired = false, description = "Filter results by workflow start date.", type = STRING), @RestParameter(name = "language", isRequired = false, description = "Filter results by mediapackage's language.", type = STRING), @RestParameter(name = "license", isRequired = false, description = "Filter results by mediapackage's license.", type = STRING), @RestParameter(name = "title", isRequired = false, description = "Filter results by mediapackage's title.", type = STRING), @RestParameter(name = "subject", isRequired = false, description = "Filter results by mediapackage's subject.", type = STRING), @RestParameter(name = "workflowdefinition", isRequired = false, description = "Filter results by workflow definition.", type = STRING), @RestParameter(name = "mp", isRequired = false, description = "Filter results by mediapackage identifier.", type = STRING), @RestParameter(name = "op", isRequired = false, description = "Filter results by workflows' current operation.", type = STRING), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any " + "of the following: DATE_CREATED, TITLE, SERIES_TITLE, SERIES_ID, MEDIA_PACKAGE_ID, WORKFLOW_DEFINITION_ID, CREATOR, " + "CONTRIBUTOR, LANGUAGE, LICENSE, SUBJECT. Add '_DESC' to reverse the sort order (e.g. TITLE_DESC).", type = STRING), @RestParameter(name = "startPage", isRequired = false, description = "The paging offset", type = INTEGER), @RestParameter(name = "count", isRequired = false, description = "The number of results to return.", type = INTEGER), @RestParameter(name = "compact", isRequired = false, description = "Whether to return a compact version of " + "the workflow instance, with mediapackage elements, workflow and workflow operation configurations and " + "non-current operations removed.", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the workflow set.") })
public // So for now, we disable checkstyle here.
Response getWorkflowsAsXml(@QueryParam("state") List<String> states, @QueryParam("q") String text, @QueryParam("seriesId") String seriesId, @QueryParam("seriesTitle") String seriesTitle, @QueryParam("creator") String creator, @QueryParam("contributor") String contributor, @QueryParam("fromdate") String fromDate, @QueryParam("todate") String toDate, @QueryParam("language") String language, @QueryParam("license") String license, @QueryParam("title") String title, @QueryParam("subject") String subject, @QueryParam("workflowdefinition") String workflowDefinitionId, @QueryParam("mp") String mediapackageId, @QueryParam("op") List<String> currentOperations, @QueryParam("sort") String sort, @QueryParam("startPage") int startPage, @QueryParam("count") int count, @QueryParam("compact") boolean compact) throws Exception {
// CHECKSTYLE:ON
if (count < 1)
count = DEFAULT_LIMIT;
WorkflowQuery q = new WorkflowQuery();
q.withCount(count);
q.withStartPage(startPage);
if (states != null && states.size() > 0) {
try {
for (String state : states) {
if (StringUtils.isBlank(state)) {
continue;
}
if (state.startsWith(NEGATE_PREFIX)) {
q.withoutState(WorkflowState.valueOf(state.substring(1).toUpperCase()));
} else {
q.withState(WorkflowState.valueOf(state.toUpperCase()));
}
}
} catch (IllegalArgumentException e) {
logger.debug("Unknown workflow state.", e);
}
}
q.withText(text);
q.withSeriesId(seriesId);
q.withSeriesTitle(seriesTitle);
q.withSubject(subject);
q.withMediaPackage(mediapackageId);
q.withCreator(creator);
q.withContributor(contributor);
q.withDateAfter(SolrUtils.parseDate(fromDate));
q.withDateBefore(SolrUtils.parseDate(toDate));
q.withLanguage(language);
q.withLicense(license);
q.withTitle(title);
q.withWorkflowDefintion(workflowDefinitionId);
if (currentOperations != null && currentOperations.size() > 0) {
for (String op : currentOperations) {
if (StringUtils.isBlank(op)) {
continue;
}
if (op.startsWith(NEGATE_PREFIX)) {
q.withoutCurrentOperation(op.substring(1));
} else {
q.withCurrentOperation(op);
}
}
}
if (StringUtils.isNotBlank(sort)) {
// Parse the sort field and direction
Sort sortField = null;
if (sort.endsWith(DESCENDING_SUFFIX)) {
String enumKey = sort.substring(0, sort.length() - DESCENDING_SUFFIX.length()).toUpperCase();
try {
sortField = Sort.valueOf(enumKey);
q.withSort(sortField, false);
} catch (IllegalArgumentException e) {
logger.debug("No sort enum matches '{}'", enumKey);
}
} else {
try {
sortField = Sort.valueOf(sort);
q.withSort(sortField);
} catch (IllegalArgumentException e) {
logger.debug("No sort enum matches '{}'", sort);
}
}
}
WorkflowSet set = service.getWorkflowInstances(q);
// Marshalling of a full workflow takes a long time. Therefore, we strip everything that's not needed.
if (compact) {
for (WorkflowInstance instance : set.getItems()) {
// Remove all operations but the current one
WorkflowOperationInstance currentOperation = instance.getCurrentOperation();
List<WorkflowOperationInstance> operations = instance.getOperations();
// instance.getOperations() is a copy
operations.clear();
if (currentOperation != null) {
for (String key : currentOperation.getConfigurationKeys()) {
currentOperation.removeConfiguration(key);
}
operations.add(currentOperation);
}
instance.setOperations(operations);
// Remove all mediapackage elements (but keep the duration)
MediaPackage mediaPackage = instance.getMediaPackage();
Long duration = instance.getMediaPackage().getDuration();
for (MediaPackageElement element : mediaPackage.elements()) {
mediaPackage.remove(element);
}
mediaPackage.setDuration(duration);
}
}
return Response.ok(set).build();
}
Aggregations