From 53d5d262b184796f88104349d93b5eabafe857e3 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 16 Jun 2014 20:47:29 +0200 Subject: [PATCH] =?UTF-8?q?Dolad=C4=9Bno=20UI=20agendy=20na=20definici=20s?= =?UTF-8?q?t=C5=99edisek=20a=20komis=C3=AD.=20closes=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/data/JobMapping.java | 5 ++ .../java/info/bukova/isspst/data/Member.java | 2 +- .../java/info/bukova/isspst/data/User.java | 2 +- .../info/bukova/isspst/data/Workgroup.java | 9 ++- .../isspst/filters/WorkgroupFilter.java | 56 +++++++++++++++++++ .../workgroups/WorkgroupException.java | 1 + .../workgroups/WorkgroupServiceImpl.java | 45 ++++++++++++++- .../info/bukova/isspst/ui/BoolConverter.java | 21 +++++++ .../isspst/ui/workgroups/WorkgroupForm.java | 27 +++++---- .../isspst/ui/workgroups/WorkgroupList.java | 25 +++++++++ .../ui/workgroups/WorkgroupTreeFactory.java | 2 +- .../webapp/WEB-INF/locales/columns.properties | 6 +- .../WEB-INF/locales/zk-label.properties | 5 +- src/main/webapp/admin/workgroups/index.zul | 2 +- .../webapp/admin/workgroups/workgroupForm.zul | 40 +++++++++++-- .../webapp/admin/workgroups/workgroups.zul | 46 +++------------ 16 files changed, 231 insertions(+), 63 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java create mode 100644 src/main/java/info/bukova/isspst/ui/BoolConverter.java diff --git a/src/main/java/info/bukova/isspst/data/JobMapping.java b/src/main/java/info/bukova/isspst/data/JobMapping.java index eebf4b1e..7de91e9f 100644 --- a/src/main/java/info/bukova/isspst/data/JobMapping.java +++ b/src/main/java/info/bukova/isspst/data/JobMapping.java @@ -68,4 +68,9 @@ public class JobMapping { return false; } + @Override + public String toString() { + return this.getMember() + " - " + this.getRole().getDescription(); + } + } diff --git a/src/main/java/info/bukova/isspst/data/Member.java b/src/main/java/info/bukova/isspst/data/Member.java index bb812b58..b2538a7f 100644 --- a/src/main/java/info/bukova/isspst/data/Member.java +++ b/src/main/java/info/bukova/isspst/data/Member.java @@ -26,7 +26,7 @@ public abstract class Member implements DataModel { private boolean valid; public abstract String getFullName(); - public abstract boolean isHasJob(); + public abstract boolean isPerson(); public int getId() { return id; diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index 9f8db047..c7cf88fb 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -192,7 +192,7 @@ public class User extends Member implements UserDetails, DataModel { } @Override - public boolean isHasJob() { + public boolean isPerson() { return true; } diff --git a/src/main/java/info/bukova/isspst/data/Workgroup.java b/src/main/java/info/bukova/isspst/data/Workgroup.java index 4d794647..7a2d7bef 100644 --- a/src/main/java/info/bukova/isspst/data/Workgroup.java +++ b/src/main/java/info/bukova/isspst/data/Workgroup.java @@ -90,11 +90,11 @@ public class Workgroup extends Member implements OwnedDataModel { @Override public String getFullName() { - return name; + return code + " " + name; } @Override - public boolean isHasJob() { + public boolean isPerson() { return false; } @@ -121,5 +121,10 @@ public class Workgroup extends Member implements OwnedDataModel { } return false; } + + @Override + public String toString() { + return getFullName(); + } } diff --git a/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java b/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java new file mode 100644 index 00000000..ec8571d3 --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java @@ -0,0 +1,56 @@ +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Workgroup; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class WorkgroupFilter implements Filter { + + private Workgroup condWorkgroup; + + public WorkgroupFilter(Workgroup condWorkgroup) { + this.condWorkgroup = condWorkgroup; + } + + private static class WorkgroupMatcher extends TypeSafeMatcher { + + private Workgroup condWorkgroup; + + public WorkgroupMatcher(Workgroup cond) { + this.condWorkgroup = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("material matches"); + } + + @Override + public boolean matchesSafely(Workgroup item) { + return nullStr(item.getCode()).toLowerCase().contains(nullStr(condWorkgroup.getCode()).toLowerCase()) + && nullStr(item.getName()).toLowerCase().contains(nullStr(condWorkgroup.getName()).toLowerCase()) + && item.isCentre() == condWorkgroup.isCentre(); + } + + @Factory + public static Matcher matchBuilding(Workgroup material) { + return new WorkgroupMatcher(material); + } + } + + @Override + public WorkgroupMatcher matcher() { + return new WorkgroupMatcher(condWorkgroup); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java index 5aac8c29..6b588f38 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java @@ -12,6 +12,7 @@ public class WorkgroupException extends IsspstException { public final static String NO_WORGROUP = "WorkgroupNotAllowed"; public final static String MSUT_HAS_CENTER = "RoleMustHasCentre"; public final static String MUST_HAS_WORKGROUP = "WorkgroupMustHasCentre"; + public final static String CYCLIC_MEMBER = "CyclicMembership"; public WorkgroupException(String message) { super(message); 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 2ed066cd..401fad8b 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -15,7 +15,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem @Override public void addMember(Workgroup workgroup, Member member, Role role) { - if (!member.isHasJob() && !role.getAuthority().equals(Constants.ROLE_USER)) { + if (!member.isPerson() && !role.getAuthority().equals(Constants.ROLE_USER)) { throw new WorkgroupException(WorkgroupException.NO_WORGROUP); } if (workgroup.isCentre() && !role.isCentre()) { @@ -25,6 +25,14 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem throw new WorkgroupException(WorkgroupException.MUST_HAS_WORKGROUP); } + if (!checkGroups(workgroup, member)) { + throw new WorkgroupException(WorkgroupException.CYCLIC_MEMBER); + } + + if (!member.isPerson() && !checkGroups((Workgroup)member, workgroup)) { + throw new WorkgroupException(WorkgroupException.CYCLIC_MEMBER); + } + JobMapping mapping = new JobMapping(member, role); if (!workgroup.getMembers().contains(mapping)) { workgroup.getMembers().add(mapping); @@ -53,5 +61,40 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem return false; } + + private boolean checkGroups(Workgroup workgroup, Member member) { + if (member.equals(workgroup)) { + return false; + } + + if (member.isPerson()) { + return true; + } + + Workgroup toAdd = Workgroup.class.cast(member); + for (JobMapping jm : toAdd.getMembers()) { + if (!jm.getMember().isPerson() && !checkGroups(workgroup, jm.getMember())) { + return false; + } + } + + return true; + } + +/* private boolean noIntersect(Workgroup w1, Workgroup w2) { + for (JobMapping jm1 : w1.getMembers()) { + for (JobMapping jm2 : w2.getMembers()) { + if (jm1.equals(jm2)) { + return false; + } + } + } + + return true; + } + + private boolean checkIntersect() { + return true; + }*/ } diff --git a/src/main/java/info/bukova/isspst/ui/BoolConverter.java b/src/main/java/info/bukova/isspst/ui/BoolConverter.java new file mode 100644 index 00000000..4281a066 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/BoolConverter.java @@ -0,0 +1,21 @@ +package info.bukova.isspst.ui; + +import info.bukova.isspst.StringUtils; + +import org.zkoss.bind.BindContext; +import org.zkoss.bind.Converter; +import org.zkoss.zk.ui.Component; + +public class BoolConverter implements Converter { + + @Override + public Boolean coerceToBean(String str, Component component, BindContext cx) { + return false; + } + + @Override + public String coerceToUi(Boolean val, Component component, BindContext cx) { + return StringUtils.localize(val.toString()); + } + +} 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 8f8179ee..faab5096 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java @@ -35,16 +35,23 @@ public class WorkgroupForm extends FormViewModel { public void init() { users = new ArrayList(); users.addAll(userService.getAll()); - List wg = workgroupService.getWorkgroups(); - - for (Workgroup w : wg) { - if (!workgroupService.isMember(getDataBean(), w)) { - users.add(w); - } - } } public List getUsers() { + if (getDataBean().isCentre()) { + List listWithWg = new ArrayList(users); + + List wg = workgroupService.getWorkgroups(); + + for (Workgroup w : wg) { + if (!workgroupService.isMember(getDataBean(), w)) { + listWithWg.add(w); + } + } + + return listWithWg; + } + return users; } @@ -56,7 +63,7 @@ public class WorkgroupForm extends FormViewModel { } } - @NotifyChange({"workgroupRoles", "centre"}) + @NotifyChange({"workgroupRoles", "centre", "users"}) public void setCentre(boolean centre) { getDataBean().setCentre(centre); } @@ -106,7 +113,7 @@ public class WorkgroupForm extends FormViewModel { if (!target.equals("users")) { moveUser(u.getMember(), event); - } else if (!u.getMember().isHasJob()) { + } else if (!u.getMember().isPerson()) { users.add(u.getMember()); } } @@ -121,7 +128,7 @@ public class WorkgroupForm extends FormViewModel { workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target)); - if (!u.isHasJob()) { + if (!u.isPerson()) { users.remove(u); } } diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java index 6376aa95..5b4155d8 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java @@ -1,5 +1,7 @@ package info.bukova.isspst.ui.workgroups; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.GlobalCommand; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -8,7 +10,9 @@ import org.zkoss.zul.TreeNode; import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.filters.WorkgroupFilter; import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.BoolConverter; import info.bukova.isspst.ui.ListViewModel; public class WorkgroupList extends ListViewModel { @@ -16,13 +20,16 @@ public class WorkgroupList extends ListViewModel { @WireVariable private WorkgroupService workgroupService; private WorkgroupTreeFactory treeFactory; + private BoolConverter boolConverter; @Init public void init() { service = workgroupService; dataClass = Workgroup.class; formZul = "workgroupForm.zul"; + dataFilter = new WorkgroupFilter(getFilterTemplate()); treeFactory = new WorkgroupTreeFactory(); + boolConverter = new BoolConverter(); } public TreeModel> getWorkgroupTreeModel() { @@ -37,5 +44,23 @@ public class WorkgroupList extends ListViewModel { public void setDataBean(Workgroup data) { super.setDataBean(data); } + + @Override + @GlobalCommand + @NotifyChange({ "dataList", "dataBean", "workgroupTreeModel" }) + public void refresh() { + super.refresh(); + } + + @Override + @Command + @NotifyChange({ "filter", "dataList", "dataBean", "workgroupTreeModel" }) + public void filter() { + super.filter(); + } + + public BoolConverter getBoolConverter() { + return boolConverter; + } } diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java index 8538b8fd..b63969a8 100644 --- a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupTreeFactory.java @@ -25,7 +25,7 @@ public class WorkgroupTreeFactory { Workgroup workgroup = Workgroup.class.cast(member); for (JobMapping jm : workgroup.getMembers()) { - if (jm.getRole().getAuthority().equals(Constants.ROLE_USER) && jm.getMember().isHasJob()) { + if (jm.getRole().getAuthority().equals(Constants.ROLE_USER) && jm.getMember().isPerson()) { children.add(new WorkgroupTreeNode(jm.getMember())); } else if (jm.getRole().getAuthority().equals(Constants.ROLE_USER)) { children.add(new WorkgroupTreeNode(jm.getMember(), generateChildren(jm.getMember()))); diff --git a/src/main/webapp/WEB-INF/locales/columns.properties b/src/main/webapp/WEB-INF/locales/columns.properties index 31df501b..0c067f53 100644 --- a/src/main/webapp/WEB-INF/locales/columns.properties +++ b/src/main/webapp/WEB-INF/locales/columns.properties @@ -35,4 +35,8 @@ fullName=Plné jméno lastName=Příjmení notify=Posílat oznámení personalNumber=Osobní číslo -username=Uživatelské jméno \ No newline at end of file +username=Uživatelské jméno + +#Skupiny +centre=Středisko +members=Členové \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 170f86e9..c67f5645 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -87,7 +87,7 @@ UsersGridColumnSureName=Příjmení AgendaMaterial=Materiál MaterialFormTitle=Materiál -AgendaWorkgroups=Pracovní skupiny +AgendaWorkgroups=Střediska / komise WorkgroupFormTitle=Pracvní skupina ButtonStorno=Storno @@ -120,4 +120,7 @@ DbForKey= pro klíč DbCannotDelete=Chyba při mazání záznamu: Záznam nelze smazat protože na něj odkazuje jiný záznam DbSaveError=Chyba při ukládání záznamu DbValidationError=Chyba validace + +true=Ano +false=Ne \ No newline at end of file diff --git a/src/main/webapp/admin/workgroups/index.zul b/src/main/webapp/admin/workgroups/index.zul index 62ca9293..5c0612a4 100644 --- a/src/main/webapp/admin/workgroups/index.zul +++ b/src/main/webapp/admin/workgroups/index.zul @@ -1,4 +1,4 @@ - + diff --git a/src/main/webapp/admin/workgroups/workgroupForm.zul b/src/main/webapp/admin/workgroups/workgroupForm.zul index d673f18b..8e5e2958 100644 --- a/src/main/webapp/admin/workgroups/workgroupForm.zul +++ b/src/main/webapp/admin/workgroups/workgroupForm.zul @@ -24,26 +24,56 @@ - + \ No newline at end of file