use of org.opencastproject.util.data.Tuple in project opencast by opencast.
the class IncidentCreatorWorkflowOperationHandler method start.
@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException {
final WorkflowOperationInstance woi = wi.getCurrentOperation();
final int code = option(woi.getConfiguration(OPT_CODE)).bind(Strings.toInt).getOrElse(1);
final Severity severity = option(woi.getConfiguration(OPT_SEVERITY)).bind(parseEnum(Severity.FAILURE)).getOrElse(Severity.INFO);
final List<Tuple<String, String>> details = option(woi.getConfiguration(OPT_DETAILS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value();
final Map<String, String> params = Immutables.map(option(woi.getConfiguration(OPT_PARAMS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value());
log.info("Create nop job");
final Job job = nopService.nop();
log.info("Log a dummy incident with code %d", code);
serviceRegistry.incident().record(job, severity, code, params, details);
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("Job did not complete successfully");
} else {
return createResult(WorkflowOperationResult.Action.CONTINUE);
}
}
use of org.opencastproject.util.data.Tuple in project opencast by opencast.
the class IncidentServiceEndpoint method postIncident.
@POST
@Produces(MediaType.APPLICATION_XML)
@Path("/")
@RestQuery(name = "postincident", description = "Creates a new job incident and returns it as XML", returnDescription = "Returns the created job incident as XML", restParameters = { @RestParameter(name = "job", isRequired = true, description = "The job on where to create the incident", type = Type.TEXT), @RestParameter(name = "date", isRequired = true, description = "The incident creation date", type = Type.STRING), @RestParameter(name = "code", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "severity", isRequired = true, description = "The incident error code", type = Type.STRING), @RestParameter(name = "details", isRequired = false, description = "The incident details", type = Type.TEXT), @RestParameter(name = "params", isRequired = false, description = "The incident parameters", type = Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "New job incident has been created"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the one of the form params"), @RestResponse(responseCode = SC_CONFLICT, description = "No job incident related job exists") })
public Response postIncident(@FormParam("job") String jobXml, @FormParam("date") String date, @FormParam("code") String code, @FormParam("severity") String severityString, @FormParam("details") String details, @FormParam("params") LocalHashMap params) {
Job job;
Date timestamp;
Severity severity;
Map<String, String> map = new HashMap<String, String>();
List<Tuple<String, String>> list = new ArrayList<Tuple<String, String>>();
try {
job = JobParser.parseJob(jobXml);
timestamp = new Date(DateTimeSupport.fromUTC(date));
severity = Severity.valueOf(severityString);
if (params != null)
map = params.getMap();
if (StringUtils.isNotBlank(details)) {
final JSONArray array = (JSONArray) JSONValue.parse(details);
for (int i = 0; i < array.size(); i++) {
JSONObject tuple = (JSONObject) array.get(i);
list.add(Tuple.tuple((String) tuple.get("title"), (String) tuple.get("content")));
}
}
} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
try {
Incident incident = svc.storeIncident(job, timestamp, code, severity, map, list);
String uri = UrlSupport.concat(serverUrl, serviceUrl, Long.toString(incident.getId()), ".xml");
return Response.created(new URI(uri)).entity(new JaxbIncident(incident)).build();
} catch (IllegalStateException e) {
return Response.status(Status.CONFLICT).build();
} catch (Exception e) {
logger.warn("Unable to post incident for job {}: {}", job.getId(), e);
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.util.data.Tuple in project opencast by opencast.
the class SearchServiceDatabaseImpl method getAllMediaPackages.
/**
* {@inheritDoc}
*
* @see org.opencastproject.search.impl.persistence.SearchServiceDatabase#getAllMediaPackages()
*/
@Override
@SuppressWarnings("unchecked")
public Iterator<Tuple<MediaPackage, String>> getAllMediaPackages() throws SearchServiceDatabaseException {
List<SearchEntity> searchEntities = null;
EntityManager em = null;
try {
em = emf.createEntityManager();
Query query = em.createNamedQuery("Search.findAll");
searchEntities = (List<SearchEntity>) query.getResultList();
} catch (Exception e) {
logger.error("Could not retrieve all episodes: {}", e.getMessage());
throw new SearchServiceDatabaseException(e);
} finally {
em.close();
}
List<Tuple<MediaPackage, String>> mediaPackageList = new LinkedList<Tuple<MediaPackage, String>>();
try {
for (SearchEntity entity : searchEntities) {
MediaPackage mediaPackage = MediaPackageParser.getFromXml(entity.getMediaPackageXML());
mediaPackageList.add(Tuple.tuple(mediaPackage, entity.getOrganization()));
}
} catch (Exception e) {
logger.error("Could not parse series entity: {}", e.getMessage());
throw new SearchServiceDatabaseException(e);
}
return mediaPackageList.iterator();
}
use of org.opencastproject.util.data.Tuple in project opencast by opencast.
the class ComposerServiceTest method testComposite.
/**
* Test method for
* {@link ComposerServiceImpl#composite(Dimension, Option, LaidOutElement, Option, String, String)}
*/
@Test
public void testComposite() throws Exception {
if (!ffmpegInstalled)
return;
Dimension outputDimension = new Dimension(500, 500);
List<HorizontalCoverageLayoutSpec> layouts = new ArrayList<HorizontalCoverageLayoutSpec>();
layouts.add(Serializer.horizontalCoverageLayoutSpec(JsonObj.jsonObj("{\"horizontalCoverage\":1.0,\"anchorOffset\":{\"referring\":{\"left\":1.0,\"top\":1.0},\"offset\":{\"y\":-20,\"x\":-20},\"reference\":{\"left\":1.0,\"top\":1.0}}}")));
layouts.add(Serializer.horizontalCoverageLayoutSpec(JsonObj.jsonObj("{\"horizontalCoverage\":0.2,\"anchorOffset\":{\"referring\":{\"left\":0.0,\"top\":0.0},\"offset\":{\"y\":-20,\"x\":-20},\"reference\":{\"left\":0.0,\"top\":0.0}}}")));
layouts.add(Serializer.horizontalCoverageLayoutSpec(JsonObj.jsonObj("{\"horizontalCoverage\":1.0,\"anchorOffset\":{\"referring\":{\"left\":1.0,\"top\":0.0},\"offset\":{\"y\":20,\"x\":20},\"reference\":{\"left\":1.0,\"top\":0.0}}}")));
List<Tuple<Dimension, HorizontalCoverageLayoutSpec>> shapes = new ArrayList<>();
shapes.add(0, Tuple.tuple(new Dimension(300, 300), layouts.get(0)));
shapes.add(1, Tuple.tuple(new Dimension(200, 200), layouts.get(1)));
MultiShapeLayout multiShapeLayout = LayoutManager.multiShapeLayout(outputDimension, shapes);
Option<LaidOutElement<Attachment>> watermarkOption = Option.<LaidOutElement<Attachment>>none();
LaidOutElement<Track> lowerLaidOutElement = new LaidOutElement<Track>(sourceVideoTrack, multiShapeLayout.getShapes().get(0));
LaidOutElement<Track> upperLaidOutElement = new LaidOutElement<Track>(sourceVideoTrack, multiShapeLayout.getShapes().get(1));
Job composite = composerService.composite(outputDimension, Option.option(lowerLaidOutElement), upperLaidOutElement, watermarkOption, "composite.work", "black");
Track compositeTrack = (Track) MediaPackageElementParser.getFromXml(composite.getPayload());
Assert.assertNotNull(compositeTrack);
inspectedTrack.setIdentifier(compositeTrack.getIdentifier());
inspectedTrack.setMimeType(MimeType.mimeType("video", "mp4"));
Assert.assertEquals(inspectedTrack, compositeTrack);
}
use of org.opencastproject.util.data.Tuple in project opencast by opencast.
the class CompositeWorkflowOperationHandler method createWatermarkLaidOutElement.
private Option<LaidOutElement<Attachment>> createWatermarkLaidOutElement(CompositeSettings compositeSettings, Dimension outputDimension, Option<Attachment> watermarkAttachment) throws WorkflowOperationException {
Option<LaidOutElement<Attachment>> watermarkOption = Option.<LaidOutElement<Attachment>>none();
if (watermarkAttachment.isSome() && compositeSettings.getWatermarkLayout().isSome()) {
BufferedImage image;
try {
File watermarkFile = workspace.get(watermarkAttachment.get().getURI());
image = ImageIO.read(watermarkFile);
} catch (Exception e) {
logger.warn("Unable to read the watermark image attachment {}: {}", watermarkAttachment.get().getURI(), e);
throw new WorkflowOperationException("Unable to read the watermark image attachment", e);
}
Dimension imageDimension = Dimension.dimension(image.getWidth(), image.getHeight());
List<Tuple<Dimension, AbsolutePositionLayoutSpec>> watermarkShapes = new ArrayList<Tuple<Dimension, AbsolutePositionLayoutSpec>>();
watermarkShapes.add(0, Tuple.tuple(imageDimension, compositeSettings.getWatermarkLayout().get()));
MultiShapeLayout watermarkLayout = LayoutManager.absoluteMultiShapeLayout(outputDimension, watermarkShapes);
watermarkOption = Option.some(new LaidOutElement<Attachment>(watermarkAttachment.get(), watermarkLayout.getShapes().get(0)));
}
return watermarkOption;
}
Aggregations