List of usage examples for java.util Optional map
public <U> Optional<U> map(Function<? super T, ? extends U> mapper)
From source file:org.cyclop.service.common.CookieStorage.java
public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try {//www.j a v a2 s .co m Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }
From source file:org.flowable.engine.impl.dynamic.AbstractDynamicStateManager.java
protected void prepareMoveExecutionEntityContainer(MoveExecutionEntityContainer moveExecutionContainer, Optional<String> migrateToProcessDefinitionId, CommandContext commandContext) { ExpressionManager expressionManager = CommandContextUtil.getProcessEngineConfiguration(commandContext) .getExpressionManager();/* w w w . ja v a 2s.c o m*/ Optional<BpmnModel> bpmnModelToMigrateTo = migrateToProcessDefinitionId .map(ProcessDefinitionUtil::getBpmnModel); boolean canContainerDirectMigrate = (moveExecutionContainer.getMoveToActivityIds().size() == 1) && (moveExecutionContainer.getExecutions().size() == 1); for (String activityId : moveExecutionContainer.getMoveToActivityIds()) { FlowElement currentFlowElement; FlowElement newFlowElement; String currentActivityId; if (moveExecutionContainer.isMoveToParentProcess()) { String parentProcessDefinitionId = moveExecutionContainer.getSuperExecution() .getProcessDefinitionId(); BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(parentProcessDefinitionId); BpmnModel modelOfCallActivity = ProcessDefinitionUtil .getBpmnModel(moveExecutionContainer.getExecutions().get(0).getProcessDefinitionId()); currentActivityId = moveExecutionContainer.getExecutions().get(0).getCurrentActivityId(); currentFlowElement = resolveFlowElementFromBpmnModel(modelOfCallActivity, currentActivityId); newFlowElement = resolveFlowElementFromBpmnModel(bpmnModelToMigrateTo.orElse(bpmnModel), activityId); canContainerDirectMigrate = false; } else if (moveExecutionContainer.isMoveToSubProcessInstance()) { //The subProcess model is defined in the callActivity of the current processDefinition or the migrateProcessDefinition if defined ExecutionEntity firstExecution = moveExecutionContainer.getExecutions().get(0); BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(firstExecution.getProcessDefinitionId()); currentActivityId = firstExecution.getCurrentActivityId(); currentFlowElement = resolveFlowElementFromBpmnModel(bpmnModel, currentActivityId); String processDefinitionIdOfCallActivity = migrateToProcessDefinitionId .orElse(firstExecution.getProcessDefinitionId()); CallActivity callActivity = (CallActivity) resolveFlowElementFromBpmnModel( bpmnModelToMigrateTo.orElse(bpmnModel), moveExecutionContainer.getCallActivityId()); moveExecutionContainer.setCallActivity(callActivity); ProcessDefinition callActivityProcessDefinition = ProcessDefinitionUtil .getProcessDefinition(processDefinitionIdOfCallActivity); String tenantId = callActivityProcessDefinition.getTenantId(); Integer calledProcessVersion = moveExecutionContainer.getCallActivitySubProcessVersion(); String calledProcessDefKey = callActivity.getCalledElement(); if (isExpression(calledProcessDefKey)) { try { calledProcessDefKey = expressionManager.createExpression(calledProcessDefKey) .getValue(firstExecution.getProcessInstance()).toString(); } catch (FlowableException e) { throw new FlowableException("Cannot resolve calledElement expression '" + calledProcessDefKey + "' of callActivity '" + callActivity.getId() + "'", e); } } moveExecutionContainer.setSubProcessDefKey(calledProcessDefKey); ProcessDefinition subProcessDefinition = resolveProcessDefinition(calledProcessDefKey, calledProcessVersion, tenantId, commandContext); BpmnModel subProcessModel = ProcessDefinitionUtil.getBpmnModel(subProcessDefinition.getId()); moveExecutionContainer.setSubProcessDefinition(subProcessDefinition); moveExecutionContainer.setSubProcessModel(subProcessModel); newFlowElement = resolveFlowElementFromBpmnModel(subProcessModel, activityId); canContainerDirectMigrate = false; } else { // Get first execution to get process definition id ExecutionEntity firstExecution = moveExecutionContainer.getExecutions().get(0); BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(firstExecution.getProcessDefinitionId()); currentActivityId = firstExecution.getCurrentActivityId(); currentFlowElement = resolveFlowElementFromBpmnModel(bpmnModel, currentActivityId); newFlowElement = resolveFlowElementFromBpmnModel(bpmnModelToMigrateTo.orElse(bpmnModel), activityId); } moveExecutionContainer.addMoveToFlowElement(activityId, currentFlowElement, newFlowElement); canContainerDirectMigrate = canContainerDirectMigrate && isDirectFlowElementExecutionMigration(currentFlowElement, newFlowElement); } moveExecutionContainer .setDirectExecutionMigration(canContainerDirectMigrate && migrateToProcessDefinitionId.isPresent()); }
From source file:org.geoserver.qos.QosMainConfigurationValidator.java
public void validateRepresentativeOperation(QosRepresentativeOperation repOp) { Optional<QosRepresentativeOperation> ro = Optional.ofNullable(repOp); // Validate internal Statements ro.map(QosRepresentativeOperation::getQualityOfServiceStatements).map(List::stream) .ifPresent(s -> s.forEach(st -> valid(st))); }
From source file:org.geowebcache.diskquota.storage.TilePageCalculator.java
private Collection<String> getGridSubsetNames(Optional<Collection<GridSubset>> gridSubsets, TileLayer tileLayer) {/*from www . j a va 2 s .com*/ return gridSubsets.map(Collection::stream).map(stream -> stream.map(GridSubset::getName)) .map(stream -> stream.collect(Collectors.toSet())).orElseGet(() -> tileLayer.getGridSubsets()); }
From source file:org.geowebcache.diskquota.storage.TilePageCalculator.java
private Collection<String> getFormatNames(Optional<Collection<MimeType>> mimeTypes, TileLayer tileLayer) { return mimeTypes.map(Collection::stream).orElseGet(() -> tileLayer.getMimeTypes().stream()) .map(MimeType::getFormat).collect(Collectors.toList()); }
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 . ja v a 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 QueuePkgIconArchiveImportJobResult queuePkgIconArchiveImportJob( QueuePkgIconArchiveImportJobRequest 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_PKGICONIMPORTARCHIVE)) { LOGGER.warn("attempt to import package icons, but was not authorized"); throw new AuthorizationFailureException(); }//from w w w . j a va 2s. c om // now check that the data is present. jobService.tryGetData(request.inputDataGuid).orElseThrow( () -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid)); // setup and go PkgIconImportArchiveJobSpecification spec = new PkgIconImportArchiveJobSpecification(); spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null)); spec.setInputDataGuid(request.inputDataGuid); return new QueuePkgIconArchiveImportJobResult(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 www . j a v a 2s.co m*/ // 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:org.jbb.board.impl.forum.DefaultForumCategoryService.java
private Integer getLastCategoryPosition() { Optional<ForumCategoryEntity> lastCategory = categoryRepository.findTopByOrderByPositionDesc(); return lastCategory.map(ForumCategoryEntity::getPosition).orElse(0); }
From source file:org.jbb.board.impl.forum.DefaultForumService.java
private Integer getLastForumPosition(ForumCategoryEntity categoryEntity) { Optional<ForumEntity> lastForum = forumRepository.findTopByCategoryOrderByPositionDesc(categoryEntity); return lastForum.map(ForumEntity::getPosition).orElse(0); }