public static String emailToPhoneNumber(String address) { if (StringUtils.isBlank(address)) { return null; } int pos = address.indexOf("@"); if (pos < 0) return address; return address.substring(0, pos); }
@JsonIgnore public String getOs() { String retVal = ""; if (osName != null) retVal = (retVal + " " + osName).trim(); if (osVersionNumber != null) retVal = (retVal + " " + osVersionNumber).trim(); if (osVersionName != null) retVal = (retVal + " " + osVersionName).trim(); return StringUtils.isBlank(retVal) ? null : retVal; }
@JsonIgnore public String getAgent() { String retVal = ""; if (agentName != null) retVal = (retVal + " " + agentName).trim(); if (agentVersion != null) retVal = (retVal + " " + agentVersion).trim(); if (agentLanguage != null) retVal = (retVal + " " + agentLanguage).trim(); return StringUtils.isBlank(retVal) ? null : retVal; } }
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 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 String parseUrl(String apiUrl) { if (StringUtils.isBlank(apiUrl)) { return null; } String auth = parseAuth(apiUrl); if (StringUtils.isBlank(auth)) { return apiUrl; } else if (apiUrl.toLowerCase().startsWith("http://")) { return apiUrl.replace("http://"+auth+"@", "http://"); } else if (apiUrl.toLowerCase().startsWith("https://")) { return apiUrl.replace("https://"+auth+"@", "https://"); } else { String msg = String.format("Unable to parse the specified URL - does not start with \"http://\" or \"https://\"."); throw new IllegalArgumentException(msg); } }
@Override public RequestErrors validate(RequestErrors errors) { ValidationUtils.requireValue(errors, toAddress, "The \"to\" address must be specified."); ValidationUtils.requireValue(errors, fromAddress, "The \"from\" address must be specified."); if (StringUtils.isBlank(emailSubject) && StringUtils.isBlank(htmlContent)) { errors.add("At least the subject and/or the HTML content must be specified."); } return errors; }
@Override public RequestErrors validate(RequestErrors errors) { ValidationUtils.requireValue(errors, toAddress, "The \"to\" address must be specified."); ValidationUtils.requireValue(errors, fromAddress, "The \"from\" address must be specified."); if (StringUtils.isBlank(emailSubject) && StringUtils.isBlank(htmlContent)) { errors.add("At least the subject and/or the HTML content must be specified."); } return errors; }
@Override public RequestErrors validate(RequestErrors errors) { ValidationUtils.requireValue(errors, toAddress, "The \"to\" address must be specified."); ValidationUtils.requireValue(errors, fromAddress, "The \"from\" address must be specified."); if (StringUtils.isBlank(emailSubject) && StringUtils.isBlank(htmlContent)) { errors.add("At least the subject and/or the HTML content must be specified."); } return errors; }
public static String parseAuth(String apiUrl) { int pos; if (StringUtils.isBlank(apiUrl)) { return null; } else if (apiUrl.toLowerCase().startsWith("http://")) { pos = 7; } else if (apiUrl.toLowerCase().startsWith("https://")) { pos = 8; } else { String msg = String.format("Unable to parse the specified URL - does not start with \"http://\" or \"https://\"."); throw new IllegalArgumentException(msg); } String contents = apiUrl.substring(pos); pos = contents.indexOf("/"); if (pos < 0) pos = contents.length(); String left = contents.substring(0, pos); pos = left.indexOf("@"); if (pos < 0) { return null; } else { return left.substring(0, pos); } } public static String parseUserFromUrl(String apiUrl) {
public static CellularType emailToCellularType(String address) { if (StringUtils.isBlank(address)) { return null; } int pos = address.indexOf("@"); if (pos < 0) return null; String value = address.substring(pos); for (CellularType cellularType : values()) { if (cellularType.getEmailRight().equals(value)) { return cellularType; } } return null; } }
@JsonCreator private NotificationPushV1(@JsonProperty("message") String message, @JsonProperty("callbackUrl") String callbackUrl, @JsonProperty("remoteHost") String remoteHost, @JsonProperty("remoteAddress") String remoteAddress, @JsonProperty("traits") Map<String, String> traits) { this.message = (message == null) ? "No message" : message.trim(); this.remoteHost = remoteHost; this.remoteAddress = remoteAddress; this.callbackUrl = callbackUrl; // 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); } } }
private static void validSecurityField(RequestErrors errors, String value, String what) { ValidationUtils.requireValue(errors, value, String.format("The %s must be specified.", what)); if (StringUtils.isBlank(value)) return; for (String chr : invalidSecurityChr) { if (value.contains(chr)) { String list = StringUtils.toDelineatedString(" ", invalidSecurityChr); String msg = String.format("The %s cannot contain the following characters: %s", what, list); errors.add(msg); break; } } }
if (StringUtils.isBlank(this.traits.get(key))) { this.traits.remove(key);
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 EmailPush(@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); } } }
private SesEmailPush(@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); } } }
public static void requireValue(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.isBlank(value)) { errors.add(errorMessage); } }
String fromAddress = config.getTestFromAddress(); if (StringUtils.isBlank((toAddress))) { String msg = "A test message cannot be sent with out specifying the config's test-to-address."; pluginContext.setLastMessage(msg); if (StringUtils.isBlank((fromAddress))) { String msg = "A test message cannot be sent with out specifying the config's test-from-address."; pluginContext.setLastMessage(msg);
@Override public void test(PluginContext pluginContext, Domain domain) throws Exception { GoogleTalkConfig config = getConfig(pluginContext.getCouchServer(), domain); if (config == null) { String msg = "The Google Talk config has not been specified."; pluginContext.setLastMessage(msg); return; } String recipient = config.getTestAddress(); if (isBlank((recipient))) { String msg = "Test message cannot be sent with out specifying the test address."; pluginContext.setLastMessage(msg); return; } String override = config.getRecipientOverride(); if (isNotBlank(override)) { recipient = override; } String when = Formats.defaultStamp(new java.util.Date()); String msg = String.format("This is a test message from Cosmic Push sent at %s.", when); GoogleTalkPush push = GoogleTalkPush.newPush(recipient, msg, null, "gtalk-test:true"); PushRequest pushRequest = new PushRequest(AppContext.CURRENT_API_VERSION, domain, push); pluginContext.getPushRequestStore().create(pushRequest); new GoogleTalkDelegate(pluginContext, domain, pushRequest, push, config).run(); msg = String.format("Test message sent to %s:\n%s", recipient, msg); pluginContext.setLastMessage(msg); }