diff --git a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java index ec1753a4..8fa3047f 100644 --- a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java +++ b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java @@ -11,12 +11,18 @@ import org.slf4j.LoggerFactory; public class EntityMessageBuilder implements MessageBuilder { private final static Logger logger = LoggerFactory.getLogger(EntityMessageBuilder.class); + private boolean html; + + public void setHtml(boolean html) { + this.html = html; + } @Override public MailMessage buildMessage(MailMessage template, Object data) { MailMessage msg = new MailMessage(template); msg.setSubject(replacaProperties(msg.getSubject(), data)); msg.setText(replacaProperties(msg.getText(), data)); + msg.setHtml(html); return msg; } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index 7a05daa4..142d0f9a 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -5,23 +5,58 @@ import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.SettingsData; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workflow; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.mail.MailMessage; +import info.bukova.isspst.mail.Mailer; +import info.bukova.isspst.mail.MessageBuilder; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; +import info.bukova.isspst.services.settings.GlobalSettingsService; +import info.bukova.isspst.services.users.UserService; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.hibernate.LazyInitializationException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; public abstract class RequirementBaseServiceImpl extends AbstractOwnedService implements RequirementBaseService { + @Autowired + private Mailer mailer; + @Autowired + private MessageBuilder messageBuilder; + @Autowired + private GlobalSettingsService settingsService; + @Autowired + private UserService userService; + + @Override + @Transactional + public void add(T entity) { + super.add(entity); + + this.sendToApprovers(entity); + } + + private void sendToApprovers(T entity) { + SettingsData settings = settingsService.getSettings(); + List approvers = this.getNextApprover(entity); + if (approvers != null && !approvers.isEmpty()) { + MailMessage message = messageBuilder.buildMessage(settings.getNewReqTemplate(), entity); + message.setTo(userService.getEmailsForSend(approvers)); + + mailer.send(message); + } + } + protected void addWorkflow(T entity) { if (entity.getType() == null) { return; @@ -153,6 +188,23 @@ public abstract class RequirementBaseServiceImpl exte entity.getAuthorization().add(auth); this.update(e); + + this.sendToApprovers(e); + + SettingsData settings = settingsService.getSettings(); + MailMessage message = null; + + if (e.getOwnedBy().getEmail() != null + && !e.getOwnedBy().getEmail().isEmpty() + && e.getOwnedBy().isNotify()) { + if (e.getState() == RequirementState.APPROVED) { + message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e); + } else { + message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e); + } + message.setTo(e.getOwnedBy().getEmail()); + mailer.send(message); + } } @Override diff --git a/src/main/java/info/bukova/isspst/services/users/UserService.java b/src/main/java/info/bukova/isspst/services/users/UserService.java index 5b913f35..5e59eb2a 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserService.java +++ b/src/main/java/info/bukova/isspst/services/users/UserService.java @@ -19,5 +19,5 @@ public interface UserService extends UserDetailsService, Service { public void grantAdmin(); public void removeAccess(); public void loadAuthorities(User user); - + public String[] getEmailsForSend(List users); } diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index 34c0dbe4..ebe25ec1 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -1,5 +1,12 @@ package info.bukova.isspst.services.users; +import info.bukova.isspst.Constants; +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; +import info.bukova.isspst.services.AbstractService; +//import info.bukova.isspst.services.LazyLoader; + +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -15,12 +22,6 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.transaction.annotation.Transactional; -import info.bukova.isspst.Constants; -import info.bukova.isspst.data.Role; -import info.bukova.isspst.data.User; -import info.bukova.isspst.services.AbstractService; -//import info.bukova.isspst.services.LazyLoader; - public class UserServiceImpl extends AbstractService implements UserService { private PasswordEncoder encoder; @@ -152,5 +153,20 @@ public class UserServiceImpl extends AbstractService implements UserServic } } + @Override + public String[] getEmailsForSend(List users) { + List emails = new ArrayList(); + for (User u : users) { + if (u.getEmail() != null && !u.getEmail().isEmpty() && u.isNotify()) { + emails.add(u.getEmail()); + } + } + + String[] ret = new String[emails.size()]; + ret = emails.toArray(ret); + + return ret; + } + } diff --git a/src/main/webapp/WEB-INF/spring/mail-services.xml b/src/main/webapp/WEB-INF/spring/mail-services.xml index 2002aed1..7e401b71 100644 --- a/src/main/webapp/WEB-INF/spring/mail-services.xml +++ b/src/main/webapp/WEB-INF/spring/mail-services.xml @@ -27,7 +27,9 @@ - + + + diff --git a/src/main/webapp/trips/requirement/requirements.zul b/src/main/webapp/trips/requirement/requirements.zul index affd1278..55e0294b 100644 --- a/src/main/webapp/trips/requirement/requirements.zul +++ b/src/main/webapp/trips/requirement/requirements.zul @@ -4,12 +4,13 @@ + viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.TripRequirementList')" + vflex="1"> - + @@ -24,7 +25,8 @@ model="@load(vm.dataList)" selectedItem="@bind(vm.dataBean)" onAfterRender="@command('afterRender')" - selectedIndex="@bind(vm.selIndex)"> + selectedIndex="@bind(vm.selIndex)" + vflex="1"> + viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListCentre')" + vflex="1"> - + + selectedIndex="@bind(vmSub.selIndex)" + vflex="1"> + viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListWorkgroup')" + vflex="1"> - + + selectedIndex="@bind(vmSub.selIndex)" + vflex="1"> - - + + selectedIndex="@bind(vmSub.selIndex)" + vflex="1">