@Override public A apply(Option<A> as) { return as.get(); } };
/** * 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()); }
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getDiskSpace() */ public String getDiskSpace() { int usable = Math.round(getUsableSpace().get() / 1024 / 1024 / 1024); int total = Math.round(getTotalSpace().get() / 1024 / 1024 / 1024); long percent = Math.round(100.0 * getUsableSpace().get() / (1 + getTotalSpace().get())); return "Usable space " + usable + " Gb out of " + total + " Gb (" + percent + "%)"; }
@Override public boolean equals(Object o) { if (o instanceof Option) { Option<?> opt = (Option<?>) o; // since an Option should NEVER contain any null this is safe return opt.isSome() && a.equals(opt.get()); } else { return false; } }
@SuppressWarnings("unchecked") @GET @Produces(MediaType.APPLICATION_JSON) @Path("storage") @RestQuery(name = "storage", description = "Returns a report on the disk usage and availability", returnDescription = "Plain text containing the report", reponses = { @RestResponse(responseCode = SC_OK, description = "Report returned") }) public Response restGetTotalStorage() { long total = this.getTotalSpace().get(); long usable = this.getUsableSpace().get(); long used = this.getUsedSpace().get(); String summary = this.getDiskSpace(); JSONObject json = new JSONObject(); json.put("size", total); json.put("usable", usable); json.put("used", used); json.put("summary", summary); return Response.ok(json.toJSONString()).build(); }
@Override public Option<Long> getTemporalDuration() { if (temporalOpt.isSome()) { if (temporalOpt.get() instanceof Long) { return temporalOpt; } } return Option.none(); }
@Override public Option<Date> getTemporalInstant() { if (temporalOpt.isSome()) { if (temporalOpt.get() instanceof Date) { return temporalOpt; } } return Option.none(); }
/** * Return the base URL of the HTTP server. <code>http://host:port</code> public URL getBaseUrl() { return baseUrl; } * * Call in @BeforeClass annotated method. */ public void setUpServer() { try { // cut of any base pathbasestUrl might have int port = baseUrl.getPort(); logger.info("Start http server at port " + port); hs = new Server(port); ServletContainer servletContainer = cfg.isSome() ? new ServletContainer(cfg.get()) : new ServletContainer(); ServletHolder jerseyServlet = new ServletHolder(servletContainer); ServletContextHandler context = new ServletContextHandler(hs, "/"); context.addServlet(jerseyServlet, "/*"); hs.start(); } catch (Exception e) { chuck(e); } }
/** Safe decomposition of the option type using functions. */ public <B> B fold(Function<A, B> some, Function0<B> none) { return isSome() ? some.apply(get()) : none.apply(); }
/** * Get the URI for a static file resource depending on whether to get it direct from Opencast or from a webserver. * * @param uuid * The unique identifier for the static file. * @return The URL for the static file resource. * @throws NotFoundException * if the resource couldn't been found */ public URI getStaticFileURL(String uuid) throws NotFoundException { if (useWebserver && webserverURL.isSome()) { return URI.create(UrlSupport.concat(webserverURL.get(), securityService.getOrganization().getId(), uuid, staticFileService.getFileName(uuid))); } else { return URI.create(UrlSupport.concat(serverUrl, STATICFILES_URL_PATH, uuid)); } }