Search in sources :

Example 1 with Stream

use of com.entwinemedia.fn.Stream 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 2 with Stream

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

the class DublinCoreUtil method calculateChecksum.

/**
 * Calculate an MD5 checksum for a DublinCore catalog.
 */
public static Checksum calculateChecksum(DublinCoreCatalog dc) {
    // Use 0 as a word separator. This is safe since none of the UTF-8 code points
    // except \u0000 contains a null byte when converting to a byte array.
    final byte[] sep = new byte[] { 0 };
    final MessageDigest md = // consider all DublinCore properties
    $(getPropertiesSorted(dc)).bind(new Fn<CatalogEntry, Stream<String>>() {

        @Override
        public Stream<String> apply(CatalogEntry entry) {
            // get attributes, sorted and serialized as [name, value, name, value, ...]
            final Stream<String> attributesSorted = $(entry.getAttributes().entrySet()).sort(new Comparator<Entry<EName, String>>() {

                @Override
                public int compare(Entry<EName, String> o1, Entry<EName, String> o2) {
                    return o1.getKey().compareTo(o2.getKey());
                }
            }).bind(new Fn<Entry<EName, String>, Stream<String>>() {

                @Override
                public Stream<String> apply(Entry<EName, String> attribute) {
                    return $(attribute.getKey().toString(), attribute.getValue());
                }
            });
            return $(entry.getEName().toString(), entry.getValue()).append(attributesSorted);
        }
    }).append(Opt.nul(dc.getRootTag()).map(toString)).foldl(mkMd5MessageDigest(), new Fn2<MessageDigest, String, MessageDigest>() {

        @Override
        public MessageDigest apply(MessageDigest digest, String s) {
            digest.update(s.getBytes(StandardCharsets.UTF_8));
            // add separator byte (see definition above)
            digest.update(sep);
            return digest;
        }
    });
    try {
        return Checksum.create("md5", Checksum.convertToHex(md.digest()));
    } catch (NoSuchAlgorithmException e) {
        return chuck(e);
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) CatalogEntry(org.opencastproject.mediapackage.XMLCatalogImpl.CatalogEntry) Fn(com.entwinemedia.fn.Fn) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Entry(java.util.Map.Entry) CatalogEntry(org.opencastproject.mediapackage.XMLCatalogImpl.CatalogEntry) Stream(com.entwinemedia.fn.Stream) InputStream(java.io.InputStream) MessageDigest(java.security.MessageDigest)

Aggregations

Stream (com.entwinemedia.fn.Stream)2 Fn (com.entwinemedia.fn.Fn)1 Fx (com.entwinemedia.fn.Fx)1 InputStream (java.io.InputStream)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Entry (java.util.Map.Entry)1 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)1 EName (org.opencastproject.mediapackage.EName)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 Track (org.opencastproject.mediapackage.Track)1 CatalogEntry (org.opencastproject.mediapackage.XMLCatalogImpl.CatalogEntry)1 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)1 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)1