com.cosmicpush.gateway.push.EmailPush Maven / Gradle / Ivy
/*
* Copyright (c) 2014 Jacob D. Parr
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cosmicpush.gateway.push;
import com.cosmicpush.gateway.CosmicPushGateway;
import com.cosmicpush.gateway.common.*;
import com.cosmicpush.gateway.internal.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.crazyyak.dev.common.StringUtils;
import org.crazyyak.dev.net.email.EmailAddress;
public class EmailPush implements Push {
private String fromAddress;
private String toAddress;
private String emailSubject;
private String htmlContent;
private PushType pushType = PushType.email;
private EmailPush() {
}
public EmailPush(EmailAddress fromAddress, EmailAddress toAddress, String emailSubject, String htmlContent) {
this.toAddress = (toAddress == null) ? null : toAddress.getValue();
this.fromAddress = (fromAddress == null) ? null : fromAddress.getValue();
this.emailSubject = emailSubject;
this.htmlContent = htmlContent;
}
@Override
public PushType getPushType() {
return pushType;
}
public String getFromAddress() {
return fromAddress;
}
public String getToAddress() {
return toAddress;
}
public String getEmailSubject() {
return emailSubject;
}
public String getHtmlContent() {
return htmlContent;
}
@Override
@JsonIgnore
public String getEndPoint() {
return CosmicPushGateway.PUSH_EMAIL;
}
@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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy