From 1c8b294f366e96f0e7bbff884b4b84b03cf9a3e7 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 16 Jul 2014 13:44:09 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Spole=C4=8Dn=C3=A9=20b=C3=A1ze=20pro=20pr?= =?UTF-8?q?=C3=A1ci=20s=20po=C5=BEadavky-=20rozpracovan=C3=A1=20verze.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukova/isspst/data/RequirementBase.java | 4 +- .../requirement/RequirementBaseService.java | 12 +- .../RequirementBaseServiceImpl.java | 130 ++++++++++++++++++ .../requirement/RequirementServiceImpl.java | 2 +- .../requirement/TripRequirementService.java | 5 + .../TripRequirementServiceImpl.java | 6 +- .../info/bukova/isspst/ui/ListViewModel.java | 5 + .../ui/requirement/RequirementSubpage.java | 42 ++++++ .../requirement/TripRequirementListAll.java | 4 + .../TripRequirementListCentre.java | 20 +-- .../TripRequirementListWorkgroup.java | 4 + .../webapp/requirements/approveStatus.zul | 25 ++++ .../webapp/trips/requirement/requirements.zul | 32 ++++- 13 files changed, 273 insertions(+), 18 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java create mode 100644 src/main/webapp/requirements/approveStatus.zul diff --git a/src/main/java/info/bukova/isspst/data/RequirementBase.java b/src/main/java/info/bukova/isspst/data/RequirementBase.java index 363f3f72..bdd572c5 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementBase.java +++ b/src/main/java/info/bukova/isspst/data/RequirementBase.java @@ -13,6 +13,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.MappedSuperclass; import javax.persistence.OneToMany; +import javax.persistence.OrderBy; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; @@ -29,7 +30,7 @@ public class RequirementBase extends BaseData { private Date reqDate; @Column(name = "DESCRIPTION") private String description; - @ManyToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CENTRE_ID") private Workgroup centre; @ManyToOne(fetch = FetchType.EAGER) @@ -37,6 +38,7 @@ public class RequirementBase extends BaseData { private Workgroup workgroup; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @LazyCollection(LazyCollectionOption.TRUE) + @OrderBy("ID") private List authorization; @Column(name = "STATE") @Enumerated(EnumType.ORDINAL) 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 b6a8723b..e6fe255b 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -1,5 +1,15 @@ package info.bukova.isspst.services.requirement; -public interface RequirementBaseService { +import info.bukova.isspst.data.RequirementBase; +import info.bukova.isspst.data.User; +import java.util.List; + +public interface RequirementBaseService { + + public void loadAuthItems(T data); + public void approve(T entity); + 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 new file mode 100644 index 00000000..0f63dc52 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -0,0 +1,130 @@ +package info.bukova.isspst.services.requirement; + +import info.bukova.isspst.data.AuthItem; +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.User; +import info.bukova.isspst.data.Workflow; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.AbstractOwnedService; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; + +public abstract class RequirementBaseServiceImpl extends + AbstractOwnedService implements RequirementBaseService { + + @Override + @Transactional + public List getNextApprover(T entity) { + T e = (T) dao.getById(entity.getId()); + + + List users = new ArrayList(); + Workgroup wg; + Workflow wf = getNextWorkflow(e); + Role nextRole; + + if (wf == null) { + return null; + } else { + nextRole = wf.getRole(); + } + + if (wf.getCentre() || e.getWorkgroup() == null) { + wg = e.getCentre(); + } else { + wg = e.getWorkgroup(); + } + + for (JobMapping jm : wg.getMembers()) { + if (jm.getRole().equals(nextRole) && jm.getMember().isPerson()) { + users.add((User) jm.getMember()); + } + } + + return users; + } + + @Override + @Transactional + public void loadAuthItems(T entity) { + T e = dao.getById(entity.getId()); + e.getAuthorization().size(); + entity.setAuthorization(e.getAuthorization()); + } + + @Override + @Transactional + @PreAuthorize("this.canApprove(#entity)") + public void approve(T entity) { + T e = (T) dao.getById(entity.getId()); + + Workflow wf = getNextWorkflow(e); + if (wf == null) { + return; + } + + Role role = wf.getRole(); + AuthItem auth = new AuthItem(); + auth.setApprover(getLoggedInUser()); + auth.setRole(role); + auth.setAuthDate(new Date()); + + e.getAuthorization().add(auth); + + if (getNextWorkflow(e) == null) { + e.setState(RequirementState.APPROVED); + } else { + e.setState(RequirementState.PARTIALLY); + } + entity.setState(e.getState()); + entity.getAuthorization().add(auth); + + this.update(e); + } + + @Override + @Transactional + public boolean canApprove(T entity) { + List nextApprovers = getNextApprover(entity); + if (nextApprovers != null && nextApprovers.contains(getLoggedInUser())) { + return true; + } + + return false; + } + + private Workflow getNextWorkflow(T e) { + AuthItem authItem = null; + if (e.getAuthorization().size() > 0) { + authItem = e.getAuthorization().get(e.getAuthorization().size() - 1); + } + + Workflow wf = null; + for (int i = 0; i < e.getType().getWorkflow().size(); i++) { + wf = e.getType().getWorkflow().get(i); + if (authItem != null && wf.getRole().equals(authItem.getRole())) { + if (i + 1 < e.getType().getWorkflow().size()) { + wf = e.getType().getWorkflow().get(i + 1); + break; + } else { + return null; + } + } + + if (authItem == null) { + break; + } + } + + return wf; + } + +} 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 ba5fad99..b4229ed4 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -8,7 +8,7 @@ import java.util.Date; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -public class RequirementServiceImpl extends AbstractOwnedService implements RequirementService, RequirementBaseService +public class RequirementServiceImpl extends AbstractOwnedService implements RequirementService, RequirementBaseService { @Override protected Requirement createEntity() 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 3285cc7b..cf258732 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java @@ -3,6 +3,7 @@ package info.bukova.isspst.services.requirement; import java.util.List; import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.User; import info.bukova.isspst.services.Service; public interface TripRequirementService extends Service { @@ -10,5 +11,9 @@ public interface TripRequirementService extends Service { public List getCentreReq(); public List getWorkgroupReq(); public List getFromAll(); + public void loadAuthItems(TripRequirement entity); + public List getNextApprover(TripRequirement entity); + public boolean canApprove(TripRequirement entity); + public void approve(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 46b84443..ad384152 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -4,7 +4,6 @@ import info.bukova.isspst.Constants; import info.bukova.isspst.data.RequirementState; import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.data.Workgroup; -import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.workgroups.WorkgroupService; import java.util.Date; @@ -16,8 +15,8 @@ import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -public class TripRequirementServiceImpl extends AbstractOwnedService - implements TripRequirementService, RequirementBaseService { +public class TripRequirementServiceImpl extends RequirementBaseServiceImpl + implements TripRequirementService, RequirementBaseService { @Autowired private RequirementTypeService reqTypeService; @@ -89,4 +88,5 @@ public class TripRequirementServiceImpl extends AbstractOwnedService { @NotifyChange({"dataBean","ableToDelete"}) public void setDataBean(T data) { + loadLazyData(data); this.dataBean = data; } + + protected void loadLazyData(T data) { + + } public void setDataFilter(Filter dataFilter) { this.dataFilter = dataFilter; diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java new file mode 100644 index 00000000..45e06dfc --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementSubpage.java @@ -0,0 +1,42 @@ +package info.bukova.isspst.ui.requirement; + +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.NotifyChange; + +import info.bukova.isspst.data.RequirementBase; +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.services.requirement.RequirementBaseService; +import info.bukova.isspst.ui.ListViewModel; + +public class RequirementSubpage extends ListViewModel { + + private RequirementBaseService reqService; + + + @Override + protected void loadLazyData(T data) { + reqService.loadAuthItems(data); + } + + @Command + @NotifyChange("dataBean") + public void approve() { + reqService.approve(getDataBean()); + } + + @Override + @NotifyChange({ "dataBean", "ableToDelete", "canApprove" }) + public void setDataBean(T data) { + super.setDataBean(data); + } + + public boolean isCanApprove() { + if (getDataBean() != null) { + return reqService.canApprove(getDataBean()); + } + + return false; + } + + +} 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 13209f19..e1bb4f52 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java @@ -55,5 +55,9 @@ public class TripRequirementListAll extends ListViewModel { public List getAllWorkgroups() { return allWorkgroups; } + + public boolean isCanApprove() { + return false; + } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java index 6eac2a19..8acd6473 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java @@ -1,13 +1,5 @@ package info.bukova.isspst.ui.requirement; -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; - import info.bukova.isspst.data.TripRequirement; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.filters.TripRequirementFilter; @@ -16,6 +8,16 @@ 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.Command; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.select.annotation.WireVariable; + public class TripRequirementListCentre extends ListViewModel { @WireVariable @@ -49,5 +51,7 @@ public class TripRequirementListCentre extends ListViewModel { public List getMyCentres() { return myCentres; } + + } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java index 78167bcd..ce9267a8 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java @@ -56,4 +56,8 @@ public class TripRequirementListWorkgroup extends ListViewModel return myWorkgroups; } + public boolean isCanApprove() { + return false; + } + } diff --git a/src/main/webapp/requirements/approveStatus.zul b/src/main/webapp/requirements/approveStatus.zul new file mode 100644 index 00000000..e18761ca --- /dev/null +++ b/src/main/webapp/requirements/approveStatus.zul @@ -0,0 +1,25 @@ + + + +