List of usage examples for java.util Optional get
public T get()
From source file:com.rockagen.gnext.test.BaseTest.java
protected void newUser() throws RegisterException { AuthUserBO bo = new AuthUserBO(); bo.setName("test user"); bo.setUid("test"); bo.setEmail("test@localhost.com"); bo.setPhone("15100000000"); bo.setAddress("USA"); bo.setCreateUserReferer(UserReferer.LOCAL); bo.setType(UserType.GUEST);//from ww w .j a va2 s. c om bo.setPassword("test"); authUserServ.signup(bo); Optional<AuthUser> u = authUserServ.load(uid); if (u.isPresent()) { user = u.get(); } else { fail("user not exist!"); } }
From source file:bg.vitkinov.edu.services.JokeCategoryService.java
private List<KeyWord> getKewWors(String keywords) { String[] words = keywords.split(","); List<KeyWord> result = new ArrayList<>(words.length); for (String word : words) { Optional<KeyWord> keyword = keyWordRepository.findByName(word); if (keyword.isPresent()) { result.add(keyword.get()); } else {/*from w w w. ja va2 s .c o m*/ result.add(keyWordRepository.save(new KeyWord(word))); } } return result; }
From source file:com.rockagen.gnext.test.BaseTest.java
protected void newAccount() throws RegisterException { accountServ.newAccount(uid, AccountType.INDIVIDUAL); Optional<Account> acc = accountServ.loadByUid(uid); if (acc.isPresent()) { account = acc.get(); accountId = account.getId();// w ww . j av a 2s . c om } else { fail("account not exist!"); } }
From source file:com.wms.multitenant.tenant.interceptor.TenantIdentifierInterceptorAdapter.java
@Override public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception { Map<String, Object> pathVars = (Map<String, Object>) req .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); if (pathVars.containsKey("tenantId")) { String tenantId = pathVars.get("tenantId").toString(); Optional<Tenant> thisTenant = tenantRepo.findByTenantKey(tenantId); if (thisTenant.isPresent()) { req.setAttribute("Current_Tenant", thisTenant.get().getTenantKey()); return true; } else {/*from www . j a va 2 s . c om*/ res.sendRedirect(req.getContextPath() + "/signUp"); return false; } } else { return true; } }
From source file:eu.jasha.demo.sbtfragments.CityController.java
@RequestMapping(value = PATH_ID, method = GET) public String showUpdateCityPage(@PathVariable(ID) String id, ModelMap modelMap) { Optional<City> city = cityDao.find(id); modelMap.addAttribute(MODEL_ATTRIBUTE_CITY, city.get()); return VIEW_CITY_FORM; }
From source file:org.openmhealth.shim.fitbit.mapper.FitbitBodyMassIndexDataPointMapper.java
@Override protected Optional<DataPoint<BodyMassIndex>> asDataPoint(JsonNode node) { TypedUnitValue<BodyMassIndexUnit> bmiValue = new TypedUnitValue<>(KILOGRAMS_PER_SQUARE_METER, asRequiredDouble(node, "bmi")); BodyMassIndex.Builder builder = new BodyMassIndex.Builder(bmiValue); Optional<OffsetDateTime> dateTime = combineDateTimeAndTimezone(node); if (dateTime.isPresent()) { builder.setEffectiveTimeFrame(dateTime.get()); }//from w w w. j a v a 2s . c o m Optional<Long> externalId = asOptionalLong(node, "logId"); return Optional.of(newDataPoint(builder.build(), externalId.orElse(null))); }
From source file:eu.jasha.demo.sbtfragments.CityController.java
@RequestMapping(value = PATH_ID + "/delete", method = GET) public String showDeleteCityPage(@PathVariable(ID) String id, ModelMap modelMap) { Optional<City> city = cityDao.find(id); modelMap.addAttribute(MODEL_ATTRIBUTE_CITY, city.get()); return VIEW_CITY_DELETE; }
From source file:com.macrossx.wechat.impl.WechatMessageHelper.java
@Override public Optional<WecahtMessageTemplateRespObj> sendTemplate(WechatMessageTemplate template) { try {/*from w w w. ja v a 2 s. c om*/ Optional<WechatAccessToken> token = wechatHelper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpPost httpPost = new HttpPost(); System.out.println(new Gson().toJson(template)); httpPost.setEntity(new StringEntity(new Gson().toJson(template), "utf-8")); httpPost.setURI(new URI(MessageFormat.format(WechatConstants.MESSAGE_TEMPLATE_SEND_URL, accessToken.getAccess_token()))); return new WechatHttpClient().send(httpPost, WecahtMessageTemplateRespObj.class); } } catch (URISyntaxException e) { log.info(e.getMessage()); } return Optional.empty(); }
From source file:org.openmhealth.dsu.repository.EndUserRepositoryIntegrationTests.java
@Test public void findOneShouldReturnSavedUser() { EndUser expected = endUserRepository.save(newUser()); Optional<EndUser> actual = endUserRepository.findOne(TEST_USERNAME); assertThat(actual.isPresent(), equalTo(true)); assertThat(actual.get(), equalTo(expected)); }
From source file:com.properned.application.LocaleListCell.java
private MenuItem getDeleteMenu(Locale locale) { MenuItem deleteMenu = new MenuItem(MessageReader.getInstance().getMessage("action.deleteMessageKey")); deleteMenu.setOnAction(new EventHandler<ActionEvent>() { @Override/*from w w w . ja v a 2 s . c om*/ public void handle(ActionEvent event) { logger.info("Clic on delete button for locale '" + locale.toString() + "'"); String fileName = properties.getMapPropertiesFileByLocale().get(locale).getAbsolutePath(); Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.title")); alert.setHeaderText(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.header")); alert.setContentText( MessageReader.getInstance().getMessage("manageLocale.confirmDelete.content", fileName)); Optional<ButtonType> result = alert.showAndWait(); if (result.isPresent() && result.get() == ButtonType.OK) { logger.info("User say OK to the confirm"); properties.deleteLocale(locale); // Reload list controller.initializeList(); } } }); if (properties.getMapPropertiesByLocale().keySet().size() <= 1) { // We can delete only if there is more than the current locale deleteMenu.setDisable(true); } return deleteMenu; }