use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowOperationSkippingTest method testIf.
@Test
public void testIf() throws Exception {
Map<String, String> properties1 = new HashMap<String, String>();
properties1.put("executecondition", "true");
Map<String, String> properties2 = new HashMap<String, String>();
properties2.put("executecondition", "false");
WorkflowInstance instance = startAndWait(workingDefinition, mediapackage1, properties1, WorkflowState.SUCCEEDED);
WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage1, properties2, WorkflowState.SUCCEEDED);
WorkflowInstance instance3 = startAndWait(workingDefinition, mediapackage1, null, WorkflowState.SUCCEEDED);
// See if the skip operation has been executed
WorkflowInstance instanceFromDb = service.getWorkflowById(instance.getId());
assertNotNull(instanceFromDb);
assertEquals(OperationState.SUCCEEDED, instanceFromDb.getOperations().get(0).getState());
// See if the skip operation has been skipped (skip value != "true")
WorkflowInstance instance2FromDb = service.getWorkflowById(instance2.getId());
assertNotNull(instance2FromDb);
assertEquals(OperationState.SKIPPED, instance2FromDb.getOperations().get(0).getState());
// See if the skip operation has been skipped (skip property is undefined)
WorkflowInstance instance3FromDb = service.getWorkflowById(instance3.getId());
assertNotNull(instance3FromDb);
assertEquals(OperationState.SKIPPED, instance3FromDb.getOperations().get(0).getState());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowServiceImplAuthzTest method testWorkflowWithoutSecurityPolicy.
@Test
public void testWorkflowWithoutSecurityPolicy() throws Exception {
// Mock up an authorization service that always returns "false" for hasPermission()
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
EasyMock.expect(authzService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(false).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
dao.setAuthorizationService(authzService);
// Create the workflow and its dependent object graph
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.add(new WorkflowOperationDefinitionImpl("op1", "op1", null, true));
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
// As an instructor, create a workflow
userResponder.setResponse(instructor1);
WorkflowInstance workflow = service.start(def, mp);
service.suspend(workflow.getId());
// Ensure that this instructor can access the workflow
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the organization admin can access that workflow
userResponder.setResponse(DEFAULT_ORG_ADMIN);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the global admin can access that workflow
userResponder.setResponse(globalAdmin);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the other instructor can not see the workflow, since there is no security policy granting access
userResponder.setResponse(instructor2);
try {
service.getWorkflowById(workflow.getId());
fail();
} catch (UnauthorizedException e) {
// expected
}
assertEquals(0, service.countWorkflowInstances());
// Ensure the instructor from a different org can not see the workflow, even though they share a role
organizationResponder.setResponse(otherOrganization);
userResponder.setResponse(instructorFromDifferentOrg);
try {
service.getWorkflowById(workflow.getId());
fail();
} catch (Exception e) {
// expected
}
assertEquals(0, service.countWorkflowInstances());
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class IngestRestService method ingestZippedMediaPackage.
private Response ingestZippedMediaPackage(HttpServletRequest request, String wdID, String wiID) {
if (isIngestLimitEnabled()) {
setIngestLimit(getIngestLimit() - 1);
logger.debug("An ingest has started so remaining ingest limit is " + getIngestLimit());
}
InputStream in = null;
Date started = new Date();
logger.info("Received new request from {} to ingest a zipped mediapackage", request.getRemoteHost());
try {
String workflowDefinitionId = wdID;
String workflowIdAsString = wiID;
Long workflowInstanceIdAsLong = null;
Map<String, String> workflowConfig = new HashMap<>();
if (ServletFileUpload.isMultipartContent(request)) {
boolean isDone = false;
for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
FileItemStream item = iter.next();
if (item.isFormField()) {
String fieldName = item.getFieldName();
String value = Streams.asString(item.openStream(), "UTF-8");
logger.trace("{}: {}", fieldName, value);
if (WORKFLOW_INSTANCE_ID_PARAM.equals(fieldName)) {
workflowIdAsString = value;
continue;
} else if (WORKFLOW_DEFINITION_ID_PARAM.equals(fieldName)) {
workflowDefinitionId = value;
continue;
} else {
logger.debug("Processing form field: " + fieldName);
workflowConfig.put(fieldName, value);
}
} else {
logger.debug("Processing file item");
// once the body gets read iter.hasNext must not be invoked or the stream can not be read
// MH-9579
in = item.openStream();
isDone = true;
}
if (isDone)
break;
}
} else {
logger.debug("Processing file item");
in = request.getInputStream();
}
// Adding ingest start time to workflow configuration
DateFormat formatter = new SimpleDateFormat(IngestService.UTC_DATE_FORMAT);
workflowConfig.put(IngestService.START_DATE_KEY, formatter.format(started));
/* Legacy support: Try to convert the workflowId to integer */
if (!StringUtils.isBlank(workflowIdAsString)) {
try {
workflowInstanceIdAsLong = Long.parseLong(workflowIdAsString);
} catch (NumberFormatException e) {
// The workflowId is not a long value and might be the media package identifier
workflowConfig.put(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY, workflowIdAsString);
}
}
if (StringUtils.isBlank(workflowDefinitionId)) {
workflowDefinitionId = defaultWorkflowDefinitionId;
}
WorkflowInstance workflow;
if (workflowInstanceIdAsLong != null) {
workflow = ingestService.addZippedMediaPackage(in, workflowDefinitionId, workflowConfig, workflowInstanceIdAsLong);
} else {
workflow = ingestService.addZippedMediaPackage(in, workflowDefinitionId, workflowConfig);
}
return Response.ok(WorkflowParser.toXml(workflow)).build();
} catch (NotFoundException e) {
logger.info(e.getMessage());
return Response.status(Status.NOT_FOUND).build();
} catch (MediaPackageException e) {
logger.warn(e.getMessage());
return Response.serverError().status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
IOUtils.closeQuietly(in);
if (isIngestLimitEnabled()) {
setIngestLimit(getIngestLimit() + 1);
logger.debug("An ingest has finished so increased ingest limit to " + getIngestLimit());
}
}
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class IngestRestService method ingest.
private Response ingest(MultivaluedMap<String, String> formData, String wdID) {
/**
* Note: We use a MultivaluedMap here to ensure that we can get any arbitrary form parameters. This is required to
* enable things like holding for trim or distributing to YouTube.
*/
final Map<String, String> wfConfig = getWorkflowConfig(formData);
if (StringUtils.isNotBlank(wdID))
wfConfig.put(WORKFLOW_DEFINITION_ID_PARAM, wdID);
final MediaPackage mp;
try {
mp = factory.newMediaPackageBuilder().loadFromXml(formData.getFirst("mediaPackage"));
if (MediaPackageSupport.sanityCheck(mp).isSome()) {
logger.warn("Rejected ingest with invalid mediapackage {}", mp);
return Response.status(Status.BAD_REQUEST).build();
}
} catch (Exception e) {
logger.warn("Rejected ingest without mediapackage");
return Response.status(Status.BAD_REQUEST).build();
}
final String workflowInstance = wfConfig.get(WORKFLOW_INSTANCE_ID_PARAM);
final String workflowDefinition = wfConfig.get(WORKFLOW_DEFINITION_ID_PARAM);
// Adding ingest start time to workflow configuration
wfConfig.put(IngestService.START_DATE_KEY, formatter.format(startCache.asMap().get(mp.getIdentifier().toString())));
final X<WorkflowInstance> ingest = new X<WorkflowInstance>() {
@Override
public WorkflowInstance xapply() throws Exception {
/* Legacy support: Try to convert the workflowInstance to integer */
Long workflowInstanceId = null;
if (StringUtils.isNotBlank(workflowInstance)) {
try {
workflowInstanceId = Long.parseLong(workflowInstance);
} catch (NumberFormatException e) {
// The workflowId is not a long value and might be the media package identifier
wfConfig.put(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY, workflowInstance);
}
}
if (workflowInstanceId != null) {
return ingestService.ingest(mp, trimToNull(workflowDefinition), wfConfig, workflowInstanceId);
} else {
return ingestService.ingest(mp, trimToNull(workflowDefinition), wfConfig);
}
}
};
try {
WorkflowInstance workflow = ingest.apply();
startCache.asMap().remove(mp.getIdentifier().toString());
return Response.ok(WorkflowParser.toXml(workflow)).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class IngestServiceImplTest method testThickClient.
@Test
public void testThickClient() throws Exception {
FileUtils.copyURLToFile(urlPackage.toURL(), packageFile);
InputStream packageStream = null;
try {
packageStream = urlPackage.toURL().openStream();
WorkflowInstance instance = service.addZippedMediaPackage(packageStream);
// Assert.assertEquals(2, mediaPackage.getTracks().length);
// Assert.assertEquals(3, mediaPackage.getCatalogs().length);
Assert.assertEquals(workflowInstanceID, instance.getId());
} catch (IOException e) {
Assert.fail(e.getMessage());
} finally {
IOUtils.closeQuietly(packageStream);
}
}
Aggregations