List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:org.openmhealth.shim.jawbone.mapper.JawboneBodyEventsDataPointMapper.java
/** * Handles some of the basic measure creation activities for body event datapoints and then delegates the creation * of the {@link Builder} to subclasses for each individual body event {@link Measure}. * * @param listEntryNode an individual entry node from the "items" array of a Jawbone endpoint response *///from ww w . jav a2s . c o m @Override protected Optional<T> getMeasure(JsonNode listEntryNode) { if (!containsType(listEntryNode, getBodyEventType())) { return Optional.empty(); } Optional<Measure.Builder<T, ?>> builderOptional = newMeasureBuilder(listEntryNode); if (!builderOptional.isPresent()) { return Optional.empty(); } Measure.Builder<T, ?> builder = builderOptional.get(); setEffectiveTimeFrame(builder, listEntryNode); Optional<String> optionalUserNote = asOptionalString(listEntryNode, "note"); optionalUserNote.ifPresent(builder::setUserNotes); return Optional.of(builder.build()); }
From source file:ch.sportchef.business.authentication.boundary.AuthenticationResource.java
@POST @Consumes({ MediaType.APPLICATION_JSON }) public Response authenticate(final DefaultLoginCredentials credential) { final Optional<String> token = authenticationService.validateChallenge(identity, credential); return token.isPresent() ? Response.ok(Entity.text(token.get())).build() : Response.status(Status.FORBIDDEN).build(); }
From source file:com.siemens.sw360.fossology.ssh.JSchSessionProvider.java
public Session getSession(int connectionTimeout) throws SW360Exception { Optional<Session> session = pollCachedSession(); if (session.isPresent()) { return session.get(); } else {// ww w .j a va 2 s .c o m return doGetSession(connectionTimeout); } }
From source file:org.apache.ambari.view.web.controller.PackageController.java
@GetMapping("/versions/{versionId}/config") public PackageWrapper.ApplicationConfigResponse getApplicationConfig( @PathVariable("versionId") Long versionId) { Optional<ApplicationConfig> applicationConfigOptional = service.getApplicationConfig(versionId); if (!applicationConfigOptional.isPresent()) { log.error("Configuration for package version id: {} not found", versionId); throw new RuntimeException("Package Version not found. Could not retrieve configuration."); }/*from www . j a va 2 s . c om*/ return new PackageWrapper.ApplicationConfigResponse(applicationConfigOptional.get()); }
From source file:com.arpnetworking.configuration.jackson.JsonNodePaginatedUrlSourceTest.java
@Test public void test() throws MalformedURLException { final WireMockServer server = new WireMockServer(0); server.start();//w w w . j a v a 2 s. com final WireMock wireMock = new WireMock(server.port()); wireMock.register(WireMock.get(WireMock.urlEqualTo("/animals?offset=0&limit=1")) .willReturn(WireMock.aResponse().withStatus(200) .withHeader("Content-Type", "application/json; charset=utf-8") .withBody("{\"metadata\":{\"next\":\"animals?offset=1&limit=1\"},\"data\":[\"cat\"]}"))); wireMock.register(WireMock.get(WireMock.urlEqualTo("/animals?offset=1&limit=1")) .willReturn(WireMock.aResponse().withStatus(200) .withHeader("Content-Type", "application/json; charset=utf-8") .withBody("{\"metadata\":{\"next\":\"animals?offset=2&limit=1\"},\"data\":[\"dog\"]}"))); wireMock.register(WireMock.get(WireMock.urlEqualTo("/animals?offset=2&limit=1")) .willReturn(WireMock.aResponse().withStatus(200) .withHeader("Content-Type", "application/json; charset=utf-8") .withBody("{\"metadata\":{\"next\":null},\"data\":[\"mouse\"]}"))); final JsonNodePaginatedUriSource jsonNodePaginatedUrlSource = new JsonNodePaginatedUriSource.Builder() .setUri(URI.create("http://localhost:" + server.port() + "/animals?offset=0&limit=1")) .setDataKeys(ImmutableList.of("data")).setNextPageKeys(ImmutableList.of("metadata", "next")) .build(); final Optional<JsonNode> jsonNode = jsonNodePaginatedUrlSource.getJsonNode(); Assert.assertTrue(jsonNode.isPresent()); Assert.assertTrue(jsonNode.get().isArray()); Assert.assertEquals(3, ((ArrayNode) jsonNode.get()).size()); Assert.assertEquals("cat", ((ArrayNode) jsonNode.get()).get(0).textValue()); Assert.assertEquals("dog", ((ArrayNode) jsonNode.get()).get(1).textValue()); Assert.assertEquals("mouse", ((ArrayNode) jsonNode.get()).get(2).textValue()); server.stop(); }
From source file:com.googlesource.gerrit.plugins.lfs.fs.LfsFsContentServlet.java
private void getObject(HttpServletRequest req, HttpServletResponse rsp, Optional<AnyLongObjectId> obj) throws IOException { if (obj.isPresent()) { AsyncContext context = req.startAsync(); context.setTimeout(timeout);// www. ja v a2 s .co m rsp.getOutputStream().setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj.get())); } }
From source file:com.ejisto.core.classloading.javassist.ObjectEditor.java
/** * Edits a field access replacing the code * with a call to {@link PropertyManager#mockField(String, String, String, Class, Object)}}. * * @param f the "fieldAccess"/* w w w. j a v a 2 s . co m*/ */ @Override public void edit(FieldAccess f) throws CannotCompileException { String fieldName = f.getFieldName(); if (shouldBeEdited(f, fieldName) && editFieldReader(f)) { CtClass clazz = f.getEnclosingClass(); final Optional<String> fieldMarker = getFieldMarker(fieldName); if (fieldMarker.isPresent()) { clazz.addField(CtField.make(format("private boolean %s = true;", fieldMarker.get()), clazz)); } } }
From source file:it.lic.cli.Main.java
private void run(final CommandLine cli) throws Exception { final Wallet wallet = new Wallet.Default(new FileStorage(new System.Default())); if (cli.hasOption("h")) { this.help(); } else if (cli.hasOption("l")) { final LicenseKeyPair lkp = wallet.licenseKeyPair(cli.getOptionValue("l")); java.lang.System.out.println(String.format("[%s] Public key: %s", lkp.name(), new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded())))); } else if (cli.hasOption("L")) { final Iterator<License> licenses = wallet.licenses(wallet.licenseKeyPair(cli.getOptionValue("L")), ""); while (licenses.hasNext()) { License current = licenses.next(); java.lang.System.out.println(String.format("%s\t%s\t%s\t%s", current.name(), current.issuer(), current.until(), current.encode())); }//ww w.j a v a 2 s .c o m } else if (cli.hasOption("k")) { final LicenseKeyPair lkp = wallet.newLicenseKeyPair(cli.getOptionValue("k")); java.lang.System.out.println(String.format("new keypair created: %s", new String(Base64.getEncoder().encode(lkp.publicKey().getEncoded())))); } else if (cli.hasOption("K")) { final Calendar expire = Calendar.getInstance(); expire.add(Calendar.YEAR, 1); Optional<License> license = wallet.hasLicenseFor(wallet.licenseKeyPair("prometeo"), cli.getOptionValue("K")); if (license.isPresent()) { java.lang.System.out.println(String.format("license already esists: %s", license.get().encode())); } else { final License newlicense = wallet.newLicense(cli.getOptionValue("K"), wallet.licenseKeyPair("prometeo"), cli.getOptionValue("K"), expire.getTime(), Collections.emptyMap()); java.lang.System.out.println(String.format("new license created: %s", newlicense.encode())); } } }
From source file:me.adaptive.core.data.api.WorkspaceMemberService.java
public WorkspaceMemberEntity toWorkspaceMemberEntity(Member member, Optional<WorkspaceMemberEntity> workspaceMemberEntity) { WorkspaceMemberEntity entity = workspaceMemberEntity.isPresent() ? workspaceMemberEntity.get() : new WorkspaceMemberEntity(); CollectionUtils.addAll(entity.getRoles(), member.getRoles().iterator()); entity.setUser(member.getUserId() == null ? null : userService.findByUserId(member.getUserId()).get()); entity.setWorkspace(member.getWorkspaceId() == null ? null : workspaceEntityService.findByWorkspaceId(member.getWorkspaceId()).get()); return entity; }
From source file:com.gtp.tradeapp.rest.TransactionController.java
private boolean validateIfEnoughCash(Transaction transaction) { Optional<User> userDao = userService.getUserById(transaction.getUserId()); if (userDao.isPresent()) { return userDao.get().getCash().compareTo(transaction.getTotal()) > 0; }/*from www . j a v a 2 s.c o m*/ return false; }