From 23d2eb58f6d80516be7121f48a5c6f2e3f674bca Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 20 Aug 2014 09:52:24 +0200 Subject: [PATCH] =?UTF-8?q?Do=20definice=20pracovn=C3=ADch=20skupin=20byl?= =?UTF-8?q?=20p=C5=99id=C3=A1n=20vyhled=C3=A1vac=C3=AD=20edit.=20Dopln?= =?UTF-8?q?=C4=9Bna=20kontrola=20=C4=8Dlenstv=C3=AD=20v=20komis=C3=ADch/st?= =?UTF-8?q?=C5=99edisc=C3=ADch.=20refs=20#123=20closes=20#119?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/workgroups/WorkgroupService.java | 1 + .../workgroups/WorkgroupServiceImpl.java | 29 +++++++- .../isspst/ui/workgroups/WorkgroupForm.java | 66 +++++++++++++++++-- .../WEB-INF/locales/zk-label.properties | 6 +- .../webapp/admin/workgroups/workgroupForm.zul | 26 ++++---- 5 files changed, 110 insertions(+), 18 deletions(-) diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java index b9420b1c..ec1b33bb 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java @@ -22,5 +22,6 @@ public interface WorkgroupService extends Service { public List getMembers(Workgroup workgroup); public void loadMembers(Workgroup workgroup); public void loadParents(Member member); + public void loadParentsMembers(Workgroup workgroup); } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java index 90b87a9d..5057396e 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -89,7 +89,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } if (member.isPerson()) { - return true; + return checkParentsMembers(workgroup, (User)member); } Workgroup toAdd = Workgroup.class.cast(member); @@ -104,6 +104,23 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem return true; } + + //check, jestli uzivatel pridavany do komise neni zaroven clenem strediska, jehoz je komise clenem + private boolean checkParentsMembers(Workgroup workgroup, User user) { + if (workgroup.isCentre()) { + return true; + } + + for (Workgroup wg : workgroup.getParents()) { + for (JobMapping jm : wg.getMembers()) { + if (jm.getMember().equals(user)) { + return false; + } + } + } + + return true; + } @Override @Transactional @@ -290,5 +307,15 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } } } + + @Override + @Transactional + public void loadParentsMembers(Workgroup workgroup) { + loadParents(workgroup); + + for (Workgroup wg : workgroup.getParents()) { + loadMembers(wg); + } + } } diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java index cff1e50f..8673a0ee 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java @@ -1,6 +1,7 @@ package info.bukova.isspst.ui.workgroups; import info.bukova.isspst.Constants; +import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Role; @@ -8,6 +9,7 @@ import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupException; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.FormViewModel; @@ -22,6 +24,10 @@ import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.event.DropEvent; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Listitem; +import org.zkoss.zul.Messagebox; + +import static ch.lambdaj.Lambda.*; +import static org.hamcrest.Matchers.*; public class WorkgroupForm extends FormViewModel { @@ -32,11 +38,14 @@ public class WorkgroupForm extends FormViewModel { @WireVariable private WorkgroupService workgroupService; private List users; + private String findUser; + private List selectedUsers; @Init(superclass = true) public void init() { users = new ArrayList(); users.addAll(userService.getAll()); + selectedUsers = new ArrayList(); } public List getUsers() { @@ -147,13 +156,31 @@ public class WorkgroupForm extends FormViewModel { if (!u.isPerson()) { workgroupService.loadMembers((Workgroup) u); + } else if (!getDataBean().isCentre()) { + workgroupService.loadParentsMembers(getDataBean()); } - workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target)); - - if (!u.isPerson()) { - users.remove(u); + try { + workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target)); + + if (!u.isPerson()) { + users.remove(u); + } + } catch (WorkgroupException e) { + String message; + String title; + + if (!getDataBean().isCentre()) { + message = StringUtils.localize("WorkgroupFormUserIsCenterMember"); + title = StringUtils.localize("WorkgroupFormCannotAddUser"); + } else { + message = StringUtils.localize("WorkgroupFormMemberIsCenterMember"); + title = StringUtils.localize("WorkgroupFormCannotAddWorkgroup"); + } + + Messagebox.show(message, title, Messagebox.OK, Messagebox.ERROR); } + } private String getSource(DropEvent event) { @@ -171,5 +198,36 @@ public class WorkgroupForm extends FormViewModel { return target; } + + public String getFindUser() { + return findUser; + } + + public void setFindUser(String findUser) { + this.findUser = findUser; + } + + public List getSelectedUsers() { + return selectedUsers; + } + + public void setSelectedUsers(List selectedUser) { + this.selectedUsers = selectedUser; + } + + @Command + @NotifyChange("selectedUsers") + public void find() { + List found = filter(having(on(Member.class).getFullName(), startsWith(findUser)), users); + + if (!found.isEmpty()) { + if (selectedUsers == null) { + selectedUsers = new ArrayList(); + } else { + selectedUsers.clear(); + selectedUsers.add(found.get(0)); + } + } + } } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 68da1854..c8d6e4db 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -276,4 +276,8 @@ AddItem=Přidat položku RemoveItem=Smazat Amount=Částka - \ No newline at end of file + +WorkgroupFormUserIsCenterMember=Uživatel je členem střediska, jehož je komise členem! +WorkgroupFormMemberIsCenterMember=Některý ze členů přidávané komise je členem tohoto střediska! +WorkgroupFormCannotAddUser=Uživatele nelze přidat +WorkgroupFormCannotAddWorkgroup=Komisi nelze přidat diff --git a/src/main/webapp/admin/workgroups/workgroupForm.zul b/src/main/webapp/admin/workgroups/workgroupForm.zul index 062ea08c..29f50d90 100644 --- a/src/main/webapp/admin/workgroups/workgroupForm.zul +++ b/src/main/webapp/admin/workgroups/workgroupForm.zul @@ -30,18 +30,20 @@