List of usage examples for java.util Optional orElse
public T orElse(T other)
From source file:org.haiku.haikudepotserver.api1.PkgJobApiImpl.java
@Override public QueuePkgCategoryCoverageImportSpreadsheetJobResult queuePkgCategoryCoverageImportSpreadsheetJob( QueuePkgCategoryCoverageImportSpreadsheetJobRequest request) throws ObjectNotFoundException { Preconditions.checkArgument(null != request, "the request must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(request.inputDataGuid), "the input data must be identified by guid"); final ObjectContext context = serverRuntime.newContext(); Optional<User> user = tryObtainAuthenticatedUser(context); if (!authorizationService.check(context, user.orElse(null), null, Permission.BULK_PKGCATEGORYCOVERAGEIMPORTSPREADSHEET)) { LOGGER.warn("attempt to import package categories, but was not authorized"); throw new AuthorizationFailureException(); }/*from w w w . j ava 2 s. c o m*/ // now check that the data is present. jobService.tryGetData(request.inputDataGuid).orElseThrow( () -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid)); // setup and go PkgCategoryCoverageImportSpreadsheetJobSpecification spec = new PkgCategoryCoverageImportSpreadsheetJobSpecification(); spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null)); spec.setInputDataGuid(request.inputDataGuid); return new QueuePkgCategoryCoverageImportSpreadsheetJobResult( jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE)); }
From source file:org.haiku.haikudepotserver.api1.PkgJobApiImpl.java
@Override public QueuePkgScreenshotArchiveImportJobResult queuePkgScreenshotArchiveImportJob( QueuePkgScreenshotArchiveImportJobRequest request) throws ObjectNotFoundException { Preconditions.checkArgument(null != request, "the request must be supplied"); Preconditions.checkArgument(StringUtils.isNotBlank(request.inputDataGuid), "the data guid must be supplied"); Preconditions.checkArgument(null != request.importStrategy, "the import strategy must be supplied"); final ObjectContext context = serverRuntime.newContext(); Optional<User> user = tryObtainAuthenticatedUser(context); if (!authorizationService.check(context, user.orElse(null), null, Permission.BULK_PKGSCREENSHOTIMPORTARCHIVE)) { LOGGER.warn("attempt to import package screenshots, but was not authorized"); throw new AuthorizationFailureException(); }//from w w w. jav a 2 s . c om // now check that the data is present. jobService.tryGetData(request.inputDataGuid).orElseThrow( () -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid)); // setup and go PkgScreenshotImportArchiveJobSpecification spec = new PkgScreenshotImportArchiveJobSpecification(); spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null)); spec.setInputDataGuid(request.inputDataGuid); spec.setImportStrategy( PkgScreenshotImportArchiveJobSpecification.ImportStrategy.valueOf(request.importStrategy.name())); return new QueuePkgScreenshotArchiveImportJobResult( jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE)); }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderSimple.java
@ExtDirectMethod public String methodWithOptional(Optional<String> param1) { return param1.orElse("default value"); }
From source file:org.openmhealth.shim.jawbone.mapper.JawbonePhysicalActivityDataPointMapper.java
@Override protected Optional<PhysicalActivity> getMeasure(JsonNode workoutNode) { checkNotNull(workoutNode);/*w w w. j a v a 2 s. c om*/ // assume that the title and workout type are optional since the documentation isn't clear Optional<String> title = asOptionalString(workoutNode, "title"); Optional<Integer> workoutType = asOptionalInteger(workoutNode, "sub_type"); String activityName = getActivityName(title.orElse(null), workoutType.orElse(null)); PhysicalActivity.Builder builder = new PhysicalActivity.Builder(activityName); asOptionalBigDecimal(workoutNode, "details.meters") .ifPresent(distance -> builder.setDistance(new LengthUnitValue(METER, distance))); Optional<Long> endTimestamp = asOptionalLong(workoutNode, "time_completed"); Optional<Long> durationInSec = asOptionalLong(workoutNode, "details.time"); Optional<ZoneId> timeZoneId = asOptionalZoneId(workoutNode, "details.tz"); if (endTimestamp.isPresent() && durationInSec.isPresent() && timeZoneId.isPresent()) { OffsetDateTime endDateTime = ofInstant(ofEpochSecond(endTimestamp.get()), getTimeZoneForTimestamp(workoutNode, endTimestamp.get())); builder.setEffectiveTimeFrame( ofEndDateTimeAndDuration(endDateTime, new DurationUnitValue(SECOND, durationInSec.get()))); } Optional<BigDecimal> totalCalories = asOptionalBigDecimal(workoutNode, "details.calories"); if (totalCalories.isPresent()) { asOptionalBigDecimal(workoutNode, "details.bmr_calories").ifPresent(bmrCalories -> { BigDecimal caloriesBurned = totalCalories.get().subtract(bmrCalories); builder.setCaloriesBurned(new KcalUnitValue(KILOCALORIE, caloriesBurned)); }); } asOptionalInteger(workoutNode, "details.intensity") .ifPresent(intensity -> builder.setReportedActivityIntensity(asSelfReportedIntensity(intensity))); return Optional.of(builder.build()); }
From source file:org.roda.core.plugins.plugins.PluginHelper.java
private static Optional<String> getAncestorById(String ancestor, Optional<String> computedSearchScope, IndexService index, String aipField) { if (ancestor.equalsIgnoreCase(computedSearchScope.orElse(null))) { return computedSearchScope; }/*from w ww .j a v a 2s. c om*/ Optional<String> ancestorBySIPId = Optional.empty(); Filter ancestorFilter = new Filter(new SimpleFilterParameter(aipField, ancestor)); if (computedSearchScope.isPresent()) { try { IndexedAIP computedParent = index.retrieve(IndexedAIP.class, computedSearchScope.get(), Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.AIP_ANCESTORS)); ancestorFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS, computedParent.getId())); } catch (NotFoundException | GenericException e) { // Do nothing } } try { // TODO 2016-11-24 sleroux: add user permission IndexResult<IndexedAIP> result = index.find(IndexedAIP.class, ancestorFilter, Sorter.NONE, new Sublist(0, 1), Arrays.asList(RodaConstants.INDEX_UUID)); if (result.getTotalCount() >= 1) { IndexedAIP indexedAIP = result.getResults().get(0); ancestorBySIPId = Optional.ofNullable(indexedAIP.getId()); } } catch (GenericException | RequestNotValidException e) { // Do nothing LOGGER.error("Error getting ancestor", e); } return ancestorBySIPId; }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(value = ExtDirectMethodType.POLL, event = "opoll2", synchronizeOnSession = true, group = "optional") public int opoll2(@RequestParam(value = "id") Optional<Integer> id, HttpServletRequest request) { assertThat(request).isNotNull();/*ww w . j a v a 2 s . c o m*/ return id.orElse(2) * 2; }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@OptionalNamedMethod public Optional<String> namedMethod1(Optional<Long> i, Optional<Double> d, Optional<String> s) { return Optional.of(String.format("namedMethod1() called-%d-%.3f-%s", i.orElse(-1L), d.orElse(3.141), s.orElse("default"))); }
From source file:org.apache.pulsar.functions.source.TopicSchema.java
public Schema<?> getSchema(String topic, Class<?> clazz, Optional<SchemaType> schemaType) { return cachedSchemas.computeIfAbsent(topic, key -> { // If schema type was not provided, try to get it from schema registry, or fallback to default types SchemaType type = schemaType.orElse(getSchemaTypeOrDefault(topic, clazz)); return newSchemaInstance(clazz, type); });//from w w w . j a va 2 s . c o m }
From source file:org.opensingular.form.wicket.mapper.DecimalMapper.java
private Map<String, Object> withOptionsOf(IModel<? extends SInstance> model) { Optional<Integer> inteiroMaximo = Optional .ofNullable(model.getObject().getAttributeValue(SPackageBasic.ATR_INTEGER_MAX_LENGTH)); Integer decimal = getDecimalMaximo(model); Map<String, Object> options = defaultOptions(); options.put("integerDigits", inteiroMaximo.orElse(DEFAULT_INTEGER_DIGITS)); options.put("digits", decimal); return options; }
From source file:ch.ralscha.extdirectspring.provider.RemoteProviderOptional.java
@ExtDirectMethod(value = ExtDirectMethodType.POLL, group = "optional") public Optional<String> opoll4(@RequestParam(value = "id") Optional<Integer> id, Optional<String> dummy, @RequestHeader Optional<String> header) { return Optional.of(id.orElse(100) + ";" + dummy.orElse("dummy") + ";" + header.orElse("header")); }