Search in sources :

Example 16 with WorkflowInstanceImpl

use of org.opencastproject.workflow.api.WorkflowInstanceImpl 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 17 with WorkflowInstanceImpl

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

the class VideoEditorWorkflowOperationHandlerTest method getWorkflowInstance.

private WorkflowInstanceImpl getWorkflowInstance(MediaPackage mp, Map<String, String> configurations) {
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowInstance.WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", WorkflowOperationInstance.OperationState.RUNNING);
    operation.setTemplate("editor");
    operation.setState(WorkflowOperationInstance.OperationState.RUNNING);
    for (String key : configurations.keySet()) {
        operation.setConfiguration(key, configurations.get(key));
    }
    List<WorkflowOperationInstance> operations = new ArrayList<WorkflowOperationInstance>(1);
    operations.add(operation);
    workflowInstance.setOperations(operations);
    return workflowInstance;
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 18 with WorkflowInstanceImpl

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

the class VideoEditorWorkflowOperationHandlerTest method testEditorResume.

@Test
public void testEditorResume() throws WorkflowOperationException, URISyntaxException, NotFoundException, IOException, ProcessFailedException, ServiceRegistryException, MediaPackageException {
    // filled smil file
    URI episodeSmilURI = VideoEditorWorkflowOperationHandlerTest.class.getResource("/editor_smil_filled.smil").toURI();
    File episodeSmilFile = new File(episodeSmilURI);
    // setup mock services
    EasyMock.expect(workspaceMock.get((URI) EasyMock.anyObject())).andReturn(episodeSmilFile);
    EasyMock.expect(workspaceMock.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(episodeSmilURI);
    EasyMock.expect(workspaceMock.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(URI.create("http://localhost:8080/foo/trimmed.mp4"));
    Job job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(mpSmil.getTracks()[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    videoEditorWorkflowOperationHandler.setServiceRegistry(serviceRegistry);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.expect(videoEditorServiceMock.processSmil((Smil) EasyMock.anyObject())).andReturn(Arrays.asList(job));
    EasyMock.replay(workspaceMock, job, serviceRegistry, videoEditorServiceMock);
    WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mpSmil, getDefaultConfiguration(true));
    // run test
    WorkflowOperationResult result = videoEditorWorkflowOperationHandler.resume(workflowInstance, null, null);
    Assert.assertNotNull("VideoEditor workflow operation returns null but should be an instantiated WorkflowOperationResult", result);
    EasyMock.verify(workspaceMock, job, serviceRegistry, videoEditorServiceMock);
    // verify trimmed track derived from source track
    WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
    String targetFlavorSubtypeProperty = worflowOperationInstance.getConfiguration("target-flavor-subtype");
    String sourceFlavorsProperty = worflowOperationInstance.getConfiguration("source-flavors");
    TrackSelector trackSelector = new TrackSelector();
    trackSelector.addFlavor(sourceFlavorsProperty);
    Collection<Track> sourceTracks = trackSelector.select(result.getMediaPackage(), false);
    Assert.assertTrue("Mediapackage does not contain any tracks matching flavor " + sourceFlavorsProperty, sourceTracks != null && !sourceTracks.isEmpty());
    for (Track sourceTrack : sourceTracks) {
        MediaPackageElementFlavor targetFlavor = MediaPackageElementFlavor.flavor(sourceTrack.getFlavor().getType(), targetFlavorSubtypeProperty);
        Track[] targetTracks = result.getMediaPackage().getTracks(targetFlavor);
        Assert.assertTrue("Media package doesn't contain track with flavor " + targetFlavor.toString(), targetTracks != null && targetTracks.length > 0);
    }
}
Also used : TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) URI(java.net.URI) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) File(java.io.File) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 19 with WorkflowInstanceImpl

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

the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunTranscriptionCompletedState.

@Test
public void testWorkflowDispatcherRunTranscriptionCompletedState() throws Exception {
    database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
    // Mocks for query, result, etc
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p);
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L);
    EasyMock.expect(r.getRecords()).andReturn(recStream);
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
    EasyMock.expect(selectQuery.run()).andReturn(r);
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t);
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p);
    EasyMock.expect(query.version()).andReturn(v);
    EasyMock.expect(assetManager.createQuery()).andReturn(query);
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
    Capture<Set<String>> capturedMpIds = Capture.newInstance();
    WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
    EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
    List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
    wfList.add(new WorkflowInstanceImpl());
    Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
    Workflows wfs = EasyMock.createNiceMock(Workflows.class);
    EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
    service.setWfUtil(wfs);
    EasyMock.replay(wfService, wfs);
    WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
    dispatcher.run();
    // Check if only one mp has a workflow created for it
    Assert.assertEquals(1, capturedMpIds.getValue().size());
    // And if it was the correct one
    Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
    // Check if status in db was updated
    TranscriptionJobControl job = database.findByJob(JOB_ID);
    Assert.assertNotNull(job);
    Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
Also used : TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) Set(java.util.Set) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) Workflows(org.opencastproject.assetmanager.util.Workflows) VersionField(org.opencastproject.assetmanager.api.query.VersionField) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowDispatcher(org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ConfiguredWorkflow(org.opencastproject.workflow.api.ConfiguredWorkflow) Predicate(org.opencastproject.assetmanager.api.query.Predicate) Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) AResult(org.opencastproject.assetmanager.api.query.AResult) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Example 20 with WorkflowInstanceImpl

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

the class StartTranscriptionOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // Media package set up
    URI mediaPackageURI = StartTranscriptionOperationHandlerTest.class.getResource("/mp.xml").toURI();
    mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
    // Service registry set up
    Job job1 = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job1.getId()).andReturn(1L);
    EasyMock.expect(job1.getPayload()).andReturn(null).anyTimes();
    EasyMock.expect(job1.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job1.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job1.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job1.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job1);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
    EasyMock.replay(serviceRegistry);
    // Transcription service set up
    service = EasyMock.createStrictMock(TranscriptionService.class);
    capturedTrack = Capture.newInstance();
    EasyMock.expect(service.startTranscription(EasyMock.anyObject(String.class), EasyMock.capture(capturedTrack))).andReturn(null);
    EasyMock.replay(service);
    // Workflow set up
    WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
    def.setId("DCE-start-transcription");
    def.setPublished(true);
    workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, null, null, null);
    workflowInstance.setId(1);
    operation = new WorkflowOperationInstanceImpl("start-transcript", OperationState.RUNNING);
    List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
    operationList.add(operation);
    workflowInstance.setOperations(operationList);
    // Operation handler set up
    operationHandler = new StartTranscriptionOperationHandler();
    operationHandler.setTranscriptionService(service);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : TranscriptionService(org.opencastproject.transcription.api.TranscriptionService) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) URI(java.net.URI) Date(java.util.Date) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Before(org.junit.Before)

Aggregations

WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)57 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)37 ArrayList (java.util.ArrayList)34 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)31 Test (org.junit.Test)27 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)17 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 Job (org.opencastproject.job.api.Job)9 Track (org.opencastproject.mediapackage.Track)9 URI (java.net.URI)8 Before (org.junit.Before)8 HashMap (java.util.HashMap)7 NotFoundException (org.opencastproject.util.NotFoundException)7 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)7 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)6 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)5 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)5 File (java.io.File)4