List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:io.kamax.mxisd.lookup.provider.BridgeFetcher.java
@Override public Optional<SingleLookupReply> find(SingleLookupRequest request) { Optional<String> mediumUrl = Optional.ofNullable(cfg.getMappings().get(request.getType())); if (mediumUrl.isPresent() && !StringUtils.isBlank(mediumUrl.get())) { log.info("Using specific medium bridge lookup URL {}", mediumUrl.get()); return fetcher.find(mediumUrl.get(), request); } else if (!StringUtils.isBlank(cfg.getServer())) { log.info("Using generic bridge lookup URL {}", cfg.getServer()); return fetcher.find(cfg.getServer(), request); } else {/*from w w w . j ava 2 s . c om*/ log.info("No bridge lookup URL found/configured, skipping"); return Optional.empty(); } }
From source file:org.obiba.mica.micaConfig.rest.DataAccessResource.java
@GET @Path("/pdf") public FileResource getDataAccessPdf(@QueryParam("lang") String lang) { Optional<DataAccessForm> d = dataAccessFormService.find(); if (!d.isPresent()) throw NoSuchDataAccessFormException.withDefaultMessage(); DataAccessForm dataAccessForm = d.get(); Locale locale = Locale .forLanguageTag(!Strings.isNullOrEmpty(lang) ? Locale.forLanguageTag(lang).toLanguageTag() : LanguageTag.UNDETERMINED); if (!dataAccessForm.getPdfTemplates().containsKey(locale)) throw NoSuchDataAccessFormException.withDefaultMessage(); fileResource.setAttachment(dataAccessForm.getPdfTemplates().get(locale)); return fileResource; }
From source file:org.onebusaway.alexa.MainSpeechlet.java
public SpeechletResponse onIntent(final IntentRequest request, final Session session) throws SpeechletException { try {/*from www . j a va 2 s .c o m*/ Optional<ObaUserDataItem> optUserData = obaDao.getUserData(session); if (optUserData.isPresent()) { return getAuthedSpeechlet(optUserData.get()).onIntent(request, session); } else { return anonSpeechlet.onIntent(request, session); } } catch (URISyntaxException e) { log.error("Intent exception: " + e.getMessage()); log.error("Backtrace:\n" + e.getStackTrace()); throw new SpeechletException("Error creating user data on Intent using ObaBaseUrl: " + e); } catch (Exception e) { log.error("Intent exception: " + e.getMessage()); log.error("Backtrace:\n" + e.getStackTrace()); throw e; } }
From source file:net.sf.jabref.logic.fulltext.SpringerLink.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { // Available in catalog? try {//from w w w . j a v a2 s .c o m HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL).queryString("api_key", API_KEY) .queryString("q", String.format("doi:%s", doi.get().getDOI())).asJson(); JSONObject json = jsonResponse.getBody().getObject(); int results = json.getJSONArray("result").getJSONObject(0).getInt("total"); if (results > 0) { LOGGER.info("Fulltext PDF found @ Springer."); pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI()))); } } catch (UnirestException e) { LOGGER.warn("SpringerLink API request failed", e); } } return pdfLink; }
From source file:org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory.java
@Override public SolrHttpClientBuilder getHttpClientBuilder(Optional<SolrHttpClientBuilder> builder) { return builder.isPresent() ? initHttpClientBuilder(builder.get()) : initHttpClientBuilder(SolrHttpClientBuilder.create()); }
From source file:com.github.dmyersturnbull.transformations.DataTransformationRunner.java
public void run(@Nonnull String... args) throws Exception { m_helper.addOptions(new Option("i", "input", true, "The input file"), new Option("o", "output", true, "The output file")); Optional<ExtendedCommandLine> response = m_helper.parse(args); if (response.isPresent()) { ExtendedCommandLine cli = response.get(); Optional<File> input = cli.getFile("i"); Optional<File> output = cli.getFile("o"); if (input.isPresent() ^ output.isPresent()) { m_helper.printHelp();//w w w.ja v a2 s.c o m } else if (!input.isPresent()) { m_constructor.construct(cli).pipe(); } else { m_constructor.construct(cli).apply(input.get(), output.get()); } } }
From source file:it.polimi.diceH2020.launcher.service.Validator.java
public boolean validatePublicCloudParameters(Path pathToFile) { Optional<PublicCloudParametersMap> sol = objectFromPath(pathToFile, PublicCloudParametersMap.class); return (sol.isPresent() && sol.get().validate()); }
From source file:net.sf.jabref.logic.fetcher.DoiResolution.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); Optional<DOI> doi = DOI.build(entry.getField("doi")); if (doi.isPresent()) { String sciLink = doi.get().getURLAsASCIIString(); // follow all redirects and scan for a single pdf link if (!sciLink.isEmpty()) { try { Connection connection = Jsoup.connect(sciLink); connection.followRedirects(true); connection.ignoreHttpErrors(true); // some publishers are quite slow (default is 3s) connection.timeout(5000); Document html = connection.get(); // scan for PDF Elements elements = html.body().select("[href]"); List<Optional<URL>> links = new ArrayList<>(); for (Element element : elements) { String href = element.attr("abs:href"); // Only check if pdf is included in the link // See https://github.com/lehner/LocalCopy for scrape ideas if (href.contains("pdf") && MimeTypeDetector.isPdfContentType(href)) { links.add(Optional.of(new URL(href))); }//from w ww. j a va2 s . co m } // return if only one link was found (high accuracy) if (links.size() == 1) { LOGGER.info("Fulltext PDF found @ " + sciLink); pdfLink = links.get(0); } } catch (IOException e) { LOGGER.warn("DoiResolution fetcher failed: ", e); } } } return pdfLink; }
From source file:com.gtp.tradeapp.rest.UserController.java
@RequestMapping(value = "/password/reset", method = RequestMethod.POST) public Status resetPassword(@RequestParam("email") String email) { LOGGER.debug("Resetting password for username={}" + email); Optional<User> user = userService.getUserByEmail(email); if (user.isPresent()) { return updatePasswordAndSendTo(user.get()); }//from w w w.ja v a2 s .c om return new Status(0, "Unable to reset password for " + email); }
From source file:com.linksinnovation.elearning.controller.api.ViewerController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public void get(@PathVariable("id") Long id, @AuthenticationPrincipal String username) { Lecture lecture = lectureRepository.findOne(id); UserDetails userDetails = userDetailsRepository.findOne(username); Optional<Viewer> viOptional = viewerRepository.findByLectureAndUser(lecture, userDetails); Viewer viewer;/*from w ww . jav a 2 s.c o m*/ if (viOptional.isPresent()) { viewer = viOptional.get(); viewer.setUpdateDate(new Date()); } else { viewer = new Viewer(); viewer.setLecture(lecture); viewer.setUser(userDetails); viewer.setUpdateDate(new Date()); } viewerRepository.save(viewer); }