use of org.opencastproject.mediapackage.MediaPackageElement 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();
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class WaveformServiceImplTest method testProcess.
/**
* Test of process method of class WaveformServiceImpl.
*/
@Test
public void testProcess() throws Exception {
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(audioTrack.getURI()));
Capture filenameCapture = new Capture();
EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), (String) EasyMock.capture(filenameCapture), (InputStream) EasyMock.anyObject())).andReturn(new URI("waveform.png"));
EasyMock.replay(workspace);
WaveformServiceImpl instance = new WaveformServiceImpl();
instance.setWorkspace(workspace);
String audioTrackXml = MediaPackageElementParser.getAsXml(audioTrack);
Job job = new JobImpl(1);
job.setJobType(WaveformServiceImpl.JOB_TYPE);
job.setOperation(WaveformServiceImpl.Operation.Waveform.toString());
job.setArguments(Arrays.asList(audioTrackXml));
String result = instance.process(job);
assertNotNull(result);
MediaPackageElement waveformAttachment = MediaPackageElementParser.getFromXml(result);
assertEquals(new URI("waveform.png"), waveformAttachment.getURI());
assertTrue(filenameCapture.hasCaptured());
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class WaveformWorkflowOperationHandler method cleanupWorkspace.
/**
* Remove all files created by the given jobs
* @param jobs
* Jobs to clean up for
*/
private void cleanupWorkspace(List<Job> jobs) {
for (Job job : jobs) {
String jobPayload = job.getPayload();
if (StringUtils.isNotEmpty(jobPayload)) {
try {
MediaPackageElement waveformMpe = MediaPackageElementParser.getFromXml(jobPayload);
URI waveformUri = waveformMpe.getURI();
workspace.delete(waveformUri);
} catch (MediaPackageException ex) {
// unexpected job payload
logger.error("Can't parse waveform attachment from job {}", job.getId());
} catch (NotFoundException ex) {
// this is ok, because we want delete the file
} catch (IOException ex) {
logger.warn("Deleting waveform image file from workspace failed: {}", ex.getMessage());
// this is ok, because workspace cleaner will remove old files if they exist
}
}
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AttachmentTest method testFromURL.
/**
* Test method for {@link org.opencastproject.mediapackage.attachment.AttachmentImpl#fromURI(java.net.URI)}.
*/
@Test
public void testFromURL() {
MediaPackageElementBuilderFactory factory = MediaPackageElementBuilderFactory.newInstance();
MediaPackageElementBuilder builder = factory.newElementBuilder();
MediaPackageElement packageElement = null;
// Create the element
try {
packageElement = builder.elementFromURI(coverFile.toURI());
} catch (UnsupportedElementException e) {
fail("Attachment is unsupported: " + e.getMessage());
}
// Type test
assertTrue("Type mismatch", packageElement instanceof Attachment);
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class LiveScheduleServiceImpl method addAndDistributeElements.
MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException {
try {
MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone();
Set<String> elementIds = new HashSet<String>();
// Then, add series catalog if needed
if (StringUtils.isNotEmpty(mp.getSeries())) {
DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries());
// Create temporary catalog and save to workspace
mp.add(catalog);
URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "series.xml", dublinCoreService.serialize(catalog));
catalog.setURI(uri);
catalog.setChecksum(null);
catalog.setFlavor(MediaPackageElements.SERIES);
elementIds.add(catalog.getIdentifier());
}
if (mp.getCatalogs(MediaPackageElements.EPISODE).length > 0)
elementIds.add(mp.getCatalogs(MediaPackageElements.EPISODE)[0].getIdentifier());
if (mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE).length > 0)
elementIds.add(mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE)[0].getIdentifier());
// Distribute element(s)
Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, elementIds, false);
if (!waitForStatus(distributionJob).isSuccess())
throw new LiveScheduleException("Element(s) for live media package " + mp.getIdentifier() + " could not be distributed");
for (String id : elementIds) {
MediaPackageElement e = mp.getElementById(id);
// Cleanup workspace/wfr
mp.remove(e);
workspace.delete(e.getURI());
}
// Add distributed element(s) to mp
List<MediaPackageElement> distributedElements = (List<MediaPackageElement>) MediaPackageElementParser.getArrayFromXml(distributionJob.getPayload());
for (MediaPackageElement mpe : distributedElements) mp.add(mpe);
return mp;
} catch (LiveScheduleException e) {
throw e;
} catch (Exception e) {
throw new LiveScheduleException(e);
}
}
Aggregations