List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:org.obiba.mica.micaConfig.service.DataAccessFormService.java
public Optional<DataAccessForm> find() { DataAccessForm form = dataAccessFormRepository.findOne(DataAccessForm.DEFAULT_ID); if (form == null) { createOrUpdate(createDefaultDataAccessForm()); form = dataAccessFormRepository.findOne(DataAccessForm.DEFAULT_ID); }/* w w w .j av a 2s .c om*/ if (StringUtils.isEmpty(form.getCsvExportFormat())) { form.setCsvExportFormat(getDefaultDataAccessFormResourceAsString("export-csv-schema.json")); form = createOrUpdate(form); } return Optional.ofNullable(form); }
From source file:controllers.DiscourseAuth.java
/** Appends the user's info to the Nonce, fields from. */ protected String appendUserInfoToNonce(Request req, String nonce) throws UnsupportedEncodingException { // find logged-in user AuthUser auth = AuthUser.auth(req);/*from w w w. j av a 2s . com*/ AccountRecord account; try (DSLContext dsl = req.require(DSLContext.class)) { account = dsl.selectFrom(ACCOUNT).where(ACCOUNT.ID.eq(auth.id())).fetchOne(); } // return the logged-in user String name = Optional.ofNullable(account.getName()).orElse(account.getUsername()); return nonce + "&name=" + urlEncode(name) + "&username=" + urlEncode(account.getUsername()) + "&email=" + urlEncode(account.getEmail()) + "&external_id=" + urlEncode(account.getId().toString()); }
From source file:com.todo.backend.web.rest.TodoApi.java
@RequestMapping(value = "/todo/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed/*w w w .ja va 2 s . co m*/ @Transactional(readOnly = true) public ResponseEntity<ReadTodoResponse> readTodo(@PathVariable Long id) { log.debug("GET /todo/{}", id); final Optional<Todo> result = Optional.ofNullable(todoRepository.findOne(id)); if (result.isPresent()) { return ResponseEntity.ok().body(convertToReadTodoResponse(result.get())); } return new ResponseEntity<>(HttpStatus.NOT_FOUND); }
From source file:org.openmhealth.shimmer.common.configuration.DefaultEndpointSettings.java
@Override public Optional<DateTimeQuerySettings> getModificationDateTimeQuerySettings() { return Optional.ofNullable(modificationDateTimeQuerySettings); }
From source file:com.lithium.flow.filer.Record.java
@Nonnull public Optional<String> getParent() { return Optional.ofNullable(parent); }
From source file:org.obiba.mica.micaConfig.service.OpalCredentialService.java
public Optional<OpalCredential> findOpalCredentialById(String id) { OpalCredential opalCredential = repository.findOne(id); if (opalCredential != null && opalCredential.getAuthType() == AuthType.USERNAME) opalCredential.setPassword(micaConfigService.decrypt(opalCredential.getPassword())); return Optional.ofNullable(opalCredential); }
From source file:com.netflix.genie.common.internal.dto.v4.ApplicationMetadata.java
/** * Get the type of this application./*from ww w. j av a 2 s .co m*/ * * @return The type wrapped in an {@link Optional} */ public Optional<String> getType() { return Optional.ofNullable(this.type); }
From source file:com.github.dmyersturnbull.transformations.CommandLineHelper.java
@Nonnull public CommandLineHelper setClass(@Nullable Class<?> aClass) { m_class = Optional.ofNullable(aClass); return this; }
From source file:io.syndesis.rest.v1.handler.user.UserHandler.java
@Path("~") @GET/*from w w w .ja va 2s. com*/ @Produces(MediaType.APPLICATION_JSON) public User whoAmI() { String token = String.valueOf(SecurityContextHolder.getContext().getAuthentication().getCredentials()); io.fabric8.openshift.api.model.User openShiftUser = this.openShiftService.whoAmI(token); Assert.notNull(openShiftUser, "A valid user is required"); return new User.Builder().username(openShiftUser.getMetadata().getName()) .fullName(Optional.ofNullable(openShiftUser.getFullName())) .name(Optional.ofNullable(openShiftUser.getFullName())).build(); }
From source file:com.devicehive.dao.riak.ConfigurationDaoRiakImpl.java
@Override public Optional<ConfigurationVO> getByName(String id) { //TODO configurable quorum? try {/* w ww. j ava2 s. c o m*/ Location objectKey = new Location(CONFIG_NS, id); FetchValue fetch = new FetchValue.Builder(objectKey) .withOption(quorum.getReadQuorumOption(), quorum.getReadQuorum()).build(); FetchValue.Response response = client.execute(fetch); RiakConfiguration configuration = getOrNull(response, RiakConfiguration.class); return Optional.ofNullable(RiakConfiguration.convert(configuration)); } catch (ExecutionException | InterruptedException e) { LOGGER.error("Exception accessing Riak Storage.", e); throw new HivePersistenceLayerException("Cannot fetch configuration by name.", e); } }