Search in sources :

Example 6 with Tuple

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);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Severity(org.opencastproject.job.api.Incident.Severity) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple)

Example 7 with Tuple

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) LocalHashMap(org.opencastproject.util.LocalHashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) Severity(org.opencastproject.job.api.Incident.Severity) URI(java.net.URI) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) NotFoundException(org.opencastproject.util.NotFoundException) JSONObject(org.json.simple.JSONObject) JaxbIncident(org.opencastproject.job.api.JaxbIncident) JaxbIncident(org.opencastproject.job.api.JaxbIncident) Incident(org.opencastproject.job.api.Incident) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 8 with Tuple

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();
}
Also used : EntityManager(javax.persistence.EntityManager) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NoResultException(javax.persistence.NoResultException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Tuple(org.opencastproject.util.data.Tuple) LinkedList(java.util.LinkedList)

Example 9 with Tuple

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);
}
Also used : MultiShapeLayout(org.opencastproject.composer.layout.MultiShapeLayout) ArrayList(java.util.ArrayList) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) Dimension(org.opencastproject.composer.layout.Dimension) HorizontalCoverageLayoutSpec(org.opencastproject.composer.layout.HorizontalCoverageLayoutSpec) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 10 with Tuple

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;
}
Also used : MultiShapeLayout(org.opencastproject.composer.layout.MultiShapeLayout) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) ArrayList(java.util.ArrayList) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) Dimension(org.opencastproject.composer.layout.Dimension) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) EncoderException(org.opencastproject.composer.api.EncoderException) Tuple(org.opencastproject.util.data.Tuple) AbsolutePositionLayoutSpec(org.opencastproject.composer.layout.AbsolutePositionLayoutSpec)

Aggregations

Tuple (org.opencastproject.util.data.Tuple)28 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 NotFoundException (org.opencastproject.util.NotFoundException)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 URI (java.net.URI)6 Job (org.opencastproject.job.api.Job)5 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)5 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 LaidOutElement (org.opencastproject.composer.api.LaidOutElement)4 Dimension (org.opencastproject.composer.layout.Dimension)4 Catalog (org.opencastproject.mediapackage.Catalog)4 AccessControlList (org.opencastproject.security.api.AccessControlList)4 File (java.io.File)3 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 MultiShapeLayout (org.opencastproject.composer.layout.MultiShapeLayout)3