From 50ee0215c07a604fbb974d6c28682bb6a2d34eea Mon Sep 17 00:00:00 2001 From: Franta Pribyl Date: Fri, 8 Aug 2014 12:37:20 +0200 Subject: [PATCH] =?UTF-8?q?Po=C5=BEadavky=20na=20objedn=C3=A1vky=20p=C5=99?= =?UTF-8?q?epracov=C3=A1ny=20do=20z=C3=A1lo=C5=BEek.=20Funk=C4=8Dnost=20sj?= =?UTF-8?q?ednocena=20s=20po=C5=BEadavky=20na=20cestovn=C3=AD=20p=C5=99?= =?UTF-8?q?=C3=ADkaz.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #109 --- .../isspst/mail/EntityMessageBuilder.java | 6 +- .../requirement/RequirementBaseService.java | 9 +- .../RequirementBaseServiceImpl.java | 79 +++++- .../requirement/RequirementService.java | 4 +- .../requirement/RequirementServiceImpl.java | 1 + .../requirement/TripRequirementService.java | 9 +- .../TripRequirementServiceImpl.java | 49 ---- .../bukova/isspst/ui/main/TabPanelsVM.java | 56 ++++ .../main/orders/requirements/ReqListMy.java | 13 +- .../orders/requirements/ReqListMyAll.java | 13 +- .../orders/requirements/ReqListMyCenters.java | 13 +- .../requirements/ReqListMyWorkgroups.java | 13 +- .../ui/requirement/TripRequirementList.java | 17 ++ .../requirement/TripRequirementListAll.java | 2 +- .../validators/RequirementFormValidator.java | 4 +- .../main/orders/requirements/reqForm.zul | 4 +- .../main/orders/requirements/reqListMyAll.zul | 262 +++++++++--------- .../orders/requirements/reqListMyCenters.zul | 262 +++++++++--------- .../requirements/reqListMyWorkgroups.zul | 262 +++++++++--------- src/main/webapp/main/tabPanels.zul | 17 +- 20 files changed, 634 insertions(+), 461 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/ui/main/TabPanelsVM.java diff --git a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java index 8fa3047f..b8e54ed6 100644 --- a/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java +++ b/src/main/java/info/bukova/isspst/mail/EntityMessageBuilder.java @@ -20,13 +20,13 @@ public class EntityMessageBuilder implements MessageBuilder { @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.setSubject(replaceProperties(msg.getSubject(), data)); + msg.setText(replaceProperties(msg.getText(), data)); msg.setHtml(html); return msg; } - private String replacaProperties(String src, Object data) { + private String replaceProperties(String src, Object data) { int current = 0; List properties = new ArrayList(); boolean found = false; 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 80933537..61eb2a0f 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -2,10 +2,12 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.User; +import info.bukova.isspst.services.Service; import java.util.List; -public interface RequirementBaseService { +public interface RequirementBaseService extends Service +{ public void loadAuthItems(T data); public void loadType(T data); @@ -14,4 +16,9 @@ public interface RequirementBaseService { public boolean canApprove(T entity); public List getNextApprover(T entity); + public List getMy(); + + public List getCentreReq(); + + public List getWorkgroupReq(); } 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 142d0f9a..e0d79886 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -16,13 +16,16 @@ 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 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; +import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -37,7 +40,9 @@ public abstract class RequirementBaseServiceImpl exte private GlobalSettingsService settingsService; @Autowired private UserService userService; - + @Autowired + private WorkgroupService workgroupService; + @Override @Transactional public void add(T entity) { @@ -95,7 +100,28 @@ public abstract class RequirementBaseServiceImpl exte wg = e.getWorkgroup(); } - for (JobMapping jm : wg.getMembers()) { + + try + { + if (wg.getMembers() == null) + { + throw new LazyInitializationException(""); + } + + wg.getMembers().size(); + } + catch (LazyInitializationException ex) + { + Query q = dao.getQuery("from Workgroup where id = :id"); + q.setParameter("id", wg.getId()); + wg = (Workgroup) q.uniqueResult(); + + wg.getMembers().size(); + } + + + for (JobMapping jm : wg.getMembers()) + { if (jm.getRole().equals(nextRole) && jm.getMember().isPerson()) { users.add((User) jm.getMember()); } @@ -248,4 +274,53 @@ public abstract class RequirementBaseServiceImpl exte return wf; } + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public List getMy() + { + Query q = dao.getQuery("from " + dao.getEntityName() + " where ownedBy = :owner and state != :state"); + q.setParameter("owner", getLoggedInUser()); + q.setParameter("state", RequirementState.APPROVED); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_CENTRE_REQ')") + @PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')") + public List getCentreReq() + { + List wgList = workgroupService.getUserCentres(getLoggedInUser()); + Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) order by tr.numser"); + q.setParameterList("wgList", wgList); + q.setParameter("state", RequirementState.APPROVED); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_WORKGROUP_REQ')") + @PostFilter("hasPermission(filterObject, 'PERM_SHOW_WORKGROUP_REQ')") + public List getWorkgroupReq() + { + List wgList = workgroupService.getUserWorkgroups(getLoggedInUser()); + Query q = dao.getQuery("select tr from " + dao.getEntityName() + " tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) order by tr.numser"); + q.setParameterList("wgList", wgList); + q.setParameter("state", RequirementState.APPROVED); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_ALL_REQ')") + public List getAll() + { + Query q = dao.getQuery("from " + dao.getEntityName() + " as tr join fetch tr.ownedBy order by tr.numser"); + return q.list(); + } } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java index 6a05d509..e743d507 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java @@ -1,8 +1,8 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.Requirement; -import info.bukova.isspst.services.Service; -public interface RequirementService extends Service { +public interface RequirementService extends RequirementBaseService +{ } 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 b6b40b6a..dbb0c5f9 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -24,6 +24,7 @@ public class RequirementServiceImpl extends entity.setReqDate(new Date()); entity.setType(reqTypeService.getTypeById(Constants.REQTYPE_ORDER)); entity.setState(RequirementState.NEW); + this.addWorkflow(entity); return entity; } diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java index 89ed1331..373fee93 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java @@ -1,15 +1,10 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.TripRequirement; -import info.bukova.isspst.services.Service; -import java.util.List; - -public interface TripRequirementService extends Service { +public interface TripRequirementService extends RequirementBaseService +{ - public List getCentreReq(); - public List getWorkgroupReq(); - public List getFromAll(); public void loadPassangers(TripRequirement entity); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java index 28fd66e8..e13f6c72 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -8,12 +8,9 @@ import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.workgroups.WorkgroupService; import java.util.Date; -import java.util.List; import org.hibernate.LazyInitializationException; -import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -50,52 +47,6 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl getAll() { - Query q = dao.getQuery("from TripRequirement where ownedBy = :owner and state != :state"); - q.setParameter("owner", getLoggedInUser()); - q.setParameter("state", RequirementState.APPROVED); - return q.list(); - } - - @SuppressWarnings("unchecked") - @Override - @Transactional - @PreAuthorize("hasPermission(this, 'PERM_SHOW_CENTRE_REQ')") - @PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')") - public List getCentreReq() { - List wgList = workgroupService.getUserCentres(getLoggedInUser()); - Query q = dao.getQuery("select tr from TripRequirement tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) order by tr.numser"); - q.setParameterList("wgList", wgList); - q.setParameter("state", RequirementState.APPROVED); - return q.list(); - } - - @SuppressWarnings("unchecked") - @Override - @Transactional - @PreAuthorize("hasPermission(this, 'PERM_SHOW_WORKGROUP_REQ')") - @PostFilter("hasPermission(filterObject, 'PERM_SHOW_WORKGROUP_REQ')") - public List getWorkgroupReq() { - List wgList = workgroupService.getUserWorkgroups(getLoggedInUser()); - Query q = dao.getQuery("select tr from TripRequirement tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) order by tr.numser"); - q.setParameterList("wgList", wgList); - q.setParameter("state", RequirementState.APPROVED); - return q.list(); - } - - @SuppressWarnings("unchecked") - @Override - @Transactional - @PreAuthorize("hasPermission(this, 'PERM_SHOW_ALL_REQ')") - public List getFromAll() { - Query q = dao.getQuery("from TripRequirement as tr join fetch tr.ownedBy order by tr.numser"); - return q.list(); - } - @Override @Transactional @LazyLoader("form") diff --git a/src/main/java/info/bukova/isspst/ui/main/TabPanelsVM.java b/src/main/java/info/bukova/isspst/ui/main/TabPanelsVM.java new file mode 100644 index 00000000..ab16deed --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/main/TabPanelsVM.java @@ -0,0 +1,56 @@ +package info.bukova.isspst.ui.main; + +import org.zkoss.bind.annotation.GlobalCommand; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; + +public class TabPanelsVM +{ + private boolean showCentre; + private boolean showWorkgroup; + private boolean showAll; + + @Init + public void init() + { + showCentre = true; + showWorkgroup = true; + showAll = true; + } + + @GlobalCommand + @NotifyChange("showCentre") + public void disableCentre() + { + showCentre = false; + } + + @GlobalCommand + @NotifyChange("showWorkgroup") + public void disableWorkgroup() + { + showWorkgroup = false; + } + + @GlobalCommand + @NotifyChange("showAll") + public void disableAll() + { + showAll = false; + } + + public boolean isShowCentre() + { + return showCentre; + } + + public boolean isShowWorkgroup() + { + return showWorkgroup; + } + + public boolean isShowAll() + { + return showAll; + } +} diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMy.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMy.java index e412d0d7..6cb132c2 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMy.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMy.java @@ -8,8 +8,11 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.requirement.RequirementSubpage; +import java.util.ArrayList; import java.util.List; +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -43,6 +46,14 @@ public class ReqListMy extends RequirementSubpage @Override protected List getListFromService() { - return super.getListFromService(); + try + { + return requirementService.getMy(); + } + catch (AccessDeniedException e) + { + BindUtils.postGlobalCommand(null, null, "disableAll", null); + return new ArrayList(); + } } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyAll.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyAll.java index 29336b4a..5d32819e 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyAll.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyAll.java @@ -8,8 +8,11 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.requirement.RequirementSubpage; +import java.util.ArrayList; import java.util.List; +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -43,6 +46,14 @@ public class ReqListMyAll extends RequirementSubpage @Override protected List getListFromService() { - return super.getListFromService(); + try + { + return requirementService.getAll(); + } + catch (AccessDeniedException e) + { + BindUtils.postGlobalCommand(null, null, "disableAll", null); + return new ArrayList(); + } } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyCenters.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyCenters.java index c3a651dc..b4954d00 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyCenters.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyCenters.java @@ -8,8 +8,11 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.requirement.RequirementSubpage; +import java.util.ArrayList; import java.util.List; +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -43,6 +46,14 @@ public class ReqListMyCenters extends RequirementSubpage @Override protected List getListFromService() { - return super.getListFromService(); + try + { + return requirementService.getCentreReq(); + } + catch (AccessDeniedException e) + { + BindUtils.postGlobalCommand(null, null, "disableCentre", null); + return new ArrayList(); + } } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyWorkgroups.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyWorkgroups.java index cc20ee71..26856a70 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyWorkgroups.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/ReqListMyWorkgroups.java @@ -8,8 +8,11 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.requirement.RequirementSubpage; +import java.util.ArrayList; import java.util.List; +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -43,6 +46,14 @@ public class ReqListMyWorkgroups extends RequirementSubpage @Override protected List getListFromService() { - return super.getListFromService(); + try + { + return requirementService.getWorkgroupReq(); + } + catch (AccessDeniedException e) + { + BindUtils.postGlobalCommand(null, null, "disableWorkgroup", null); + return new ArrayList(); + } } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java index c570ecaf..3175c074 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java @@ -8,8 +8,11 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.ListViewModel; +import java.util.ArrayList; import java.util.List; +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; @@ -81,4 +84,18 @@ public class TripRequirementList extends ListViewModel { tripRequirementService.loadPassangers(data); } + @Override + protected List getListFromService() + { + try + { + return tripRequirementService.getMy(); + } + catch (AccessDeniedException e) + { + BindUtils.postGlobalCommand(null, null, "disableAll", null); + return new ArrayList(); + } + } + } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java index 463e7f72..6e0fec74 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java @@ -39,7 +39,7 @@ public class TripRequirementListAll extends RequirementSubpage @Override protected List getListFromService() { try { - return tripRequirementService.getFromAll(); + return tripRequirementService.getAll(); } catch (AccessDeniedException e) { BindUtils.postGlobalCommand(null, null, "disableAll", null); return new ArrayList(); diff --git a/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java b/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java index 7a0d3281..57e7dd55 100644 --- a/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java +++ b/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java @@ -21,8 +21,8 @@ public class RequirementFormValidator extends BaseValidator @Override public void validate(ValidationContext ctx) { - Property propertyWorkgroup = ctx.getProperties("workgroup")[0]; - Workgroup workgroup = (Workgroup) propertyWorkgroup.getValue(); + Property propertyCentre = ctx.getProperties("centre")[0]; + Workgroup workgroup = (Workgroup) propertyCentre.getValue(); if (workgroup == null) { diff --git a/src/main/webapp/main/orders/requirements/reqForm.zul b/src/main/webapp/main/orders/requirements/reqForm.zul index e71ba831..0a198062 100644 --- a/src/main/webapp/main/orders/requirements/reqForm.zul +++ b/src/main/webapp/main/orders/requirements/reqForm.zul @@ -53,7 +53,7 @@ model="@load(vm.centres)" readonly="true" disabled="@load(vm.editRec)" - selectedItem="@bind(fx.workgroup)"> + selectedItem="@bind(fx.centre)"> @@ -94,7 +94,7 @@