From b7967e66c0d79496cddde534de1db75ac20f6106 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 1 Sep 2014 21:51:52 +0200 Subject: [PATCH] =?UTF-8?q?Pokud=20m=C3=A1=20dal=C5=A1=C3=AD=20schvalovate?= =?UTF-8?q?l=20v=20po=C5=99ad=C3=AD=20nastaveno=20schvalov=C3=A1n=C3=AD=20?= =?UTF-8?q?pouze=20nadlimitn=C3=ADch=20po=C5=BEadavk=C5=AF=20a=20po=C5=BEa?= =?UTF-8?q?davek=20je=20pod=20limitem,=20schv=C3=A1l=C3=AD=20se=20za=20toh?= =?UTF-8?q?oto=20schvalovatele=20automaticky.=20closes=20#133?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../requirement/ReqMaterialServiceImpl.java | 2 +- .../requirement/ReqServicesServiceImpl.java | 2 +- .../RequirementBaseServiceImpl.java | 54 +++++++++++-------- .../requirement/RequirementServiceImpl.java | 20 +++++++ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/main/java/info/bukova/isspst/services/requirement/ReqMaterialServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/ReqMaterialServiceImpl.java index d0da386d..cf52e60d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/ReqMaterialServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/ReqMaterialServiceImpl.java @@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -public class ReqMaterialServiceImpl extends RequirementBaseServiceImpl implements RequirementService, RequirementBaseService +public class ReqMaterialServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService { @Autowired private RequirementTypeService reqTypeService; diff --git a/src/main/java/info/bukova/isspst/services/requirement/ReqServicesServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/ReqServicesServiceImpl.java index a3aa4d22..46d86338 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/ReqServicesServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/ReqServicesServiceImpl.java @@ -14,7 +14,7 @@ import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -public class ReqServicesServiceImpl extends RequirementBaseServiceImpl implements RequirementService, RequirementBaseService +public class ReqServicesServiceImpl extends RequirementServiceImpl implements RequirementService, RequirementBaseService { @Autowired private RequirementTypeService reqTypeService; 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 37a29784..0a84ae74 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -182,10 +182,7 @@ public abstract class RequirementBaseServiceImpl exte } } - @Override - @Transactional - @PreAuthorize("this.canApprove(#entity)") - public void approve(T entity) { + protected void approve(T entity, User user) { T e = (T) dao.getById(entity.getId()); Workflow wf = getNextWorkflow(e); @@ -195,7 +192,7 @@ public abstract class RequirementBaseServiceImpl exte Role role = wf.getRole(); AuthItem auth = new AuthItem(); - auth.setApprover(getLoggedInUser()); + auth.setApprover(user); auth.setRole(role); auth.setAuthDate(new Date()); @@ -211,26 +208,39 @@ public abstract class RequirementBaseServiceImpl exte super.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 && settings.getConfReqTemplate() != null) { - message = messageBuilder.buildMessage(settings.getConfReqTemplate(), e); - } else if (settings.getAuthReqTemplate() != null) { - message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e); - } + if (!autoApprove(entity)) { + this.sendToApprovers(e); - if (message != null) { - message.setTo(e.getOwnedBy().getEmail()); - mailer.send(message); + 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) { + 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 @Transactional @@ -243,7 +253,7 @@ public abstract class RequirementBaseServiceImpl exte return false; } - private Workflow getNextWorkflow(T e) { + protected Workflow getNextWorkflow(T e) { AuthItem authItem = null; if (e.getWorkflow() == null) { return null; diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index d57b2d85..a34559ab 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -3,8 +3,11 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.Constants; import info.bukova.isspst.data.Requirement; 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.List; import org.springframework.beans.factory.annotation.Autowired; @@ -26,4 +29,21 @@ public class RequirementServiceImpl extends return entity; } + @Override + protected boolean autoApprove(Requirement entity) { + List 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; + } + }