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