Search in sources :

Example 1 with AbsolutePositionLayoutSpec

use of org.opencastproject.composer.layout.AbsolutePositionLayoutSpec 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)

Example 2 with AbsolutePositionLayoutSpec

use of org.opencastproject.composer.layout.AbsolutePositionLayoutSpec in project opencast by opencast.

the class ThemeWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext)
 */
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    logger.debug("Running theme workflow operation on workflow {}", workflowInstance.getId());
    final MediaPackageElementFlavor bumperFlavor = getOptConfig(workflowInstance, BUMPER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "bumper"));
    final MediaPackageElementFlavor trailerFlavor = getOptConfig(workflowInstance, TRAILER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "trailer"));
    final MediaPackageElementFlavor titleSlideFlavor = getOptConfig(workflowInstance, TITLE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "title-slide"));
    final MediaPackageElementFlavor licenseSlideFlavor = getOptConfig(workflowInstance, LICENSE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "license-slide"));
    final MediaPackageElementFlavor watermarkFlavor = getOptConfig(workflowInstance, WATERMARK_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "watermark"));
    final List<String> bumperTags = asList(workflowInstance.getConfiguration(BUMPER_TAGS));
    final List<String> trailerTags = asList(workflowInstance.getConfiguration(TRAILER_TAGS));
    final List<String> titleSlideTags = asList(workflowInstance.getConfiguration(TITLE_SLIDE_TAGS));
    final List<String> licenseSlideTags = asList(workflowInstance.getConfiguration(LICENSE_SLIDE_TAGS));
    final List<String> watermarkTags = asList(workflowInstance.getConfiguration(WATERMARK_TAGS));
    Opt<String> layoutStringOpt = getOptConfig(workflowInstance, WATERMARK_LAYOUT);
    Opt<String> watermarkLayoutVariable = getOptConfig(workflowInstance, WATERMARK_LAYOUT_VARIABLE);
    List<String> layoutList = new ArrayList<>(Stream.$(layoutStringOpt).bind(Strings.split(";")).toList());
    try {
        MediaPackage mediaPackage = workflowInstance.getMediaPackage();
        String series = mediaPackage.getSeries();
        if (series == null) {
            logger.info("Skipping theme workflow operation, no series assigned to mediapackage {}", mediaPackage.getIdentifier());
            return createResult(Action.SKIP);
        }
        Long themeId;
        try {
            themeId = Long.parseLong(seriesService.getSeriesProperty(series, THEME_PROPERTY_NAME));
        } catch (NotFoundException e) {
            logger.info("Skipping theme workflow operation, no theme assigned to series {} on mediapackage {}.", series, mediaPackage.getIdentifier());
            return createResult(Action.SKIP);
        } catch (UnauthorizedException e) {
            logger.warn("Skipping theme workflow operation, user not authorized to perform operation: {}", ExceptionUtils.getStackTrace(e));
            return createResult(Action.SKIP);
        }
        Theme theme;
        try {
            theme = themesServiceDatabase.getTheme(themeId);
        } catch (NotFoundException e) {
            logger.warn("Skipping theme workflow operation, no theme with id {} found.", themeId);
            return createResult(Action.SKIP);
        }
        logger.info("Applying theme {} to mediapackage {}", themeId, mediaPackage.getIdentifier());
        /* Make theme settings available to workflow instance */
        workflowInstance.setConfiguration(THEME_ACTIVE, Boolean.toString(theme.isBumperActive() || theme.isTrailerActive() || theme.isTitleSlideActive() || theme.isWatermarkActive()));
        workflowInstance.setConfiguration(THEME_BUMPER_ACTIVE, Boolean.toString(theme.isBumperActive()));
        workflowInstance.setConfiguration(THEME_TRAILER_ACTIVE, Boolean.toString(theme.isTrailerActive()));
        workflowInstance.setConfiguration(THEME_TITLE_SLIDE_ACTIVE, Boolean.toString(theme.isTitleSlideActive()));
        workflowInstance.setConfiguration(THEME_TITLE_SLIDE_UPLOADED, Boolean.toString(StringUtils.isNotBlank(theme.getTitleSlideBackground())));
        workflowInstance.setConfiguration(THEME_WATERMARK_ACTIVE, Boolean.toString(theme.isWatermarkActive()));
        if (theme.isBumperActive() && StringUtils.isNotBlank(theme.getBumperFile())) {
            try (InputStream bumper = staticFileService.getFile(theme.getBumperFile())) {
                addElement(mediaPackage, bumperFlavor, bumperTags, bumper, staticFileService.getFileName(theme.getBumperFile()), Type.Track);
            } catch (NotFoundException e) {
                logger.warn("Bumper file {} not found in static file service, skip applying it", theme.getBumperFile());
            }
        }
        if (theme.isTrailerActive() && StringUtils.isNotBlank(theme.getTrailerFile())) {
            try (InputStream trailer = staticFileService.getFile(theme.getTrailerFile())) {
                addElement(mediaPackage, trailerFlavor, trailerTags, trailer, staticFileService.getFileName(theme.getTrailerFile()), Type.Track);
            } catch (NotFoundException e) {
                logger.warn("Trailer file {} not found in static file service, skip applying it", theme.getTrailerFile());
            }
        }
        if (theme.isTitleSlideActive()) {
            if (StringUtils.isNotBlank(theme.getTitleSlideBackground())) {
                try (InputStream titleSlideBackground = staticFileService.getFile(theme.getTitleSlideBackground())) {
                    addElement(mediaPackage, titleSlideFlavor, titleSlideTags, titleSlideBackground, staticFileService.getFileName(theme.getTitleSlideBackground()), Type.Attachment);
                } catch (NotFoundException e) {
                    logger.warn("Title slide file {} not found in static file service, skip applying it", theme.getTitleSlideBackground());
                }
            }
        // TODO add the title slide metadata to the workflow properties to be used by the cover-image WOH
        // String titleSlideMetadata = theme.getTitleSlideMetadata();
        }
        if (theme.isLicenseSlideActive()) {
            if (StringUtils.isNotBlank(theme.getLicenseSlideBackground())) {
                try (InputStream licenseSlideBackground = staticFileService.getFile(theme.getLicenseSlideBackground())) {
                    addElement(mediaPackage, licenseSlideFlavor, licenseSlideTags, licenseSlideBackground, staticFileService.getFileName(theme.getLicenseSlideBackground()), Type.Attachment);
                } catch (NotFoundException e) {
                    logger.warn("License slide file {} not found in static file service, skip applying it", theme.getLicenseSlideBackground());
                }
            } else {
            // TODO define what to do here (maybe extract image as background)
            }
        // TODO add the license slide description to the workflow properties to be used by the cover-image WOH
        // String licenseSlideDescription = theme.getLicenseSlideDescription();
        }
        if (theme.isWatermarkActive() && StringUtils.isNotBlank(theme.getWatermarkFile())) {
            try (InputStream watermark = staticFileService.getFile(theme.getWatermarkFile())) {
                addElement(mediaPackage, watermarkFlavor, watermarkTags, watermark, staticFileService.getFileName(theme.getWatermarkFile()), Type.Attachment);
            } catch (NotFoundException e) {
                logger.warn("Watermark file {} not found in static file service, skip applying it", theme.getWatermarkFile());
            }
            if (layoutStringOpt.isNone() || watermarkLayoutVariable.isNone())
                throw new WorkflowOperationException(format("Configuration key '%s' or '%s' is either missing or empty", WATERMARK_LAYOUT, WATERMARK_LAYOUT_VARIABLE));
            AbsolutePositionLayoutSpec watermarkLayout = parseLayout(theme.getWatermarkPosition());
            layoutList.set(layoutList.size() - 1, Serializer.json(watermarkLayout).toJson());
            layoutStringOpt = Opt.some(Stream.$(layoutList).mkString(";"));
        }
        if (watermarkLayoutVariable.isSome() && layoutStringOpt.isSome())
            workflowInstance.setConfiguration(watermarkLayoutVariable.get(), layoutStringOpt.get());
        return createResult(mediaPackage, Action.CONTINUE);
    } catch (SeriesException | ThemesServiceDatabaseException | IllegalStateException | IllegalArgumentException | IOException e) {
        throw new WorkflowOperationException(e);
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) ThemesServiceDatabaseException(org.opencastproject.themes.persistence.ThemesServiceDatabaseException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Theme(org.opencastproject.themes.Theme) AbsolutePositionLayoutSpec(org.opencastproject.composer.layout.AbsolutePositionLayoutSpec)

Aggregations

IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AbsolutePositionLayoutSpec (org.opencastproject.composer.layout.AbsolutePositionLayoutSpec)2 NotFoundException (org.opencastproject.util.NotFoundException)2 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 InputStream (java.io.InputStream)1 EncoderException (org.opencastproject.composer.api.EncoderException)1 LaidOutElement (org.opencastproject.composer.api.LaidOutElement)1 Dimension (org.opencastproject.composer.layout.Dimension)1 MultiShapeLayout (org.opencastproject.composer.layout.MultiShapeLayout)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 SeriesException (org.opencastproject.series.api.SeriesException)1 Theme (org.opencastproject.themes.Theme)1 ThemesServiceDatabaseException (org.opencastproject.themes.persistence.ThemesServiceDatabaseException)1 Tuple (org.opencastproject.util.data.Tuple)1