Pokud má další schvalovatel v pořadí nastaveno schvalování pouze

nadlimitních požadavků a požadavek je pod limitem, schválí se za tohoto
schvalovatele automaticky.
closes #133
multitenant
Josef Rokos 10 years ago
parent 4047418fba
commit b7967e66c0

@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public class ReqMaterialServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement> public class ReqMaterialServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService<Requirement>
{ {
@Autowired @Autowired
private RequirementTypeService reqTypeService; private RequirementTypeService reqTypeService;

@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
public class ReqServicesServiceImpl extends RequirementBaseServiceImpl<Requirement> implements RequirementService, RequirementBaseService<Requirement> public class ReqServicesServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService<Requirement>
{ {
@Autowired @Autowired
private RequirementTypeService reqTypeService; private RequirementTypeService reqTypeService;

@ -182,10 +182,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
} }
} }
@Override protected void approve(T entity, User user) {
@Transactional
@PreAuthorize("this.canApprove(#entity)")
public void approve(T entity) {
T e = (T) dao.getById(entity.getId()); T e = (T) dao.getById(entity.getId());
Workflow wf = getNextWorkflow(e); Workflow wf = getNextWorkflow(e);
@ -195,7 +192,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
Role role = wf.getRole(); Role role = wf.getRole();
AuthItem auth = new AuthItem(); AuthItem auth = new AuthItem();
auth.setApprover(getLoggedInUser()); auth.setApprover(user);
auth.setRole(role); auth.setRole(role);
auth.setAuthDate(new Date()); auth.setAuthDate(new Date());
@ -211,26 +208,39 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
super.update(e); super.update(e);
this.sendToApprovers(e); if (!autoApprove(entity)) {
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 && settings.getConfReqTemplate() != null) {
message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e);
} else if (settings.getAuthReqTemplate() != null) {
message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e);
}
if (message != null) { SettingsData settings = settingsService.getSettings();
message.setTo(e.getOwnedBy().getEmail()); MailMessage message = null;
mailer.send(message);
if (e.getOwnedBy().getEmail() != null
&& !e.getOwnedBy().getEmail().isEmpty()
&& e.getOwnedBy().isNotify()) {
if (e.getState() == RequirementState.APPROVED && settings.getConfReqTemplate() != null) {
message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e);
} else if (settings.getAuthReqTemplate() != null) {
message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e);
}
if (message != null) {
message.setTo(e.getOwnedBy().getEmail());
mailer.send(message);
}
} }
} }
} }
@Override
@Transactional
@PreAuthorize("this.canApprove(#entity)")
public void approve(T entity) {
approve(entity, getLoggedInUser());
}
protected boolean autoApprove(T entity) {
return false;
}
@Override @Override
@Transactional @Transactional
@ -243,7 +253,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
return false; return false;
} }
private Workflow getNextWorkflow(T e) { protected Workflow getNextWorkflow(T e) {
AuthItem authItem = null; AuthItem authItem = null;
if (e.getWorkflow() == null) { if (e.getWorkflow() == null) {
return null; return null;

@ -3,8 +3,11 @@ package info.bukova.isspst.services.requirement;
import info.bukova.isspst.Constants; import info.bukova.isspst.Constants;
import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.RequirementState;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workflow;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -26,4 +29,21 @@ public class RequirementServiceImpl extends
return entity; return entity;
} }
@Override
protected boolean autoApprove(Requirement entity) {
List<User> approvers = this.getNextApprover(entity);
Workflow nextWf = this.getNextWorkflow(entity);
if (approvers == null || approvers.isEmpty() || nextWf == null || nextWf.getLimit() == null) {
return false;
}
if (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1) {
approve(entity, approvers.get(0));
return true;
}
return false;
}
} }

Loading…
Cancel
Save