List of usage examples for java.util Optional get
public T get()
From source file:de.Keyle.MyPet.util.Updater.java
public void update() { if (Configuration.Update.CHECK) { Optional<Update> update = check(); if (update.isPresent()) { latest = update.get(); notifyVersion();//from w w w . j a v a 2s.c o m if (Configuration.Update.DOWNLOAD) { download(); } } } }
From source file:ch.wisv.areafiftylan.extras.consumption.service.ConsumptionServiceImpl.java
@Override public ConsumptionMap getByTicketIdIfValid(Long ticketId) { if (!ticketService.getTicketById(ticketId).isValid()) { throw new InvalidTicketException("Ticket is invalid; It can not be used for consumptions."); }/*from w w w . j a v a 2 s . c o m*/ Optional<ConsumptionMap> mapOptional = consumptionMapsRepository.findByTicketId(ticketId); if (mapOptional.isPresent()) { return mapOptional.get(); } else { return initializeConsumptionMap(ticketId); } }
From source file:io.gravitee.management.service.impl.UserServiceImpl.java
@Override public UserEntity findByName(String username) { try {/*from w ww .ja v a 2 s . c o m*/ LOGGER.debug("Find user by name: {}", username); Optional<User> user = userRepository.findByUsername(username); if (user.isPresent()) { return convert(user.get()); } throw new UserNotFoundException(username); } catch (TechnicalException ex) { LOGGER.error("An error occurs while trying to find a user using its name {}", username, ex); throw new TechnicalManagementException( "An error occurs while trying to find a user using its name " + username, ex); } }
From source file:io.apiman.cli.PluginTest.java
/** * @return the plugin expected to have been added * @throws java.io.IOException/*w w w. jav a 2 s .co m*/ */ @NotNull private Plugin getPlugin() throws java.io.IOException { // fetch all plugins final Response response = given().log().all() .header(AuthUtil.HEADER_AUTHORIZATION, AuthUtil.BASIC_AUTH_VALUE).when().get("/plugins") .thenReturn(); assertEquals(HttpURLConnection.HTTP_OK, response.statusCode()); @SuppressWarnings("unchecked") final List<Plugin> plugins = MappingUtil.JSON_MAPPER.readValue(response.body().asByteArray(), new TypeReference<List<Plugin>>() { }); assertNotNull(plugins); assertTrue("At least one plugin should be installed", plugins.size() > 0); // find the expected plugin final Optional<Plugin> addedPlugin = plugins.stream().filter(this::isArtifactMatch).findAny(); assertTrue(addedPlugin.isPresent()); return addedPlugin.get(); }
From source file:com.todo.backend.security.JWTFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { try {/*from w w w . j a v a 2 s. c om*/ final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; final Optional<String> jwtToken = extractToken(httpServletRequest); if (jwtToken.isPresent()) { final Authentication authentication = JWTUtils.getAuthentication(jwtToken.get(), secretKey); SecurityContextHolder.getContext().setAuthentication(authentication); } filterChain.doFilter(servletRequest, servletResponse); } catch (ExpiredJwtException e) { log.debug("Security exception for user {} - {}. Expired token.", e.getClaims().getSubject(), e.getMessage()); ((HttpServletResponse) servletResponse).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication token expired!"); } catch (JwtException e) { log.debug("Authentication token is invalid. {}", e.getMessage()); ((HttpServletResponse) servletResponse).sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication token is invalid!"); } }
From source file:gndata.lib.srv.LocalFileTest.java
@Test public void testGetParent() throws Exception { Optional<LocalFile> currParent = localFile.getParent(); assertThat(currParent.isPresent());/*from w ww .j a va 2 s . c o m*/ assertThat(currParent.get().hasPath(testFileFolder)); }
From source file:org.camunda.bpm.spring.boot.starter.configuration.impl.custom.EnterLicenseKeyConfigurationTest.java
private void readLicenseKeyFromDataSource(DataSource dataSource, EnterLicenseKeyConfiguration enterLicenseKeyConfiguration) throws SQLException { try (Connection connection = dataSource.getConnection()) { Optional<String> keyFromDatasource = enterLicenseKeyConfiguration .readLicenseKeyFromDatasource(connection); assertThat(keyFromDatasource.get()).isNotNull().startsWith("1234567890").endsWith("Github;unlimited") .doesNotContain("\n"); }/* w ww . j a v a2 s .co m*/ }
From source file:com.galenframework.storage.controllers.api.PageApiController.java
private Page findOrCreatePage(Long projectId, String pageName) { Optional<Page> page = pageRepository.findPage(projectId, pageName); if (page.isPresent()) { return page.get(); } else {/*w w w . j av a 2s.c o m*/ Page p = new Page(pageName); p.setProjectId(projectId); Long pageId = pageRepository.createPage(p); p.setPageId(pageId); return p; } }
From source file:com.devicehive.dao.rdbms.UserDaoRdbmsImpl.java
private Optional<UserVO> optionalUserConvertToVo(Optional<User> login) { if (login.isPresent()) { return Optional.ofNullable(User.convertToVo(login.get())); }/* w w w . j a v a2 s . c om*/ return Optional.empty(); }
From source file:org.trustedanalytics.servicebroker.hbase.integration.HbaseBrokerTest.java
@Test public void testCreateInstanceBinding_success_shouldStoreInstanceBindingDataInBrokerStore() throws Exception { ServiceInstance instance = getServiceInstance("instanceId3", "fake-bare-plan"); instanceService.createServiceInstance(getCreateInstanceRequest(instance)); CreateServiceInstanceBindingRequest request = getCreateBindingRequest("instanceId3") .withBindingId("bindingId2"); bindingService.createServiceInstanceBinding(request); Optional<CreateServiceInstanceBindingRequest> bindingInstance = bindingBrokerStore .getById(Location.newInstance("bindingId2", "instanceId3")); assertThat(bindingInstance.get().getAppGuid(), equalTo(request.getAppGuid())); assertThat(bindingInstance.get().getServiceDefinitionId(), equalTo(request.getServiceDefinitionId())); assertThat(bindingInstance.get().getPlanId(), equalTo(request.getPlanId())); }