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);
}
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);
}
}
Aggregations