public static boolean isAnyNotBlank(Collection<?> values) { if (values == null) { return false; } for (Object value : values) { if (isNotBlank(value)) { return true; } } return false; }
public boolean hasTempPassword() { return StringUtils.isNotBlank(tempPassword); } public String createTempPassword() {
public static String buildLabel(String latitude, String longitude, String city, State state, Country country) { if (StringUtils.isNotBlank(city) && StringUtils.isNotBlank(state)) { if (StringUtils.isNotBlank(country) || Country.US.equals(country)) { return city+", "+state; } else { return city+", "+state + " " + country; } } else { return latitude + ", " + longitude; } }
public RequestStatus processed(String note) { this.requestStatus = RequestStatus.processed; this.notes.add("Request has been processed."); if (StringUtils.isNotBlank(note)) { this.notes.add(note); } return this.requestStatus; }
@Override public Collection<? extends GrantedAuthority> getAuthorities() { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String roleType : permissions.getRoleTypes()) { if (StringUtils.isNotBlank(roleType)) { SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(roleType); authorities.add(grantedAuthority); } } return Collections.unmodifiableCollection(authorities); }
public static String parsePassFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return null; String pass = authentication.substring(pos+1); return StringUtils.isNotBlank(pass) ? pass : null; }
public static void requireInteger(RequestErrors errors, String value, String message) { if (StringUtils.isNotBlank(value)) { try { // noinspection ResultOfMethodCallIgnored Integer.valueOf(value); } catch (NumberFormatException e) { errors.add(message); } } } }
public static void requireInteger(RequestErrors errors, String value, String message) { if (StringUtils.isNotBlank(value)) { try { // noinspection ResultOfMethodCallIgnored Integer.valueOf(value); } catch (NumberFormatException e) { errors.add(message); } } } }
public static String parseUserFromAuth(String authentication) { if (StringUtils.isBlank(authentication)) { return null; } int pos = authentication.indexOf(":"); if (pos < 0) return authentication; String name = authentication.substring(0, pos); return StringUtils.isNotBlank(name) ? name : null; } public static String parsePassFromAuth(String authentication) {
public String[] resolveSpringProfiles(String additionalProfiles) { String activeProfiles = EnvUtils.findProperty(profilesPropertyName, ""); if (StringUtils.isNotBlank(activeProfiles)) activeProfiles += ","; activeProfiles += additionalProfiles; System.setProperty(profilesPropertyName, activeProfiles); log.info("Active spring profiles: {}", activeProfiles); String[] values = activeProfiles.split(","); for (int i = 0; i < values.length; i++) { values[i] = values[i].trim(); } return values; } }
public static String requireProperty(String propertyName, Class<? extends RuntimeException> type) { String value = findProperty(propertyName, null); if (StringUtils.isNotBlank(value)) { return value; } String msg = String.format("The system or environment property \"%s\" must be specified.", propertyName); try { throw type.getConstructor(String.class).newInstance(msg); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { log.error("Cannot create custom exception: " + type.getName(), ex); // Fall back to our default throw new IllegalArgumentException(msg); } }
public static String findProperty(String propertyName, String defaultValue) { String value = getSystemProperty(propertyName); if (StringUtils.isNotBlank(value)) { return value; } else { return findEnvironmentProperty(System.getenv(), propertyName, defaultValue); } }
private SmtpEmailPush(@JsonProperty("toAddress") String toAddress, @JsonProperty("fromAddress") String fromAddress, @JsonProperty("emailSubject") String emailSubject, @JsonProperty("htmlContent") String htmlContent, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.toAddress = toAddress; this.fromAddress = fromAddress; this.emailSubject = emailSubject; String content = StringUtils.getTagContents(htmlContent, "body", 0); this.htmlContent = StringUtils.isNotBlank(content) ? content : htmlContent; this.callbackUrl = callbackUrl; this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; // Get a list of all the keys so that we can loop on the map // and remove anything without an actual value (purge nulls). if (traits != null) { this.traits.putAll(traits); } String[] keys = ReflectUtils.toArray(String.class, this.traits.keySet()); for (String key : keys) { if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key); } } }
protected Invocation.Builder builder(String url, Map<String, Object> queryMap, String...acceptedResponseTypes) { Client client = ClientBuilder.newBuilder().build(); UriBuilder uriBuilder = UriBuilder.fromUri(getApiUrl()).path(url); for (Map.Entry<String,Object> queryParam : queryMap.entrySet()) { uriBuilder.queryParam(queryParam.getKey(), queryParam.getValue()); } WebTarget target = client.target(uriBuilder); Invocation.Builder builder = target.request(acceptedResponseTypes); if (StringUtils.isNotBlank(getUsername())) { builder.header("Authorization", getBasicAuthentication(getUsername(), getPassword())); } return builder; }
public static Response get(WaitForHttpAction action, String httpRequest) { Client client = ClientBuilder.newBuilder().build(); UriBuilder uriBuilder = UriBuilder.fromUri(httpRequest); WebTarget target = client.target(uriBuilder); Invocation.Builder builder = target.request(action.getAcceptedResponseTypes()); if (StringUtils.isNotBlank(action.getUsername())) { builder.header("Authorization", getBasicAuthentication(action.getUsername(), action.getPassword())); } return builder.get(Response.class); }
public static void requireNull(RequestErrors errors, Object value, String errorMessage) { if (value instanceof Integer) { if (((Integer)value) != 0) { errors.add(errorMessage); } } else if (value instanceof Long) { if (((Long)value) != 0) { errors.add(errorMessage); } } else if (StringUtils.isNotBlank(value)) { errors.add(errorMessage); } }
public static void requireNull(RequestErrors errors, Object value, String errorMessage) { if (value instanceof Integer) { if (((Integer)value) != 0) { errors.add(errorMessage); } } else if (value instanceof Long) { if (((Long)value) != 0) { errors.add(errorMessage); } } else if (StringUtils.isNotBlank(value)) { errors.add(errorMessage); } }
public static Response get(WaitForHttpAction action, String httpRequest) { Client client = ClientBuilder.newBuilder().build(); UriBuilder uriBuilder = UriBuilder.fromUri(httpRequest); WebTarget target = client.target(uriBuilder); Invocation.Builder builder = target.request(action.getAcceptedResponseTypes()); if (StringUtils.isNotBlank(action.getUsername())) { builder.header("Authorization", getBasicAuthentication(action.getUsername(), action.getPassword())); } return builder.get(Response.class); }
public static GoogleAuthentication getAuthResponse(String code, String clientId, String clientSecret) throws IOException { Client client = ClientBuilder.newBuilder().build(); Form form = new Form(); form.param("code", code); form.param("client_id", clientId); form.param("client_secret", clientSecret); form.param("grant_type", "authorization_code"); form.param("redirect_uri", "postmessage"); UriBuilder uriBuilder = UriBuilder.fromUri("https://accounts.google.com/o/oauth2/token"); Response jerseyResponse = client.target(uriBuilder) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE)); int status = jerseyResponse.getStatus(); String json = jerseyResponse.readEntity(String.class); TiogaJacksonObjectMapper objectMapper = new TiogaJacksonObjectMapper(); GoogleAuthentication googleAuth = objectMapper.readValue(json, GoogleAuthentication.class); // If there was an error in the token info, abort. if (StringUtils.isNotBlank(googleAuth.getError())) { String msg = String.format("Authentication Error: %s", googleAuth.getError()); throw ApiException.internalServerError(msg); } return googleAuth; }
if (StringUtils.isNotBlank(googleAuth.getError())) { String msg = String.format("Authentication Error: %s", googleAuth.getError()); throw ApiException.internalServerError(msg);