List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:com.netflix.genie.common.internal.dto.v4.Criterion.java
/** * Get the version of the resource desired if it exists. * * @return {@link Optional} wrapping the version *//* www. j av a 2 s . co m*/ public Optional<String> getVersion() { return Optional.ofNullable(this.version); }
From source file:ws.salient.model.Settings.java
private List<Profile> getProfiles(Collection<String> profileIds) { List<Profile> selectedProfiles = new LinkedList(); Optional.ofNullable(activeProfiles).orElse(Collections.EMPTY_LIST).forEach((id) -> { selectedProfiles.add(this.profiles.getOrDefault(id, new Profile())); });/*from w w w .j a v a2 s. c om*/ if (profileIds != null && this.profiles != null) { profileIds.forEach((id) -> { selectedProfiles.add(this.profiles.getOrDefault(id, new Profile())); }); } return selectedProfiles; }
From source file:com.thinkbiganalytics.feedmgr.service.feed.FeedHiveTableService.java
/** * Updates the column descriptions in the Hive metastore for the specified feed. * * @param feed the feed to update//from w w w . j av a 2 s . c om * @throws DataAccessException if there is any problem */ public void updateColumnDescriptions(@Nonnull final FeedMetadata feed) { final List<Field> feedFields = Optional.ofNullable(feed.getTable()).map(TableSetup::getTableSchema) .map(TableSchema::getFields).orElse(null); if (feedFields != null && !feedFields.isEmpty()) { final TableSchema hiveSchema = hiveService.getTableSchema(feed.getSystemCategoryName(), feed.getSystemFeedName()); if (hiveSchema != null) { final Map<String, Field> hiveFieldMap = hiveSchema.getFields().stream() .collect(Collectors.toMap(field -> field.getName().toLowerCase(), Function.identity())); feedFields.stream().filter(feedField -> { final Field hiveField = hiveFieldMap.get(feedField.getName().toLowerCase()); return hiveField != null && (StringUtils.isNotEmpty(feedField.getDescription()) || StringUtils.isNotEmpty(hiveField.getDescription())) && !Objects.equals(feedField.getDescription(), hiveField.getDescription()); }).forEach(feedField -> changeColumn(feed, feedField.getName(), feedField)); } } }
From source file:alfio.controller.api.ReservationApiController.java
@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/assign", method = RequestMethod.POST, headers = "X-Requested-With=XMLHttpRequest") public Map<String, Object> assignTicketToPerson(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, @RequestParam(value = "single-ticket", required = false, defaultValue = "false") boolean singleTicket, UpdateTicketOwnerForm updateTicketOwner, BindingResult bindingResult, HttpServletRequest request, Model model, Authentication authentication) throws Exception { Optional<UserDetails> userDetails = Optional.ofNullable(authentication).map(Authentication::getPrincipal) .filter(UserDetails.class::isInstance).map(UserDetails.class::cast); Optional<Triple<ValidationResult, Event, Ticket>> assignmentResult = ticketHelper.assignTicket(eventName, ticketIdentifier, updateTicketOwner, Optional.of(bindingResult), request, t -> { Locale requestLocale = RequestContextUtils.getLocale(request); model.addAttribute("ticketFieldConfiguration", ticketHelper.findTicketFieldConfigurationAndValue(t.getMiddle().getId(), t.getRight(), requestLocale)); model.addAttribute("value", t.getRight()); model.addAttribute("validationResult", t.getLeft()); model.addAttribute("countries", TicketHelper.getLocalizedCountries(requestLocale)); model.addAttribute("event", t.getMiddle()); model.addAttribute("useFirstAndLastName", t.getMiddle().mustUseFirstAndLastName()); model.addAttribute("availableLanguages", i18nManager.getEventLanguages(eventName).stream() .map(ContentLanguage.toLanguage(requestLocale)).collect(Collectors.toList())); String uuid = t.getRight().getUuid(); model.addAttribute("urlSuffix", singleTicket ? "ticket/" + uuid + "/view" : uuid); model.addAttribute("elementNamePrefix", ""); }, userDetails);/* w w w . jav a2s . co m*/ Map<String, Object> result = new HashMap<>(); Optional<ValidationResult> validationResult = assignmentResult.map(Triple::getLeft); if (validationResult.isPresent() && validationResult.get().isSuccess()) { result.put("partial", templateManager.renderServletContextResource("/WEB-INF/templates/event/assign-ticket-result.ms", model.asMap(), request, TemplateManager.TemplateOutput.HTML)); } result.put("validationResult", validationResult.orElse( ValidationResult.failed(new ValidationResult.ErrorDescriptor("fullName", "error.fullname")))); return result; }
From source file:com.netflix.genie.common.internal.dto.v4.CommonMetadata.java
/** * Get the description./*from www . ja v a 2s . c om*/ * * @return The description as an {@link Optional} */ public Optional<String> getDescription() { return Optional.ofNullable(this.description); }
From source file:com.thoughtworks.go.server.persistence.ServerBackupRepository.java
public Optional<ServerBackup> getBackup(long id) { return Optional.ofNullable(getHibernateTemplate().get(ServerBackup.class, id)); }
From source file:org.ow2.proactive.connector.iaas.service.InstanceService.java
public void deleteAllInstances(String infrastructureId) { Optional.ofNullable(infrastructureService.getInfrastructure(infrastructureId)).ifPresent(infrastructure -> { cloudManager.getAllInfrastructureInstances(infrastructure).forEach(instance -> { cloudManager.deleteInstance(infrastructure, instance.getId()); instanceCache.deleteInfrastructureInstance(infrastructure, instance); });/*from w ww . j a va 2 s . co m*/ }); }
From source file:com.ikanow.aleph2.analytics.services.GraphBuilderEnrichmentService.java
@Override public void onStageInitialize(IEnrichmentModuleContext context, DataBucketBean bucket, EnrichmentControlMetadataBean control, Tuple2<ProcessingStage, ProcessingStage> previous_next, Optional<List<String>> next_grouping_fields) { _context.set(context);/*from w w w .j av a 2s.c om*/ final GraphConfigBean dedup_config = BeanTemplateUtils .from(Optional.ofNullable(control.config()).orElse(Collections.emptyMap()), GraphConfigBean.class) .get(); // Check if enabled final Optional<GraphSchemaBean> maybe_graph_schema = Optional .ofNullable(dedup_config.graph_schema_override()).map(Optional::of) .orElse(Optionals.of(() -> bucket.data_schema().graph_schema())); //(exists by construction) _enabled.set(maybe_graph_schema.map(gs -> Optional.ofNullable(gs.enabled()).orElse(true)).orElse(false)); if (_enabled.get()) { // Get the configured graph db service's delegate and store it final GraphSchemaBean graph_schema = maybe_graph_schema.get(); //(exists by construction) context.getServiceContext() .getService(IGraphService.class, Optional.ofNullable(graph_schema.service_name())) .flatMap(graph_service -> graph_service.getUnderlyingPlatformDriver( IEnrichmentBatchModule.class, Optional.of(this.getClass().getName()))) .ifPresent(delegate -> _delegate.set(delegate)); ; _delegate.optional().ifPresent(delegate -> delegate.onStageInitialize(context, bucket, control, previous_next, next_grouping_fields)); } }
From source file:org.ow2.proactive.addons.ldap_query.LDAPClient.java
public LDAPClient(Map<String, Serializable> actualTaskVariables, Map<String, Serializable> credentials) { ImmutableList<String> taskVariablesList = ImmutableList.of(ARG_URL, ARG_DN_BASE, ARG_USERNAME, ARG_PASSWORD, ARG_SEARCH_BASE, ARG_SEARCH_FILTER, ARG_SELECTED_ATTRIBUTES); for (String variableName : taskVariablesList) { Serializable value = credentials.getOrDefault(variableName, actualTaskVariables.get(variableName)); allLDAPClientParameters.put(variableName, (String) Optional.ofNullable(value).orElseThrow(() -> new IllegalArgumentException( "The missed argument for LDAPClient, variable name: " + variableName))); }// w w w.ja v a 2 s . c o m }
From source file:com.teradata.benchto.driver.BenchmarkProperties.java
public Optional<String> getExecutionSequenceId() { return Optional.ofNullable(executionSequenceId); }