use of org.opencastproject.workflow.api.WorkflowDefinition in project opencast by opencast.
the class JobsListProviderTest method setUp.
@Before
public void setUp() throws Exception {
jobsListProvider = new JobsListProvider();
workflowDefinitions = new ArrayList<WorkflowDefinition>();
WorkflowDefinition wfD = new WorkflowDefinitionImpl();
wfD.setTitle("Full");
wfD.setId("full");
workflowDefinitions.add(wfD);
wfD = new WorkflowDefinitionImpl();
wfD.setTitle("Quick");
wfD.setId("quick");
workflowDefinitions.add(wfD);
workflowService = EasyMock.createNiceMock(WorkflowService.class);
EasyMock.expect(workflowService.listAvailableWorkflowDefinitions()).andReturn(workflowDefinitions).anyTimes();
jobsListProvider.setWorkflowService(workflowService);
jobsListProvider.activate(null);
EasyMock.replay(workflowService);
}
use of org.opencastproject.workflow.api.WorkflowDefinition in project opencast by opencast.
the class JobsListProviderTest method testWorkflowListName.
@Test
public void testWorkflowListName() throws ListProviderException, WorkflowDatabaseException {
ResourceListQuery query = new JobsListQuery();
assertEquals(workflowDefinitions.size(), jobsListProvider.getList(JobsListProvider.LIST_WORKFLOW, query, null).size());
for (Entry<String, String> entry : jobsListProvider.getList(JobsListProvider.LIST_WORKFLOW, query, null).entrySet()) {
boolean match = false;
for (WorkflowDefinition wfD : workflowDefinitions) {
if (StringUtils.equals(wfD.getId(), entry.getKey()) && StringUtils.equals(wfD.getTitle(), entry.getValue())) {
match = true;
break;
}
}
assertTrue(match);
}
}
use of org.opencastproject.workflow.api.WorkflowDefinition in project opencast by opencast.
the class EventsLoader method addWorkflowEntry.
private void addWorkflowEntry(MediaPackage mediaPackage) throws Exception {
WorkflowDefinition def = workflowService.getWorkflowDefinitionById("full");
WorkflowInstance workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, securityService.getUser(), securityService.getOrganization(), new HashMap<String, String>());
workflowInstance.setState(WorkflowState.SUCCEEDED);
String xml = WorkflowParser.toXml(workflowInstance);
// create job
Job job = serviceRegistry.createJob(WorkflowService.JOB_TYPE, "START_WORKFLOW", null, null, false);
job.setStatus(Status.FINISHED);
job.setPayload(xml);
job = serviceRegistry.updateJob(job);
workflowInstance.setId(job.getId());
workflowService.update(workflowInstance);
}
use of org.opencastproject.workflow.api.WorkflowDefinition in project opencast by opencast.
the class TasksEndpoint method createNewTask.
@POST
@Path("/new")
@RestQuery(name = "createNewTask", description = "Creates a new task by the given metadata as JSON", returnDescription = "The task identifiers", restParameters = { @RestParameter(name = "metadata", isRequired = true, description = "The metadata as JSON", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_CREATED, description = "Task sucessfully added"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the workflow definition is not found"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "If the metadata is not set or couldn't be parsed") })
public Response createNewTask(@FormParam("metadata") String metadata) throws NotFoundException {
if (StringUtils.isBlank(metadata)) {
logger.warn("No metadata set");
return RestUtil.R.badRequest("No metadata set");
}
Gson gson = new Gson();
Map metadataJson = null;
try {
metadataJson = gson.fromJson(metadata, Map.class);
} catch (Exception e) {
logger.warn("Unable to parse metadata {}", metadata);
return RestUtil.R.badRequest("Unable to parse metadata");
}
String workflowId = (String) metadataJson.get("workflow");
if (StringUtils.isBlank(workflowId))
return RestUtil.R.badRequest("No workflow set");
List eventIds = (List) metadataJson.get("eventIds");
if (eventIds == null)
return RestUtil.R.badRequest("No eventIds set");
Map<String, String> configuration = (Map<String, String>) metadataJson.get("configuration");
if (configuration == null) {
configuration = new HashMap<>();
} else {
Iterator<String> confKeyIter = configuration.keySet().iterator();
while (confKeyIter.hasNext()) {
String confKey = confKeyIter.next();
if (StringUtils.equalsIgnoreCase("eventIds", confKey)) {
confKeyIter.remove();
}
}
}
WorkflowDefinition wfd;
try {
wfd = workflowService.getWorkflowDefinitionById(workflowId);
} catch (WorkflowDatabaseException e) {
logger.error("Unable to get workflow definition {}: {}", workflowId, ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
final Workflows workflows = new Workflows(assetManager, workspace, workflowService);
final List<WorkflowInstance> instances = workflows.applyWorkflowToLatestVersion(eventIds, workflow(wfd, configuration)).toList();
if (eventIds.size() != instances.size()) {
logger.debug("Can't start one or more tasks.");
return Response.status(Status.BAD_REQUEST).build();
}
return Response.status(Status.CREATED).entity(gson.toJson($(instances).map(getWorkflowIds).toList())).build();
}
use of org.opencastproject.workflow.api.WorkflowDefinition in project opencast by opencast.
the class TasksEndpoint method getProcessing.
@GET
@Path("processing.json")
@RestQuery(name = "getProcessing", description = "Returns all the data related to the processing tab in the new tasks modal as JSON", returnDescription = "All the data related to the tasks processing tab as JSON", restParameters = { @RestParameter(name = "tags", isRequired = false, description = "A comma separated list of tags to filter the workflow definitions", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the tasks processing tab as JSON") })
public Response getProcessing(@QueryParam("tags") String tagsString) {
List<String> tags = RestUtil.splitCommaSeparatedParam(Option.option(tagsString)).value();
// This is the JSON Object which will be returned by this request
List<JValue> actions = new ArrayList<>();
try {
List<WorkflowDefinition> workflowsDefinitions = workflowService.listAvailableWorkflowDefinitions();
for (WorkflowDefinition wflDef : workflowsDefinitions) {
if (wflDef.containsTag(tags)) {
actions.add(obj(f("id", v(wflDef.getId())), f("title", v(nul(wflDef.getTitle()).getOr(""))), f("description", v(nul(wflDef.getDescription()).getOr(""))), f("configuration_panel", v(nul(wflDef.getConfigurationPanel()).getOr("")))));
}
}
} catch (WorkflowDatabaseException e) {
logger.error("Unable to get available workflow definitions: {}", ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
return okJson(arr(actions));
}
Aggregations