Created
March 7, 2014 14:10
-
-
Save nyilmaz/9412157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package magnet.support.mail.queue.builder; | |
| import com.google.common.collect.Maps; | |
| import magnet.support.mail.queue.entity.MailQueueEntity; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import org.springframework.util.Assert; | |
| import java.util.Date; | |
| /** | |
| * @author nyilmaz | |
| */ | |
| public class MailQueueBuilder { | |
| private static final Logger logger = LoggerFactory.getLogger(MailQueueBuilder.class); | |
| private MailQueueEntity mailQueueEntity; | |
| public MailQueueBuilder init() { | |
| // defaults | |
| mailQueueEntity = new MailQueueEntity(); | |
| mailQueueEntity.setVariables(Maps.<String, Object>newHashMap()); | |
| mailQueueEntity.setAddedTime(new Date()); | |
| mailQueueEntity.setForced(false); | |
| return this; | |
| } | |
| public MailQueueBuilder userId(Long userId) { | |
| mailQueueEntity.setUserId(userId); | |
| return this; | |
| } | |
| public MailQueueBuilder toEmail(String email) { | |
| mailQueueEntity.setEmail(email); | |
| return this; | |
| } | |
| public MailQueueBuilder force(Boolean force) { | |
| mailQueueEntity.setForced(force); | |
| return this; | |
| } | |
| public MailQueueBuilder addTemplateVar(String key, Object value) { | |
| mailQueueEntity.getVariables().put(key, value); | |
| return this; | |
| } | |
| public MailQueueEntity build() { | |
| Assert.notNull(mailQueueEntity.getEmail(), "email cannot be null."); | |
| if(mailQueueEntity.getVariables().isEmpty()) { | |
| logger.warn("Did you forget to add template variables?"); | |
| } | |
| return mailQueueEntity; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment