@Override public A apply(Option<A> as) { return as.getOrElse(none); } };
@Override public A apply(Option<A> ao) { return ao.getOrElse(a); } };
public StandAloneTrustedHttpClientImpl(String user, String pass, Option<Integer> nonceTimeoutRetries, Option<Integer> retryBaseDelay, Option<Integer> retryMaximumVariableTime) { this.user = user; this.pass = pass; this.nonceTimeoutRetries = nonceTimeoutRetries.getOrElse(DEFAULT_NONCE_TIMEOUT_RETRIES); this.retryBaseDelay = retryBaseDelay.getOrElse(DEFAULT_RETRY_BASE_DELAY); this.retryMaximumVariableTime = retryMaximumVariableTime.getOrElse(DEFAULT_RETRY_MAXIMUM_VARIABLE_TIME); }
@Override public T marshal(Option<T> option) throws Exception { return option.getOrElse((T) null); }
Transactional currentTx() { return emStore.get().getOrElse(startTx); }
/** Create a property. Passing none is like setting {@link #ZERO_VAL} which erases the property. */ public static Prop p(String key, Option<Val> val) { return new Prop(key, val.getOrElse(ZERO_VAL)); }
/** * Returns an expression to search for any date that lies in between <code>startDate</code> and <code>endDate</code>. * * @param startDate * the start date or none for an infinite left endpoint, "*" in solr query syntax * @param endDate * the end date or none for an infinite right endpoint, "*" in solr query syntax * @return the serialized search expression */ public static String serializeDateRange(Option<Date> startDate, Option<Date> endDate) { final Function<Date, String> f = format(newSolrDateFormat()); return new StringBuilder("[") .append(startDate.map(f).getOrElse("*")) .append(" TO ") .append(endDate.map(f).getOrElse("*")) .append("]") .toString(); }
@Override public String getPrefix(final String uri) { return option(b.getPrefix(uri)).getOrElse(new Function0<String>() { @Override public String apply() { return a.getPrefix(uri); } }); }
/** Evaluate the xpath expression against the contained document. The expression must return a list of strings (text). */ // todo replace return type with Valid once it is implemented public List<String> strings(String expr) { final List<String> list = new ArrayList<String>(); return nodeSet(expr).map(new Function<NodeList, List<String>>() { @Override public List<String> apply(NodeList nodes) { for (int i = 0; i < nodes.getLength(); i++) { list.add(nodes.item(i).getNodeValue()); } return list; } }).getOrElse(list); } }
/** * OSGI activate method. * * @param cc * OSGI component context **/ public void activate(ComponentContext cc) { acceptJobLoadsExeedingMaxLoad = getOptContextProperty(cc, ACCEPT_JOB_LOADS_EXCEEDING_PROPERTY).map(Strings.toBool) .getOrElse(DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING); }
/** OSGi callback */ public void activate(ComponentContext cc) { host = option(getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY)).bind(Strings.trimToNone).getOrElse( UrlSupport.DEFAULT_BASE_URL); for (BundleInfoDb a : db) a.clear(host); cc.getBundleContext().addBundleListener(this); for (Bundle b : cc.getBundleContext().getBundles()) { logBundle(b); } }
/** * Return the endpoint's server URL and the service path by extracting the relevant parameters from the * ComponentContext. * * @param cc * ComponentContext to get configuration from * @param serverUrlKey * Configuration key for the server URL * @param servicePathKey * Configuration key for the service path * @return (serverUrl, servicePath) * @throws Error * if the service path is not configured for this component */ public static Tuple<String, String> getEndpointUrl(ComponentContext cc, String serverUrlKey, String servicePathKey) { final String serverUrl = option(cc.getBundleContext().getProperty(serverUrlKey)).getOrElse( UrlSupport.DEFAULT_BASE_URL); final String servicePath = option((String) cc.getProperties().get(servicePathKey)).getOrElse( Option.<String> error(RestConstants.SERVICE_PATH_PROPERTY + " property not configured")); return tuple(serverUrl, servicePath); }
private void logBundle(final Bundle bundle) { final BundleInfo info = bundleInfo(host, bundle.getSymbolicName(), bundle.getBundleId(), bundle.getVersion() .toString(), getBuildNumber(bundle)); final String log = String.format("Bundle %s, id %d, version %s, build number %s", info.getBundleSymbolicName(), info.getBundleId(), info.getBundleVersion(), info.getBuildNumber().getOrElse("n/a")); logger.info(log); for (BundleInfoDb a : db) a.store(info); } }
/** * OSGI callback for activating this component * * @param cc * the osgi component context */ public void activate(ComponentContext cc) throws ConfigurationException { logger.info("Static File REST Service started."); serverUrl = OsgiUtil.getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY); useWebserver = BooleanUtils.toBoolean(OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_ENABLED_KEY) .getOrElse("false")); webserverURL = OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_URL_KEY); Option<String> cfgMaxUploadSize = OsgiUtil.getOptContextProperty(cc, STATICFILES_UPLOAD_MAX_SIZE_KEY); if (cfgMaxUploadSize.isSome()) maxUploadSize = Long.parseLong(cfgMaxUploadSize.get()); }
.getOrElse(DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING);
@Override public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException { final WorkflowOperationInstance woi = wi.getCurrentOperation(); final int code = option(woi.getConfiguration(OPT_CODE)).bind(Strings.toInt).getOrElse(1); final Severity severity = option(woi.getConfiguration(OPT_SEVERITY)).bind(parseEnum(Severity.FAILURE)).getOrElse(Severity.INFO); final List<Tuple<String, String>> details = Arrays.stream(ArrayUtils.nullToEmpty( StringUtils.split(woi.getConfiguration(OPT_DETAILS), ";"))) .map((opt) -> opt.split("=")) .filter((t) -> t.length == 2) .map((x) -> Tuple.tuple(x[0], x[1])) .collect(Collectors.toList()); final Map<String, String> params = Arrays.stream(ArrayUtils.nullToEmpty( StringUtils.split(woi.getConfiguration(OPT_PARAMS), ";"))) .map((opt) -> opt.split("=")) .filter((t) -> t.length == 2) .collect(Collectors.toMap(x -> x[0], x -> x[1])); log.info("Create nop job"); final Job job = nopService.nop(); log.info("Log a dummy incident with code %d", code); serviceRegistry.incident().record(job, severity, code, params, details); if (!waitForStatus(job).isSuccess()) { throw new WorkflowOperationException("Job did not complete successfully"); } else { return createResult(WorkflowOperationResult.Action.CONTINUE); } }
/** * Basic sanity checking for media packages. * * <pre> * // media package is ok * sanityCheck(mp).isNone() * </pre> * * @return none if the media package is a healthy condition, some([error_msgs]) otherwise */ public static Option<List<String>> sanityCheck(MediaPackage mp) { final Option<List<String>> errors = sequenceOpt(list(toOption(mp.getIdentifier() != null, "no ID"), toOption(mp.getIdentifier() != null && isNotBlank(mp.getIdentifier().toString()), "blank ID"))); return errors.getOrElse(NIL).size() == 0 ? Option.<List<String>> none() : errors; }
@Override public IncidentL10n getLocalization(long id, Locale locale) throws IncidentServiceException, NotFoundException { final Incident incident = getIncident(id); final List<String> loc = localeToList(locale); // check if cache map is empty // fill cache from final String title = findText(loc, incident.getCode(), FIELD_TITLE).getOrElse(NO_TITLE); final String description = findText(loc, incident.getCode(), FIELD_DESCRIPTION).map( replaceVarsF(incident.getDescriptionParameters())).getOrElse(NO_DESCRIPTION); return new IncidentL10n() { @Override public String getTitle() { return title; } @Override public String getDescription() { return description; } }; }
case Analyze: audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0)); serialized = analyze(job, audioTrack).map(MediaPackageElementParser.<Track> getAsXml()).getOrElse(""); break; case Normalize: Float targetRmsLevDb = new Float(arguments.get(1)); serialized = normalize(job, audioTrack, targetRmsLevDb).map(MediaPackageElementParser.<Track> getAsXml()) .getOrElse(""); break; default:
/** * {@inheritDoc} * * @see org.opencastproject.metadata.api.MetadataService#getMetadata(org.opencastproject.mediapackage.MediaPackage) */ @Override public StaticMetadata getMetadata(final MediaPackage mp) { return mlist(list(mp.getCatalogs(DublinCoreCatalog.ANY_DUBLINCORE))) .find(flavorPredicate(MediaPackageElements.EPISODE)) .flatMap(loader) .map(new Function<DublinCoreCatalog, StaticMetadata>() { @Override public StaticMetadata apply(DublinCoreCatalog episode) { return newStaticMetadataFromEpisode(episode); } }) .getOrElse((StaticMetadata) null); }