Při změně stavu požadavku se odešle e-mail dalšímu schvalovateli v

pořadí, případně uživateli, který zadal požadavek. 
closes #114
multitenant
Josef Rokos 10 years ago
parent 9076d5da4a
commit 09a6864710

@ -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;
}

@ -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<T extends RequirementBase> extends
AbstractOwnedService<T> implements RequirementBaseService<T> {
@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<User> 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<T extends RequirementBase> 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

@ -19,5 +19,5 @@ public interface UserService extends UserDetailsService, Service<User> {
public void grantAdmin();
public void removeAccess();
public void loadAuthorities(User user);
public String[] getEmailsForSend(List<User> users);
}

@ -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<User> implements UserService {
private PasswordEncoder encoder;
@ -152,5 +153,20 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
}
}
@Override
public String[] getEmailsForSend(List<User> users) {
List<String> emails = new ArrayList<String>();
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;
}
}

@ -27,7 +27,9 @@
<property name="from" value="${mail.from}"/>
</bean>
<bean id="messageBuilder" class="info.bukova.isspst.mail.EntityMessageBuilder"/>
<bean id="messageBuilder" class="info.bukova.isspst.mail.EntityMessageBuilder">
<property name="html" value="true"/>
</bean>
<!-- <bean id="mailer" class="info.bukova.rsfaktura.services.mail.ThreadMailer"> -->
<!-- <constructor-arg ref="attachementMailer"/> -->

@ -4,12 +4,13 @@
<window
border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.TripRequirementList')">
viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.TripRequirementList')"
vflex="1">
<caption
zclass="form-caption"
label="${labels.AgendaActRequirements}" />
<tabbox>
<tabbox vflex="1">
<tabs>
<tab label="${labels.RequirementsGridMy}"/>
<tab label="${labels.RequirementsGridMyCentres}" disabled="@load(not vm.showCentre)"/>
@ -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">
<listhead menupopup="auto" sizable="true">
<listheader
label="${labels.RequirementsGridNumberSerie}"
@ -140,16 +142,18 @@
</tabpanel>
<tabpanel apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListCentre')">
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListCentre')"
vflex="1">
<include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<hbox vflex="1">
<listbox
model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"
hflex="7"
onAfterRender="@command('afterRender')"
selectedIndex="@bind(vmSub.selIndex)">
selectedIndex="@bind(vmSub.selIndex)"
vflex="1">
<listhead menupopup="auto">
<listheader
label="${labels.RequirementsGridNumberSerie}"
@ -291,15 +295,17 @@
</tabpanel>
<tabpanel apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListWorkgroup')">
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListWorkgroup')"
vflex="1">
<include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<hbox vflex="1">
<listbox
model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"
hflex="7"
onAfterRender="@command('afterRender')"
selectedIndex="@bind(vmSub.selIndex)">
selectedIndex="@bind(vmSub.selIndex)"
vflex="1">
<listhead menupopup="auto">
<listheader
label="${labels.RequirementsGridNumberSerie}"
@ -462,16 +468,17 @@
</hbox>
</tabpanel>
<tabpanel apply="org.zkoss.bind.BindComposer"
<tabpanel vflex="1" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmSub') @init('info.bukova.isspst.ui.requirement.TripRequirementListAll')">
<include src="/requirements/toolbar.zul"/>
<hbox width="100%">
<hbox vflex="1">
<listbox
model="@load(vmSub.dataList)"
selectedItem="@bind(vmSub.dataBean)"
hflex="7"
onAfterRender="@command('afterRender')"
selectedIndex="@bind(vmSub.selIndex)">
selectedIndex="@bind(vmSub.selIndex)"
vflex="1">
<listhead menupopup="auto">
<listheader
label="${labels.RequirementsGridNumberSerie}"

Loading…
Cancel
Save