List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:password.pwm.http.servlet.oauth.OAuthMachine.java
public static Optional<OAuthRequestState> readOAuthRequestState(final PwmRequest pwmRequest) throws PwmUnrecoverableException { final String requestStateStr = pwmRequest .readParameterAsString(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_PARAM_OAUTH_STATE)); if (requestStateStr != null) { final String stateJson = pwmRequest.getPwmApplication().getSecureService() .decryptStringValue(requestStateStr); final OAuthState oAuthState = JsonUtil.deserialize(stateJson, OAuthState.class); if (oAuthState != null) { final boolean sessionMatch = oAuthState.getSessionID() .equals(pwmRequest.getPwmSession().getSessionStateBean().getSessionVerificationKey()); LOGGER.trace(pwmRequest, "read state while parsing oauth consumer request with match=" + sessionMatch + ", " + JsonUtil.serialize(oAuthState)); return Optional.of(new OAuthRequestState(oAuthState, sessionMatch)); }//from w ww . ja va2s . c o m } return Optional.empty(); }
From source file:com.nike.cerberus.security.CmsRequestSecurityValidator.java
public static Optional<SecurityContext> getSecurityContextForRequest(RequestInfo<?> requestInfo) { final Object securityContext = requestInfo.getRequestAttributes().get(SECURITY_CONTEXT_ATTR_KEY); if (securityContext == null) { return Optional.empty(); } else {//from w w w . j a va 2s . c o m return Optional.of((SecurityContext) securityContext); } }
From source file:com.teradata.tempto.fulfillment.hive.HiveTableDefinition.java
public static HiveTableDefinition hiveTableDefinition(String name, String createTableDDLTemplate, DataSource dataSource) {//from w ww .jav a 2s.c om return new HiveTableDefinition(name, createTableDDLTemplate, Optional.of(dataSource), Optional.empty()); }
From source file:com.epam.ta.reportportal.core.externalsystem.ExternalSystemEurekaDelegate.java
@Override public Optional<Ticket> getTicket(String id, ExternalSystem system) { return Optional.of(eurekaTemplate.getForObject( getServiceInstance(system.getExternalSystemType()).getUri().toString() + "/{systemId}/ticket/{id}", Ticket.class, system.getId(), id)); }
From source file:org.openmhealth.shim.misfit.mapper.MisfitStepCountDataPointMapper.java
@Override public Optional<DataPoint<StepCount>> asDataPoint(JsonNode summaryNode) { checkNotNull(summaryNode);/*w ww.ja v a 2 s . c o m*/ Long stepCount = asRequiredLong(summaryNode, "steps"); if (stepCount == 0) { return Optional.empty(); } StepCount.Builder builder = new StepCount.Builder(stepCount); // this property isn't listed in the table, but does appear in the second Example section where detail is true LocalDate localDate = asRequiredLocalDate(summaryNode, "date"); // FIXME fix the time zone offset once Misfit add it to the API OffsetDateTime startDateTime = localDate.atStartOfDay().atOffset(UTC); DurationUnitValue durationUnitValue = new DurationUnitValue(DAY, 1); builder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(startDateTime, durationUnitValue)); StepCount measure = builder.build(); return Optional.of(newDataPoint(measure, RESOURCE_API_SOURCE_NAME, null, null)); }
From source file:net.sf.jabref.logic.fulltext.ScienceDirect.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 = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { // Available in catalog? try {//from w ww. j av a 2 s . c o m String sciLink = getUrlByDoi(doi.get().getDOI()); if (!sciLink.isEmpty()) { // Retrieve PDF link Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get(); Element link = html.getElementById("pdfLink"); if (link != null) { LOGGER.info("Fulltext PDF found @ ScienceDirect."); pdfLink = Optional.of(new URL(link.attr("pdfurl"))); } } } catch (UnirestException e) { LOGGER.warn("ScienceDirect API request failed", e); } } return pdfLink; }
From source file:com.massabot.codesender.utils.FirmwareUtils.java
/** * Gets a list of command processors initialized with user settings. *///from w w w . j a v a 2 s .c o m public static Optional<List<ICommandProcessor>> getParserFor(String firmware, Settings settings) { if (!configFiles.containsKey(firmware)) { return Optional.empty(); } try { return Optional.of(configFiles.get(firmware).loader.getProcessors()); } catch (Exception e) { return Optional.empty(); } }
From source file:org.trustedanalytics.metricsprovider.cloudadapter.api.CfServiceInstance.java
@JsonIgnore public String getServicePlanName() { Optional<CfServiceInstance> serviceInstance = Optional.of(this); return serviceInstance.map(CfServiceInstance::getServicePlan).map(CfServicePlan::getName).orElse(null); }
From source file:com.spotify.styx.model.deprecated.WorkflowConfiguration.java
public static WorkflowConfiguration create(com.spotify.styx.model.WorkflowConfiguration workflowConfiguration) { return WorkflowConfiguration.create(workflowConfiguration.id(), workflowConfiguration.schedule(), workflowConfiguration.dockerImage(), workflowConfiguration.dockerArgs(), Optional.of(workflowConfiguration.dockerTerminationLogging()), workflowConfiguration.secret().map(s -> Secret.create(s.name(), s.mountPath())), workflowConfiguration.resources()); }
From source file:org.lendingclub.mercator.aws.EC2InstanceScanner.java
@Override public Optional<String> computeArn(JsonNode n) { String region = n.path(AWSScanner.AWS_REGION_ATTRIBUTE).asText(null); String account = n.path(AccountScanner.ACCOUNT_ATTRIBUTE).asText(null); String instanceId = n.path("aws_instanceId").asText(null); Preconditions.checkState(!Strings.isNullOrEmpty(region), "aws_region not set"); Preconditions.checkState(!Strings.isNullOrEmpty(account), "aws_account not set"); Preconditions.checkState(!Strings.isNullOrEmpty(instanceId), "aws_instanceId not set"); return Optional.of(ArnGenerator.newInstance(account, region).createEc2InstanceArn(instanceId)); }