Search in sources :

Example 1 with WorkflowDefinition

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);
}
Also used : WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) WorkflowService(org.opencastproject.workflow.api.WorkflowService) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) Before(org.junit.Before)

Example 2 with WorkflowDefinition

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);
    }
}
Also used : WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) JobsListQuery(org.opencastproject.index.service.resources.list.query.JobsListQuery) Test(org.junit.Test)

Example 3 with WorkflowDefinition

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);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Job(org.opencastproject.job.api.Job)

Example 4 with WorkflowDefinition

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();
}
Also used : Workflows(org.opencastproject.assetmanager.util.Workflows) Gson(com.google.gson.Gson) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with WorkflowDefinition

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));
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)22 ArrayList (java.util.ArrayList)9 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6 Path (javax.ws.rs.Path)5 Test (org.junit.Test)5 NotFoundException (org.opencastproject.util.NotFoundException)5 RestQuery (org.opencastproject.util.doc.rest.RestQuery)5 InputStream (java.io.InputStream)4 GET (javax.ws.rs.GET)4 JValue (com.entwinemedia.fn.data.json.JValue)3 IOException (java.io.IOException)3 Set (java.util.Set)3 Before (org.junit.Before)3 Workflows (org.opencastproject.assetmanager.util.Workflows)3 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)3 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)3 File (java.io.File)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2