Search in sources :

Example 1 with Fx

use of com.entwinemedia.fn.Fx in project opencast by opencast.

the class ImageWorkflowOperationHandler method validateTargetBaseNameFormat.

static Fx<String> validateTargetBaseNameFormat(final String formatName) {
    return new Fx<String>() {

        @Override
        public void apply(String format) {
            boolean valid;
            try {
                final String name = formatFileName(format, 15.11, ".png");
                valid = name.contains(".") && name.contains(".png");
            } catch (IllegalFormatException e) {
                valid = false;
            }
            if (!valid) {
                chuck(new WorkflowOperationException(format("%s is not a valid format string for config option %s", format, formatName)));
            }
        }
    };
}
Also used : Fx(com.entwinemedia.fn.Fx) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IllegalFormatException(java.util.IllegalFormatException)

Example 2 with Fx

use of com.entwinemedia.fn.Fx in project opencast by opencast.

the class ImageWorkflowOperationHandler method configure.

/**
 * Get and parse the configuration options.
 */
private Cfg configure(MediaPackage mp, WorkflowOperationInstance woi) throws WorkflowOperationException {
    final List<EncodingProfile> profiles = getOptConfig(woi, OPT_PROFILES).toStream().bind(asList.toFn()).map(fetchProfile(composerService)).toList();
    final List<String> targetImageTags = getOptConfig(woi, OPT_TARGET_TAGS).toStream().bind(asList.toFn()).toList();
    final Opt<MediaPackageElementFlavor> targetImageFlavor = getOptConfig(woi, OPT_TARGET_FLAVOR).map(MediaPackageElementFlavor.parseFlavor.toFn());
    final List<Track> sourceTracks;
    {
        // get the source flavors
        final Stream<MediaPackageElementFlavor> sourceFlavors = getOptConfig(woi, OPT_SOURCE_FLAVORS).toStream().bind(Strings.splitCsv).append(getOptConfig(woi, OPT_SOURCE_FLAVOR)).map(MediaPackageElementFlavor.parseFlavor.toFn());
        // get the source tags
        final Stream<String> sourceTags = getOptConfig(woi, OPT_SOURCE_TAGS).toStream().bind(Strings.splitCsv);
        // fold both into a selector
        final TrackSelector trackSelector = sourceTags.apply(tagFold(sourceFlavors.apply(flavorFold(new TrackSelector()))));
        // select the tracks based on source flavors and tags and skip those that don't have video
        sourceTracks = $(trackSelector.select(mp, true)).filter(Filters.hasVideo.toFn()).each(new Fx<Track>() {

            @Override
            public void apply(Track track) {
                if (track.getDuration() == null) {
                    chuck(new WorkflowOperationException(format("Track %s cannot tell its duration", track)));
                }
            }
        }).toList();
    }
    final List<MediaPosition> positions = parsePositions(getConfig(woi, OPT_POSITIONS));
    final long endMargin = getOptConfig(woi, OPT_END_MARGIN).bind(Strings.toLong).getOr(END_MARGIN_DEFAULT);
    // 
    return new Cfg(sourceTracks, positions, profiles, targetImageFlavor, targetImageTags, getTargetBaseNameFormat(woi, OPT_TARGET_BASE_NAME_FORMAT_SECOND), getTargetBaseNameFormat(woi, OPT_TARGET_BASE_NAME_FORMAT_PERCENT), endMargin);
}
Also used : TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Fx(com.entwinemedia.fn.Fx) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Stream(com.entwinemedia.fn.Stream) Track(org.opencastproject.mediapackage.Track)

Example 3 with Fx

use of com.entwinemedia.fn.Fx in project opencast by opencast.

the class Database method setAvailability.

public void setAvailability(final VersionImpl version, final String mpId, final Availability availability) {
    penv.tx(new Fx<EntityManager>() {

        @Override
        public void apply(EntityManager em) {
            final QSnapshotDto q = QSnapshotDto.snapshotDto;
            new JPAUpdateClause(em, q, TEMPLATES).where(q.version.eq(version.value()).and(q.mediaPackageId.eq(mpId))).set(q.availability, availability.name()).execute();
        }
    }.toFn());
}
Also used : Fx(com.entwinemedia.fn.Fx) EntityManager(javax.persistence.EntityManager) JPAUpdateClause(com.mysema.query.jpa.impl.JPAUpdateClause)

Aggregations

Fx (com.entwinemedia.fn.Fx)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)2 Stream (com.entwinemedia.fn.Stream)1 JPAUpdateClause (com.mysema.query.jpa.impl.JPAUpdateClause)1 IllegalFormatException (java.util.IllegalFormatException)1 EntityManager (javax.persistence.EntityManager)1 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 Track (org.opencastproject.mediapackage.Track)1 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)1