List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:net.sf.jabref.logic.fetcher.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 = DOI.build(entry.getField("doi")); if (doi.isPresent()) { // Available in catalog? try {/*w w w. j a v a 2s. c om*/ 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:com.formkiq.core.form.bean.CustomConvertUtilsBean.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from w ww. j av a2 s . c om*/ public Object convert(final String value, final Class clazz) { if (clazz.isEnum()) { String val = Strings.extractLabelAndValue(value).getRight(); try { Method method = clazz.getMethod("find", String.class); Object result = method.invoke(method, val); if (result instanceof Optional) { Optional<Object> op = (Optional<Object>) result; if (op.isPresent()) { return op.get(); } } } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // ignore error } return Enum.valueOf(clazz, val); } return super.convert(value, clazz); }
From source file:bg.vitkinov.edu.services.JokeCategoryService.java
@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT }) public ResponseEntity<?> insert(@RequestParam String name, @RequestParam String keywords) { Optional<Category> category = repository.findByName(name); if (category.isPresent()) { return new ResponseEntity<>(category.get(), HttpStatus.CONFLICT); }/*w w w. j a v a 2 s. c o m*/ Category newCateogry = new Category(); newCateogry.setName(name); newCateogry.setKeyWords(getKewWors(keywords)); return new ResponseEntity<>(repository.save(newCateogry), HttpStatus.CREATED); }
From source file:ddf.security.impl.SubjectIdentityImpl.java
/** * Get a subject's unique identifier. 1. If the configured unique identifier if present 2. Email * address if present 3. Username not, user name is returned. * * @param subject// ww w . j av a2 s . c om * @return subject unique identifier */ @Override public String getUniqueIdentifier(Subject subject) { Optional<String> owner = getSubjectAttribute(subject).stream().findFirst(); if (owner.isPresent()) { return owner.get(); } String identifier = SubjectUtils.getEmailAddress(subject); if (StringUtils.isNotBlank(identifier)) { return identifier; } return SubjectUtils.getName(subject); }
From source file:com.macrossx.wechat.impl.WechatUserHelper.java
public Optional<WechatUserGet> userGet(String nextOpenid) { try {/*w w w . j a v a 2s. co m*/ Optional<WechatAccessToken> token = helper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpGet httpGet = new HttpGet(); httpGet.setURI(new URI(MessageFormat.format(WechatConstants.USER_GET_URL, accessToken.getAccess_token(), nextOpenid == null ? "" : nextOpenid))); return new WechatHttpClient().send(httpGet, WechatUserGet.class); } } catch (URISyntaxException e) { // TODO Auto-generated catch block log.info(e.getMessage()); } return Optional.empty(); }
From source file:com.macrossx.wechat.impl.WechatUserHelper.java
public Optional<WechatUserInfo> userInfo(String openid) { try {//from w w w . j a v a2s .c om Optional<WechatAccessToken> token = helper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpGet httpGet = new HttpGet(); httpGet.setURI(new URI(MessageFormat.format(WechatConstants.USER_INFO_URL, accessToken.getAccess_token(), openid))); return new WechatHttpClient().send(httpGet, WechatUserInfo.class); } } catch (URISyntaxException e) { // TODO Auto-generated catch block log.info(e.getMessage()); } return Optional.empty(); }
From source file:com.teradata.benchto.service.EnvironmentService.java
@Retryable(value = { TransientDataAccessException.class, DataIntegrityViolationException.class }) @Transactional//from ww w . jav a2 s . co m public void storeEnvironment(String name, Map<String, String> attributes) { Optional<Environment> environmentOptional = tryFindEnvironment(name); if (!environmentOptional.isPresent()) { Environment environment = new Environment(); environment.setName(name); environment.setAttributes(attributes); environment.setStarted(currentDateTime()); environmentOptional = Optional.of(environmentRepo.save(environment)); } else { environmentOptional.get().setAttributes(attributes); } LOG.debug("Starting environment - {}", environmentOptional.get()); }
From source file:com.atlassian.connect.spring.internal.AtlassianConnectContextModelAttributeProvider.java
private Optional<String> getHostBaseUrl() { Optional<String> optionalBaseUrl = getHostBaseUrlFromPrincipal(); if (!optionalBaseUrl.isPresent()) { optionalBaseUrl = getHostBaseUrlFromQueryParameters(); }//from ww w. j a v a 2s . c o m return optionalBaseUrl; }
From source file:se.omegapoint.facepalm.application.UserService.java
public Result<UserSuccess, UserFailure> registerUser(final String username, final String email, final String firstname, final String lastname, final String password) { notBlank(username);//from www . j a v a 2 s.com notBlank(email); notBlank(firstname); notBlank(lastname); notBlank(password); final NewUserCredentials credentials = new NewUserCredentials(username, email, firstname, lastname, password); final Optional<User> user = getUser(credentials.username); if (user.isPresent()) { return Result.failure(USER_ALREADY_EXISTS); } userRepository.addUser(credentials); return Result.success(USER_REGISTERD); }
From source file:com.bodybuilding.argos.controller.TurbineStreamController.java
@RequestMapping("/turbine-stream/{cluster}") public ResponseEntity<SseEmitter> streamHystrix(@PathVariable("cluster") String cluster) { Optional<HystrixClusterMonitor> clusterMonitor = clusterRegistry.getCluster(cluster); if (!clusterMonitor.isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); }/*from w w w.jav a2 s .co m*/ final SseEmitter emitter = new SseEmitter(TimeUnit.DAYS.toMillis(45)); SseEmitterUtil.bindObservable(emitter, clusterMonitor.get().observeJson().takeUntil(shutdown).subscribeOn(Schedulers.io())); return ResponseEntity.ok(emitter); }