List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:com.example.app.profile.model.terminology.FallbackProfileTermProvider.java
@Override public TextSource company() { return isBlank(Optional.ofNullable(getProfileTermProvider()).map(ProfileTermProvider::company).orElse(null)) ? _defaultProfileTermProvider.company() : getProfileTermProvider().company(); }
From source file:io.syndesis.model.connection.Action.java
@JsonProperty(access = JsonProperty.Access.READ_ONLY) default Optional<DataShape> getInputDataShape() { return Optional.ofNullable(getDefinition()).flatMap(ActionDefinition::getInputDataShape); }
From source file:com.thinkbiganalytics.metadata.api.event.category.CategoryChange.java
public Optional<String> getCategoryName() { return Optional.ofNullable(categoryName); }
From source file:com.devicehive.service.DeviceEquipmentServiceTest.java
@Test public void should_create_device_equipment() throws Exception { DeviceUpdate du = new DeviceUpdate(); du.setGuid(Optional.ofNullable(RandomStringUtils.randomAlphabetic(10))); du.setName(Optional.ofNullable(RandomStringUtils.randomAlphabetic(10))); DeviceClassUpdate dc = new DeviceClassUpdate(); dc.setName(Optional.ofNullable(RandomStringUtils.randomAlphabetic(10))); du.setDeviceClass(Optional.ofNullable(dc)); deviceService.deviceSave(du, Collections.<DeviceClassEquipmentVO>emptySet()); DeviceVO device = deviceService.findByGuidWithPermissionsCheck(du.getGuid().orElse(null), null); DeviceEquipmentVO de = new DeviceEquipmentVO(); de.setCode(RandomStringUtils.randomAlphabetic(10)); deviceEquipmentService.createDeviceEquipment(de, device); DeviceEquipmentVO saved = deviceEquipmentService.findByCodeAndDevice(de.getCode(), device); assertThat(saved, notNullValue());/*from w w w . j a v a2 s . c o m*/ assertThat(saved.getCode(), equalTo(de.getCode())); assertThat(saved.getTimestamp(), notNullValue()); }
From source file:io.gravitee.repository.redis.management.RedisPlanRepository.java
@Override public Optional<Plan> findById(String plan) throws TechnicalException { RedisPlan redisPlan = planRedisRepository.find(plan); return Optional.ofNullable(convert(redisPlan)); }
From source file:alfio.manager.location.DefaultLocationManager.java
@Override @Cacheable/*from w w w. j av a2 s . c o m*/ public Pair<String, String> geocode(String address) { return Optional.ofNullable(GeocodingApi.geocode(getApiContext(), address).awaitIgnoreError()) .filter(r -> r.length > 0).map(r -> r[0].geometry.location) .map(l -> Pair.of(Double.toString(l.lat), Double.toString(l.lng))) .orElseThrow(() -> new LocationNotFound("No location found for address " + address)); }
From source file:spring.travel.site.controllers.OptionalUserController.java
private <T> void withCookie(Request request, DeferredResult<T> response, OptionalUserAction<T> action) { try {/*w w w . j a v a2 s . c om*/ Map<String, String> sessionVariables = cookieBaker.decode(request.getCookieValue().get()); Optional<String> userId = Optional.ofNullable(sessionVariables.get("id")); userService.user(userId).whenComplete((user, t) -> action .execute(new Request(user, request.getCookieValue(), request.getRemoteAddress()), response)); } catch (AuthException ae) { logger.warn("Error trying to decode session cookie [%s]", request.getCookieValue().get(), ae); action.execute(request, response); } }
From source file:cn.edu.zjnu.acm.judge.service.UserDetailService.java
public static boolean isUser(Authentication authentication, String userId) { return userId != null && Optional.ofNullable(authentication).map(Principal::getName).map(userId::equals).orElse(false); }
From source file:io.gravitee.repository.jdbc.JdbcTeamRepository.java
public Optional<Team> findByName(String name) throws TechnicalException { return Optional.ofNullable(teamJpaConverter.convertTo(internalJpaTeamRepository.findOne(name))); }
From source file:com.devicehive.service.security.jwt.JwtClientService.java
public JwtPayload getPayload(String jwtToken) { Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(jwtToken).getBody(); LinkedHashMap payloadMap = (LinkedHashMap) claims.get(JwtPayload.JWT_CLAIM_KEY); Optional userId = Optional.ofNullable(payloadMap.get(JwtPayload.USER_ID)); Optional networkIds = Optional.ofNullable((ArrayList) payloadMap.get(JwtPayload.NETWORK_IDS)); Optional actions = Optional.ofNullable((ArrayList) payloadMap.get(JwtPayload.ACTIONS)); Optional deviceGuids = Optional.ofNullable((ArrayList) payloadMap.get(JwtPayload.DEVICE_GUIDS)); Optional expiration = Optional.ofNullable(payloadMap.get(JwtPayload.EXPIRATION)); Optional tokenType = Optional.ofNullable(payloadMap.get(JwtPayload.TOKEN_TYPE)); JwtPayload.Builder builder = new JwtPayload.Builder(); if (userId.isPresent()) builder.withUserId(Long.valueOf(userId.get().toString())); if (networkIds.isPresent()) builder.withNetworkIds(new HashSet<>((ArrayList) networkIds.get())); if (actions.isPresent()) builder.withActions(new HashSet<>((ArrayList) actions.get())); if (deviceGuids.isPresent()) builder.withDeviceGuids(new HashSet<>((ArrayList) deviceGuids.get())); if (!tokenType.isPresent() && !expiration.isPresent()) { throw new MalformedJwtException("Token type and expiration date should be provided in the token"); } else {/*from www. j a v a 2 s . co m*/ if (tokenType.isPresent()) builder.withTokenType(TokenType.valueOf((String) tokenType.get())); else throw new MalformedJwtException("Token type should be provided in the token"); if (expiration.isPresent()) builder.withExpirationDate(new Date((Long) expiration.get())); else throw new MalformedJwtException("Expiration date should be provided in the token"); return builder.buildPayload(); } }