From c6ebf8959b635028670a16b15c6b987cee98eb82 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 1 Mar 2015 19:28:49 +0100 Subject: [PATCH] =?UTF-8?q?Umo=C5=BEn=C4=9Bna=20zm=C4=9Bna=20data=20schv?= =?UTF-8?q?=C3=A1len=C3=AD=20po=C5=BEadavku.=20closes=20#209?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../requirement/ApproveException.java | 24 +++++++ .../requirement/RequirementBaseService.java | 2 + .../RequirementBaseServiceImpl.java | 61 ++++++++++++------ .../requirement/RequirementServiceImpl.java | 13 ++-- .../isspst/ui/main/ApproveDialogVM.java | 60 +++++++++++++++++ .../ui/requirement/RequirementSubpage.java | 17 +++-- .../WEB-INF/locales/zk-label.properties | 7 ++ src/main/webapp/img/approve-032.png | Bin 0 -> 1266 bytes src/main/webapp/main/approveDialog.zul | 29 +++++++++ src/main/webapp/main/approveStatus.zul | 8 ++- 10 files changed, 185 insertions(+), 36 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/services/requirement/ApproveException.java create mode 100644 src/main/java/info/bukova/isspst/ui/main/ApproveDialogVM.java create mode 100644 src/main/webapp/img/approve-032.png create mode 100644 src/main/webapp/main/approveDialog.zul diff --git a/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java b/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java new file mode 100644 index 00000000..df93361c --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java @@ -0,0 +1,24 @@ +package info.bukova.isspst.services.requirement; + +import info.bukova.isspst.services.IsspstException; + +/** + * @author Pepa Rokos + */ +public class ApproveException extends IsspstException { + + /** + * + */ + private static final long serialVersionUID = -3794779381621324848L; + + public ApproveException() { + super(); + } + + public ApproveException(String message) { + super(message); + this.setReason(message); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java index 02d320d5..27407beb 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -4,6 +4,7 @@ import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.User; import info.bukova.isspst.services.Service; +import java.util.Date; import java.util.List; /** @@ -21,6 +22,7 @@ public interface RequirementBaseService extends Servi public void loadType(T data); public void loadWorkflow(T data); public void approve(T entity); + public void approve(T entity, Date approveDate); public boolean canApprove(T entity); public List getNextApprover(T entity); 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 bc44a3f5..afef01a3 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -18,11 +18,6 @@ import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - import org.hibernate.LazyInitializationException; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +25,10 @@ import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * @author Pepa Rokos * @author Franta Přibyl @@ -211,37 +210,45 @@ public abstract class RequirementBaseServiceImpl exte } } - protected void approve(T entity, User user) { + protected void approve(T entity, User user, Date approveDate) { T e = (T) dao.getById(entity.getId()); - + + if (e.getReqDate().getTime() > approveDate.getTime()) { + throw new ApproveException("ErrApproveBeforeRequirement"); + } + + if (e.getLastApproveDate() != null && e.getLastApproveDate().getTime() > approveDate.getTime()) { + throw new ApproveException("ErrAppreveBeforeLastApprove"); + } + Workflow wf = getNextWorkflow(e); if (wf == null) { return; } - + Role role = wf.getRole(); AuthItem auth = new AuthItem(); auth.setApprover(user); auth.setRole(role); - auth.setAuthDate(new Date()); - + auth.setAuthDate(approveDate); + e.getAuthorization().add(auth); - + if (getNextWorkflow(e) == null) { e.setState(RequirementState.APPROVED); } else { e.setState(RequirementState.PARTIALLY); } - + super.update(e); - - if (!autoApprove(e)) { + + if (!autoApprove(e, approveDate)) { this.sendToApprovers(e); - + SettingsData settings = settingsService.getSettings(); MailMessage message = null; - - if (e.getOwnedBy().getEmail() != null + + if (e.getOwnedBy().getEmail() != null && !e.getOwnedBy().getEmail().isEmpty() && e.getOwnedBy().isNotify()) { if (e.getState() == RequirementState.APPROVED && settings.getConfReqTemplate() != null) { @@ -249,17 +256,21 @@ public abstract class RequirementBaseServiceImpl exte } else if (settings.getAuthReqTemplate() != null) { message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e); } - + if (message != null) { message.setFrom(getLoggedInUser().getEmail()); message.setTo(e.getOwnedBy().getEmail()); - mailer.send(message); + mailer.send(message); } } } - + postApprove(e); } + + protected void approve(T entity, User user) { + approve(entity, user, new Date()); + } @Override @Transactional @@ -268,13 +279,21 @@ public abstract class RequirementBaseServiceImpl exte approve(entity, getLoggedInUser()); } + @Override + @Transactional + @PreAuthorize("this.canApprove(#entity)") + public void approve(T entity, Date approveDate) { + approve(entity, getLoggedInUser(), approveDate); + } + /** * Volá se z metody approve pro automatické schválení dalším schvalovatelem v pořadí. Metoda z báze nedělá nic. * * @param entity Požadavek + * @param approveDate * @return true pokud se provedlo automatické schválení. */ - protected boolean autoApprove(T entity) { + protected boolean autoApprove(T entity, Date approveDate) { return false; } 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 a97f078d..1e33ee45 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -10,16 +10,15 @@ import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workflow; import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.invoicing.InvoicingService; - -import java.math.BigDecimal; -import java.util.Date; -import java.util.List; - import org.hibernate.Hibernate; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + /** * @author Pepa Rokos * @author Franta Přibyl @@ -48,7 +47,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl approvers = this.getNextApprover(entity); Workflow nextWf = this.getNextWorkflow(entity); @@ -61,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl extends ListViewModel { @@ -55,8 +58,12 @@ public class RequirementSubpage extends ListViewModel @Command @NotifyChange({"dataBean", "canApprove"}) public void approve() { - this.getReqService().approve(getDataBean()); - BindUtils.postGlobalCommand(null, null, "reload", null); + Map params = new HashMap(); + params.put("service", getReqService()); + params.put("requirement", getDataBean()); + params.put("grid", this); + Window window = (Window) Executions.createComponents("/main/approveDialog.zul", null, params); + window.doModal(); } @Override diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index d8dea6f6..cd200e25 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -42,6 +42,13 @@ RequirementItemDescription=Poznámka RequirementInvoicedAmount=Fakturovaná částka: +RequirementApprove=Schválit +RequirementApproveDialog=Schválení +RequirementApproveDate=Datum schválení: +RequirementApproveStatus=Stav schválení: + +ErrAppreveBeforeLastApprove=Datum schválení musí být pozdější než datum posledního schválení! +ErrApproveBeforeRequirement=Datum schválení musí být pozdější než datum požadavku! AgendaMyOrders=Aktuální AgendaOrdersHistory=Ukončené diff --git a/src/main/webapp/img/approve-032.png b/src/main/webapp/img/approve-032.png new file mode 100644 index 0000000000000000000000000000000000000000..b629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vh&NYe`|e5&6)Xzi{JP9*Zz9F zZ*>#^Fm;tRW$G&H^y*zzvafT4{{H-WUH*!bEq~c@>!oZ^a}U%4&gT#SW)q}+bWdDq zJ{^kinv&roM*nfVZQ7Afaz{m>usH>Q?q}RD0m`?-1YiZ+yo?)p&j4@(ZPa=90jPZR z^06=ux&k2P6$o68OpsJ8ppXuL7Qi^*ms45*DC$R*U~%D#3uC&ZH3FVPx*s=#yk cPyML=4FaFpi?#RcbpQYW07*qoM6N<$g7T_Bg#Z8m literal 0 HcmV?d00001 diff --git a/src/main/webapp/main/approveDialog.zul b/src/main/webapp/main/approveDialog.zul new file mode 100644 index 00000000..4fa1a7f2 --- /dev/null +++ b/src/main/webapp/main/approveDialog.zul @@ -0,0 +1,29 @@ + + + + + + + + + + + + + +