List of usage examples for java.util.function Supplier get
T get();
From source file:de.micromata.genome.gwiki.jetty.GWikiInitialSetup.java
/** * /*w w w . j a v a2 s.co m*/ * @param db * @return first initial, url. */ public Pair<String, String> getJdbcUrl(StandaloneDatabases db) { Supplier<Pair<String, String>> supl = db.getCmdlineUrlSuplider(); if (supl != null) { return supl.get(); } message("Get the jdbc url (Sample: " + db.getSampleUrl() + ")"); String inp = getInput("Get the jdbc url (Sample: " + db.getSampleUrl() + "): "); return Pair.make(inp, inp); }
From source file:nu.yona.server.device.service.DeviceService.java
private void setAppLastOpenedDateIfNewer(LocalDate now, Supplier<Optional<LocalDate>> currentDateSupplier, Runnable dateSetter) {/*from w w w .ja v a 2 s . c om*/ Optional<LocalDate> appLastOpenedDate = currentDateSupplier.get(); if (!appLastOpenedDate.isPresent() || appLastOpenedDate.get().isBefore(now)) { dateSetter.run(); } }
From source file:com.haulmont.cuba.client.sys.FileLoaderClientImpl.java
protected void saveStreamLocally(FileDescriptor fd, Supplier<InputStream> inputStream) throws FileStorageException { // cannot be injected since there is no implementation for Desktop LocalFileExchangeService localFileExchangeService = AppBeans.get(LocalFileExchangeService.NAME); localFileExchangeService.uploadFile(inputStream.get(), fd); }
From source file:com.yahoo.elide.Elide.java
/** * Handle POST./*from w ww. j a v a 2 s . com*/ * * @param path the path * @param jsonApiDocument the json api document * @param opaqueUser the opaque user * @param securityMode only for test mode * @return Elide response object */ public ElideResponse post(String path, String jsonApiDocument, Object opaqueUser, SecurityMode securityMode) { try (DataStoreTransaction transaction = dataStore.beginTransaction()) { User user = transaction.accessUser(opaqueUser); JsonApiDocument doc = mapper.readJsonApiDocument(jsonApiDocument); RequestScope requestScope = new RequestScope(doc, transaction, user, dictionary, mapper, auditLogger, securityMode); PostVisitor visitor = new PostVisitor(requestScope); Supplier<Pair<Integer, JsonNode>> responder = visitor.visit(parse(path)); requestScope.runDeferredPermissionChecks(); transaction.flush(); ElideResponse response = buildResponse(responder.get()); auditLogger.commit(); transaction.commit(); requestScope.runCommitTriggers(); return response; } catch (HttpStatusException e) { return buildErrorResponse(e, securityMode); } catch (IOException e) { return buildErrorResponse(new TransactionException(e), securityMode); } catch (ParseCancellationException e) { return buildErrorResponse(new InvalidURLException(e), securityMode); } }
From source file:com.epam.dlab.backendapi.dao.BaseDAO.java
/** * Inserts the document into the collection with given the unique id. * * @param collection collection name.//from w w w. j av a 2 s . c o m * @param document document. * @param uuid unique id. */ protected void insertOne(String collection, Supplier<Document> document, String uuid) { try { mongoService.getCollection(collection) .insertOne(document.get().append(ID, uuid).append(TIMESTAMP, new Date())); } catch (MongoException e) { LOGGER.warn("Insert to Mongo DB fails: {}", e.getLocalizedMessage(), e); throw new DlabException("Insert to Mongo DB failed: " + e.getLocalizedMessage(), e); } }
From source file:com.yahoo.elide.Elide.java
/** * Handle GET./* w ww. j av a2 s . c o m*/ * * @param path the path * @param queryParams the query params * @param opaqueUser the opaque user * @param securityMode only for test mode * @return Elide response object */ public ElideResponse get(String path, MultivaluedMap<String, String> queryParams, Object opaqueUser, SecurityMode securityMode) { try (DataStoreTransaction transaction = dataStore.beginReadTransaction()) { final User user = transaction.accessUser(opaqueUser); RequestScope requestScope = new RequestScope(new JsonApiDocument(), transaction, user, dictionary, mapper, auditLogger, queryParams, securityMode); GetVisitor visitor = new GetVisitor(requestScope); Supplier<Pair<Integer, JsonNode>> responder = visitor.visit(parse(path)); requestScope.runDeferredPermissionChecks(); transaction.flush(); ElideResponse response = buildResponse(responder.get()); auditLogger.commit(); transaction.commit(); requestScope.runCommitTriggers(); return response; } catch (HttpStatusException e) { return buildErrorResponse(e, securityMode); } catch (IOException e) { return buildErrorResponse(new TransactionException(e), securityMode); } catch (ParseCancellationException e) { return buildErrorResponse(new InvalidURLException(e), securityMode); } }
From source file:com.yahoo.elide.Elide.java
/** * Handle DELETE.// w w w .ja v a2s . c om * * @param path the path * @param jsonApiDocument the json api document * @param opaqueUser the opaque user * @param securityMode only for test mode * @return Elide response object */ public ElideResponse delete(String path, String jsonApiDocument, Object opaqueUser, SecurityMode securityMode) { JsonApiDocument doc; try (DataStoreTransaction transaction = dataStore.beginTransaction()) { User user = transaction.accessUser(opaqueUser); if (jsonApiDocument != null && !jsonApiDocument.equals("")) { doc = mapper.readJsonApiDocument(jsonApiDocument); } else { doc = new JsonApiDocument(); } RequestScope requestScope = new RequestScope(doc, transaction, user, dictionary, mapper, auditLogger, securityMode); DeleteVisitor visitor = new DeleteVisitor(requestScope); Supplier<Pair<Integer, JsonNode>> responder = visitor.visit(parse(path)); requestScope.runDeferredPermissionChecks(); transaction.flush(); ElideResponse response = buildResponse(responder.get()); auditLogger.commit(); transaction.commit(); requestScope.runCommitTriggers(); return response; } catch (HttpStatusException e) { return buildErrorResponse(e, securityMode); } catch (IOException e) { return buildErrorResponse(new TransactionException(e), securityMode); } catch (ParseCancellationException e) { return buildErrorResponse(new InvalidURLException(e), securityMode); } }
From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java
private TextField createIntegerInputField(final TextField textInput, final Supplier<Integer> getter, final Consumer<Integer> setter) { final TextField integerInput = new TextField(getter.get() == null ? "" : String.valueOf(getter.get())); integerInput.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> { if (!newValue.matches("\\d*")) { integerInput.setText(newValue.replaceAll("[^\\d]", "")); newValue = textInput.getText(); }// ww w . j a v a 2 s . co m if (StringUtils.isNotBlank(newValue)) { try { setter.accept(Integer.parseInt(newValue)); } catch (final NumberFormatException nfe) { // This can only happen if the value is "too long" / too high for "int" integerInput.setText(String.valueOf(Integer.MAX_VALUE)); setter.accept(Integer.MAX_VALUE); } } else { setter.accept(null); } this.setChanged(true); }); final double maxWidthOfIntegerInput = 80d; integerInput.setMaxWidth(maxWidthOfIntegerInput); return integerInput; }
From source file:pt.sapo.pai.vip.VipServlet.java
private void processRequest(HttpServletRequest request, HttpServletResponse response, Supplier<HttpRequestBase> supplier) throws ServletException, IOException { try (OutputStream out = response.getOutputStream(); CloseableHttpClient http = builder.build()) { Optional.ofNullable(servers[rand.nextInt(2)]).map(server -> server.split(":")) .map(parts -> Tuple.of(parts[0], Integer.valueOf(parts[1]))).ifPresent(server -> { try { HttpRequestBase method = supplier.get(); method.setURI(new URI(request.getScheme(), null, server._1, server._2, request.getRequestURI(), request.getQueryString(), null)); HttpResponse rsp = http.execute(method); Collections.list(request.getHeaderNames()) .forEach(name -> Collections.list(request.getHeaders(name)) .forEach(value -> method.setHeader(name, value))); response.setStatus(rsp.getStatusLine().getStatusCode()); response.setContentType(rsp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()); IOUtils.copy(rsp.getEntity().getContent(), out); } catch (IOException | URISyntaxException ex) { log.error(null, ex); }/*w ww.j a va 2 s . co m*/ }); } }
From source file:com.liferay.wiki.util.WikiCacheHelper.java
public WikiPageDisplay getDisplay(long nodeId, String title, PortletURL viewPageURL, Supplier<PortletURL> editPageURLSupplier, String attachmentURLPrefix) { StopWatch stopWatch = new StopWatch(); stopWatch.start();/* w w w . ja v a 2 s .c o m*/ String key = _encodeKey(nodeId, title, viewPageURL.toString()); WikiPageDisplay pageDisplay = (WikiPageDisplay) _portalCache.get(key); if (pageDisplay == null) { pageDisplay = _getPageDisplay(nodeId, title, viewPageURL, editPageURLSupplier.get(), attachmentURLPrefix); if (pageDisplay != null) { PortalCacheHelperUtil.putWithoutReplicator(_portalCache, key, pageDisplay); } } if (_log.isDebugEnabled()) { _log.debug(StringBundler.concat("getDisplay for {", String.valueOf(nodeId), ", ", title, ", ", String.valueOf(viewPageURL), ", ", String.valueOf(editPageURLSupplier.get()), "} takes ", String.valueOf(stopWatch.getTime()), " ms")); } return pageDisplay; }