List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowRevisionControllerTest.java
@Test public void testDelete() throws Exception { workflowRevisionController.delete(BUCKET_ID, WF_ID, REV_ID); verify(workflowRevisionService, times(1)).delete(BUCKET_ID, WF_ID, Optional.of(REV_ID)); }
From source file:com.epam.ta.reportportal.util.email.MailServiceFactory.java
/** * Build mail service based on provided configs * * @param projectConfig Project-level configuration * @param serverConfig Server-level configuration * @return Built email service/*from www . j av a 2s .c o m*/ */ public Optional<EmailService> getEmailService(ProjectEmailConfig projectConfig, ServerEmailDetails serverConfig) { return getEmailService(serverConfig).flatMap(service -> { // if there is server email config, let's check project config Optional<ProjectEmailConfig> projectConf = ofNullable(projectConfig); if (projectConf.isPresent()) { // if project config is present, check whether sending emails is enabled and replace server properties with project properties return projectConf.filter(ProjectEmailConfig::getEmailEnabled).flatMap(pc -> { //update of present on project level Optional.ofNullable(pc.getFrom()).ifPresent(service::setFrom); return Optional.of(service); }); } else { return Optional.of(service); } }); }
From source file:net.sf.jabref.exporter.CustomExportList.java
private Optional<ExportFormat> createFormat(List<String> s) { if (s.size() < 3) { return Optional.empty(); }/*from w w w.j a va2 s . c om*/ String lfFileName; if (s.get(1).endsWith(".layout")) { lfFileName = s.get(1).substring(0, s.get(1).length() - 7); } else { lfFileName = s.get(1); } ExportFormat format = new ExportFormat(s.get(0), s.get(0), lfFileName, null, s.get(2)); format.setCustomExport(true); return Optional.of(format); }
From source file:mtsar.processors.task.InverseCountAllocator.java
@Override @Nonnull/*from ww w. j a va2 s . co m*/ public Optional<TaskAllocation> allocate(@Nonnull Worker worker, @Nonnegative int n) { requireNonNull(stage, "the stage provider should not provide null"); final Set<Integer> answered = answerDAO.listForWorker(worker.getId(), stage.getId()).stream() .map(Answer::getTaskId).collect(Collectors.toSet()); final Map<Integer, Integer> counts = countDAO.getCountsSQL(stage.getId()).stream() .filter(pair -> !answered.contains(pair.getKey())) .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); final List<Integer> ids = filterTasks(counts); final int taskRemaining = ids.size(); if (ids.isEmpty()) return Optional.empty(); if (taskRemaining > n) ids.subList(n, ids.size()).clear(); final List<Task> tasks = taskDAO.select(ids, stage.getId()); final int taskCount = taskDAO.count(stage.getId()); final TaskAllocation allocation = new TaskAllocation.Builder().setWorker(worker).addAllTasks(tasks) .setTaskRemaining(taskRemaining).setTaskCount(taskCount).build(); return Optional.of(allocation); }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.Front50Service.java
protected Optional<Profile> generateAwsProfile(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints, String spinnakerHome) { PersistentStore.PersistentStoreType type = deploymentConfiguration.getPersistentStorage() .getPersistentStoreType();//from w ww . j a va 2 s. com S3PersistentStore store = deploymentConfiguration.getPersistentStorage().getS3(); if (type == PersistentStore.PersistentStoreType.S3 && !StringUtils.isEmpty(store.getAccessKeyId()) && !StringUtils.isEmpty(store.getSecretAccessKey())) { String outputFile = awsCredentialsProfileFactoryBuilder.getOutputFile(spinnakerHome); return Optional.of(awsCredentialsProfileFactoryBuilder.setArtifact(SpinnakerArtifact.FRONT50) .setAccessKeyId(store.getAccessKeyId()).setSecretAccessKey(store.getSecretAccessKey()).build() .getProfile("aws/front50-credentials", outputFile, deploymentConfiguration, endpoints)); } else { return Optional.empty(); } }
From source file:nu.yona.server.subscriptions.rest.NewDeviceRequestController.java
@RequestMapping(value = "/{mobileNumber}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK)// ww w . j ava2s. com public void setNewDeviceRequestForUser(@RequestHeader(value = Constants.PASSWORD_HEADER) String password, @PathVariable String mobileNumber, @RequestBody NewDeviceRequestCreationDto newDeviceRequestCreation) { try { userService.assertValidMobileNumber(mobileNumber); UUID userId = userService.getUserByMobileNumber(mobileNumber).getId(); try (CryptoSession cryptoSession = CryptoSession.start(Optional.of(password), () -> userService.doPreparationsAndCheckCanAccessPrivateData(userId))) { newDeviceRequestService.setNewDeviceRequestForUser(userId, password, newDeviceRequestCreation.getNewDeviceRequestPassword()); } } catch (UserServiceException e) { // prevent detecting whether a mobile number exists by throwing the same exception logger.error("Caught UserServiceException. Mapping it to CryptoException", e); throw CryptoException.decryptingData(); } }
From source file:org.openwms.tms.RedirectTODocumentation.java
public @Test void testRedirectToBlockedLocation() throws Exception { // setup ...// w w w . j a v a 2 s .c o m CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); vo.setTarget(INIT_LOC_STRING); given(commonGateway.getLocationGroup(INIT_LOC_STRING)).willReturn(Optional.empty()); INIT_LOC.setIncomingActive(false); given(commonGateway.getLocation(INIT_LOC_STRING)).willReturn(Optional.of(INIT_LOC)); // test ... sendPatch(vo, status().isConflict(), "to-patch-target-blocked-loc"); }
From source file:com.vsct.dt.hesperides.indexation.model.ElasticSearchResponse.java
public Optional<T> getSingleResult() throws NonUniqueResultException { if (this.getHits().getTotal() > 1) { LOGGER.error("Get {} hits but we're expecting only one", this.getHits()); //throw new ESServiceException("Failed to get instance with id " + id, url, body, httpHost.getHostName(), httpHost.getPort(), index); //TO DO Handle new exception type, it is not due to ES //Encapsulate in elastic search response throw new NonUniqueResultException("Found several instances of " + this.getHits().getDocuments().get(0).getData().getClass() + " but wanted single result"); }//from ww w .j a va 2 s.c o m if (this.getHits().getTotal() == 1) { LOGGER.debug("Data is null ?", this.getHits().getDocuments().get(0).getData()); return Optional.of(this.getHits().getDocuments().get(0).getData()); } else { LOGGER.debug("No result from ELS"); return Optional.empty(); } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ClouddriverService.java
protected Optional<Profile> generateAwsProfile(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints, String spinnakerHome) { AwsProvider awsProvider = deploymentConfiguration.getProviders().getAws(); if (awsProvider.isEnabled() && !StringUtils.isEmpty(awsProvider.getAccessKeyId()) && !StringUtils.isEmpty(awsProvider.getSecretAccessKey())) { String outputFile = awsCredentialsProfileFactoryBuilder.getOutputFile(spinnakerHome); return Optional.of(awsCredentialsProfileFactoryBuilder.setArtifact(SpinnakerArtifact.CLOUDDRIVER) .setAccessKeyId(awsProvider.getAccessKeyId()) .setSecretAccessKey(awsProvider.getSecretAccessKey()).build() .getProfile("aws/clouddriver-credentials", outputFile, deploymentConfiguration, endpoints)); } else {/* www . j a v a2s. c om*/ return Optional.empty(); } }
From source file:com.athina.queue.manager.entity.JobQueueManager.java
public Optional<Job> getJob(JobKey jobKey) { try {/* w w w.j av a 2 s. c om*/ JobDetail jobDetail = quartzScheduler.getJobDetail(jobKey.buildQuartzJobKey()); if (jobDetail == null) { return Optional.empty(); } Set<org.quartz.Trigger> quartzTriggers = ImmutableSet .copyOf(quartzScheduler.getTriggersOfJob(jobDetail.getKey())); return Optional.of(Job.fromQuartzJobDetailAndTriggers(jobDetail, quartzTriggers)); } catch (SchedulerException e) { throw Throwables.propagate(e); } }