List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderMetadata.java
@ExtDirectMethod(value = ExtDirectMethodType.STORE_READ, group = "metadata") public List<Row> method4(@MetadataParam(value = "id") Optional<Integer> id) { if (!id.isPresent()) { assertThat(id.orElse(null)).isNull(); } else {//from ww w .j a v a2 s . com assertThat(id.get()).isEqualTo(Integer.valueOf(13)); } return RemoteProviderStoreRead.createRows(":" + id); }
From source file:de.sainth.recipe.backend.rest.controller.LogoutController.java
@RequestMapping() @ResponseStatus(HttpStatus.NO_CONTENT)//from w w w . ja v a 2s . c o m void logout(HttpServletRequest request, HttpServletResponse response) { if ("/logout".equals(request.getServletPath())) { Optional<Cookie> cookie = Arrays.stream(request.getCookies()) .filter(c -> "recipe_bearer".equals(c.getName())).findFirst(); if (cookie.isPresent()) { Cookie c = cookie.get(); c.setValue(""); c.setPath("/"); c.setMaxAge(0); response.addCookie(c); } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } }
From source file:org.ameba.aop.IntegrationLayerAspect.java
/** * Called after an exception is thrown by classes of the integration layer. <p> Set log level to ERROR to log the root cause. </p> * * @param ex The root exception that is thrown * @return Returns the exception to be thrown *///from w w w.j a v a 2 s.c o m public Exception translateException(Exception ex) { if (EXC_LOGGER.isErrorEnabled()) { EXC_LOGGER.error(ex.getLocalizedMessage(), ex); } if (ex instanceof BusinessRuntimeException) { return ex; } Optional<Exception> handledException = doTranslateException(ex); if (handledException.isPresent()) { return handledException.get(); } if (ex instanceof DuplicateKeyException) { return new ResourceExistsException(); } if (ex instanceof IntegrationLayerException) { return ex; } return withRootCause ? new IntegrationLayerException(ex.getMessage(), ex) : new IntegrationLayerException(ex.getMessage()); }
From source file:com.nike.cerberus.operation.vault.EnableAuditBackendOperation.java
@Override public void run(final EnableAuditBackendCommand command) { logger.info("Getting client for Vault leader."); final Optional<VaultAdminClient> client = vaultAdminClientFactory.getClientForLeader(); if (client.isPresent()) { Map<String, String> options = Maps.newHashMap(); switch (command.getAuditBackend()) { case FILE: options = getFileOptions(command.getFilePath().toString()); break; case SYSLOG: options = getSyslogOptions(); break; }//from w ww.java 2 s . c o m final VaultEnableAuditBackendRequest request = new VaultEnableAuditBackendRequest() .setType(command.getAuditBackend().getType()) .setDescription("Cerberus configured audit backend.").setOptions(options); logger.info("Enabling the audit backend in Vault."); client.get().enableAuditBackend(command.getAuditBackend().getType(), request); logger.info("Audit enabled."); } else { throw new IllegalStateException("Unable to determine Vault leader, aborting..."); } }
From source file:me.adaptive.che.infrastructure.vfs.WorkspaceIdLocalFSMountStrategy.java
@Override public File getMountPath(String workspaceId) throws ServerException { checkRoot();//from w w w .j a va 2 s . co m Optional<WorkspaceEntity> optional = workspaceEntityService.findByWorkspaceId(workspaceId); if (!optional.isPresent()) { throw new ServerException(String.format("Workspace %s does not exist", workspaceId)); } return getMountPath(optional.get()); }
From source file:com.teradata.benchto.driver.execution.ExecutionDriver.java
private void executeHealthCheck(Benchmark benchmark) { Optional<List<String>> macros = properties.getHealthCheckMacros(); if (macros.isPresent()) { LOG.info("Running health check macros: {}", macros.get()); macroService.runBenchmarkMacros(macros.get(), benchmark); }/* w ww . j av a 2 s.c om*/ }
From source file:com.teradata.tempto.internal.hadoop.hdfs.HdfsModuleProvider.java
@Override public Module getModule(Configuration configuration) { return new PrivateModule() { @Override//w w w . j a va 2 s .c o m protected void configure() { install(httpRequestsExecutorModule()); bind(HdfsClient.class).to(WebHdfsClient.class).in(Scopes.SINGLETON); bind(RevisionStorage.class).toProvider(RevisionStorageProvider.class).in(Scopes.SINGLETON); bind(HdfsDataSourceWriter.class).to(DefaultHdfsDataSourceWriter.class).in(Scopes.SINGLETON); expose(HdfsClient.class); expose(RevisionStorage.class); expose(HdfsDataSourceWriter.class); } private Module httpRequestsExecutorModule() { if (spnegoAuthenticationRequired()) { return new SpnegoHttpRequestsExecutor.Module(); } else { return new SimpleHttpRequestsExecutor.Module(); } } private boolean spnegoAuthenticationRequired() { Optional<String> authentication = configuration.getString("hdfs.webhdfs.authentication"); return authentication.isPresent() && authentication.get().equalsIgnoreCase(AUTHENTICATION_SPNEGO); } @Inject @Provides @Singleton CloseableHttpClient createHttpClient() { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(NUMBER_OF_HTTP_RETRIES, true)); return httpClientBuilder.build(); } }; }
From source file:com.linksinnovation.elearning.controller.api.WishlistController.java
@RequestMapping(method = RequestMethod.POST) public boolean add(@RequestBody Map<String, Object> params, @AuthenticationPrincipal String username) { UserDetails userDetails = userDetailsRepository.findOne(username.toUpperCase()); Course course = courseRepositroy.findOne(new Long(params.get("id").toString())); Optional<Wishlist> optional = wishlistRepository.findByUserAndCourse(userDetails, course); Wishlist wishlist;/*from w w w . j av a 2 s. c om*/ if (optional.isPresent()) { wishlistRepository.delete(optional.get()); } else { wishlist = new Wishlist(); wishlist.setUser(userDetails); wishlist.setCourse(course); wishlistRepository.save(wishlist); } return true; }
From source file:example.springdata.jpa.java8.Java8IntegrationTests.java
@Test public void invokesDefaultMethod() { Customer customer = repository.save(new Customer("Dave", "Matthews")); Optional<Customer> result = repository.findByLastname(customer); assertThat(result.isPresent(), is(true)); assertThat(result.get(), is(customer)); }