From cf6c523698ca6e2f93cc30e71b0df36897860726 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 7 Jan 2015 17:03:58 +0100 Subject: [PATCH] =?UTF-8?q?Umo=C5=BEn=C4=9Bna=20deaktivace=20modulu=20pros?= =?UTF-8?q?t=C5=99ednictv=C3=ADm=20nastaven=C3=AD=20objektu=20modulu=20ve?= =?UTF-8?q?=20t=C5=99=C3=ADd=C4=9B=20Constants.=20Polo=C5=BEku=20neaktivn?= =?UTF-8?q?=C3=ADho=20modulu=20v=20menu=20lze=20skr=C3=BDt=20funkc=C3=AD?= =?UTF-8?q?=20isActive=20definovanou=20v=20module.tld=20(viz=20mainMenu.zu?= =?UTF-8?q?l).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/AppInitListener.java | 3 ++ src/main/java/info/bukova/isspst/Module.java | 30 +++++++++++++ .../java/info/bukova/isspst/ModuleUtils.java | 45 +++++++++++++++++++ .../isspst/services/AbstractService.java | 38 ++++++++++++---- .../services/ModuleNotActiveException.java | 14 ++++++ .../java/info/bukova/isspst/ui/ErrorVM.java | 42 +++++++++++++++++ .../isspst/ui/settings/NumberSeriesVM.java | 12 ++--- .../isspst/ui/users/PermissionForm.java | 5 +-- .../isspst/ui/users/PermissionsList.java | 15 +++---- .../bukova/isspst/ui/users/UsersList.java | 20 ++++----- .../WEB-INF/locales/zk-label.properties | 5 +++ src/main/webapp/WEB-INF/module.tld | 17 +++++++ src/main/webapp/WEB-INF/web.xml | 5 +++ src/main/webapp/app/mainMenu.zul | 4 +- src/main/webapp/error.zul | 8 ++++ src/main/webapp/errorWindow.zul | 12 +++++ 16 files changed, 239 insertions(+), 36 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/ModuleUtils.java create mode 100644 src/main/java/info/bukova/isspst/services/ModuleNotActiveException.java create mode 100644 src/main/java/info/bukova/isspst/ui/ErrorVM.java create mode 100644 src/main/webapp/WEB-INF/module.tld create mode 100644 src/main/webapp/error.zul create mode 100644 src/main/webapp/errorWindow.zul diff --git a/src/main/java/info/bukova/isspst/AppInitListener.java b/src/main/java/info/bukova/isspst/AppInitListener.java index 1f9a3e73..d46d105c 100644 --- a/src/main/java/info/bukova/isspst/AppInitListener.java +++ b/src/main/java/info/bukova/isspst/AppInitListener.java @@ -200,6 +200,9 @@ public class AppInitListener implements ServletContextListener { private void checkPermissions() { for (Module m : Constants.MODULES) { + if (!m.isDefaultPermissions()) { + continue; + } for (Permission p : Constants.DEF_PERMISSIONS) { if (permService.getPermissionByModule(m.getId(), p.getAuthority()) == null) { p.setModule(m.getId()); diff --git a/src/main/java/info/bukova/isspst/Module.java b/src/main/java/info/bukova/isspst/Module.java index 86ee6d63..eeda73e8 100644 --- a/src/main/java/info/bukova/isspst/Module.java +++ b/src/main/java/info/bukova/isspst/Module.java @@ -11,6 +11,8 @@ public class Module { private String name; private Class serviceClass; private List reports; + private boolean defaultPermissions; + private boolean active; public Class getServiceClass() { return serviceClass; @@ -25,6 +27,18 @@ public class Module { this.name = name; this.serviceClass = serviceClass; reports = new ArrayList(); + defaultPermissions = true; + active = true; + } + + public Module(String id, String name, Class serviceClass, boolean active) { + this(id, name, serviceClass); + this.active = active; + } + + public Module(String id, String name, Class serviceClass, boolean active, boolean defaultPermissions) { + this(id, name, serviceClass, active); + this.defaultPermissions = defaultPermissions; } public String getId() { @@ -51,4 +65,20 @@ public class Module { this.reports.add(report); } + public boolean isDefaultPermissions() { + return defaultPermissions; + } + + public void setDefaultPermissions(boolean defaultPermissions) { + this.defaultPermissions = defaultPermissions; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + } diff --git a/src/main/java/info/bukova/isspst/ModuleUtils.java b/src/main/java/info/bukova/isspst/ModuleUtils.java new file mode 100644 index 00000000..f527063b --- /dev/null +++ b/src/main/java/info/bukova/isspst/ModuleUtils.java @@ -0,0 +1,45 @@ +package info.bukova.isspst; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ModuleUtils { + + public static List getActiveModules() { + List modules = new ArrayList(); + + for (Module m : Arrays.asList(Constants.MODULES)) { + if (m.isActive()) { + modules.add(m); + } + } + + return modules; + } + + public static Module getModule(Class serviceClass) { + for (Module m : Constants.MODULES) { + if (Arrays.asList(serviceClass.getInterfaces()).contains(m.getServiceClass())) { + return m; + } + } + + return null; + } + + public static Module getModule(String id) { + for (Module m : Constants.MODULES) { + if (m.getId().equals(id)) { + return m; + } + } + + return null; + } + + public static boolean isActive(String id) { + return getModule(id).isActive(); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 5289e9e2..ac74c11f 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -1,8 +1,8 @@ package info.bukova.isspst.services; import static ch.lambdaj.Lambda.filter; -import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.SessionData; import info.bukova.isspst.dao.BaseDao; import info.bukova.isspst.dao.QueryDao; @@ -73,6 +73,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + validate(entity); entity.setCreated(new Date()); dao.add(entity); @@ -86,6 +90,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + validate(entity); entity.setModified(new Date()); dao.modify(entity); @@ -99,6 +107,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + dao.delete(entity); } @@ -137,6 +149,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + return dao.getById(id); } @@ -148,6 +164,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + return dao.getAll(); } @@ -159,6 +179,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + return dao.execQuery(query); } @@ -171,6 +195,10 @@ public abstract class AbstractService implements Service throw new IsspstException("DAO is null"); } + if (getModule() != null && !getModule().isActive()) { + throw new ModuleNotActiveException(); + } + try { Query q = dao.getQuery(query); return (T) q.uniqueResult(); @@ -189,13 +217,7 @@ public abstract class AbstractService implements Service @Override public Module getModule() { - for (Module m : Constants.MODULES) { - if (Arrays.asList(this.getClass().getInterfaces()).contains(m.getServiceClass())) { - return m; - } - } - - return null; + return ModuleUtils.getModule(this.getClass()); } public List getReports() { diff --git a/src/main/java/info/bukova/isspst/services/ModuleNotActiveException.java b/src/main/java/info/bukova/isspst/services/ModuleNotActiveException.java new file mode 100644 index 00000000..8b006559 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/ModuleNotActiveException.java @@ -0,0 +1,14 @@ +package info.bukova.isspst.services; + +public class ModuleNotActiveException extends IsspstException { + + /** + * + */ + private static final long serialVersionUID = -1219763294556500698L; + + public ModuleNotActiveException() { + super("Module deactivated"); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/ErrorVM.java b/src/main/java/info/bukova/isspst/ui/ErrorVM.java new file mode 100644 index 00000000..37fc3735 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/ErrorVM.java @@ -0,0 +1,42 @@ +package info.bukova.isspst.ui; + +import info.bukova.isspst.StringUtils; +import info.bukova.isspst.services.ModuleNotActiveException; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.Executions; + +public class ErrorVM { + + private String message; + private final Logger logger = LoggerFactory.getLogger(ErrorVM.class); + + @Init + public void init() { + HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); + Throwable ex = (Throwable) request.getAttribute("javax.servlet.error.exception"); + Throwable root = ex; + + if (root != null) { + while (root.getCause() != null) { + root = root.getCause(); + } + + if (root instanceof ModuleNotActiveException) { + message = StringUtils.localize("ModuleNotActive"); + } else { + logger.error("Unhandled exception", ex); + message = ex.toString(); + } + } + } + + public String getMessage() { + return message; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/settings/NumberSeriesVM.java b/src/main/java/info/bukova/isspst/ui/settings/NumberSeriesVM.java index 7e739c1a..73df521f 100644 --- a/src/main/java/info/bukova/isspst/ui/settings/NumberSeriesVM.java +++ b/src/main/java/info/bukova/isspst/ui/settings/NumberSeriesVM.java @@ -1,5 +1,10 @@ package info.bukova.isspst.ui.settings; +import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; +import info.bukova.isspst.data.NumberSeries; +import info.bukova.isspst.services.numberseries.NumberSeriesService; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -11,11 +16,6 @@ import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; -import info.bukova.isspst.Constants; -import info.bukova.isspst.Module; -import info.bukova.isspst.data.NumberSeries; -import info.bukova.isspst.services.numberseries.NumberSeriesService; - public class NumberSeriesVM { @WireVariable @@ -27,7 +27,7 @@ public class NumberSeriesVM { public void init() { numberSeriesList = new ArrayList(numericSeriesService.getAll()); moduleMap = new HashMap(); - for (Module m : Constants.MODULES) { + for (Module m : ModuleUtils.getActiveModules()) { moduleMap.put(m.getId(), m); } } diff --git a/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java b/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java index 6a4f14b6..2befc469 100644 --- a/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java +++ b/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java @@ -1,7 +1,7 @@ package info.bukova.isspst.ui.users; -import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Workgroup; @@ -10,7 +10,6 @@ import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.ui.FormViewModel; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.zkoss.bind.annotation.Init; @@ -47,7 +46,7 @@ public class PermissionForm extends FormViewModel { } public List getModules() { - return Arrays.asList(Constants.MODULES); + return ModuleUtils.getActiveModules(); } public RolePermissions getRolePerms() { diff --git a/src/main/java/info/bukova/isspst/ui/users/PermissionsList.java b/src/main/java/info/bukova/isspst/ui/users/PermissionsList.java index fe4a8509..79b7b9dd 100644 --- a/src/main/java/info/bukova/isspst/ui/users/PermissionsList.java +++ b/src/main/java/info/bukova/isspst/ui/users/PermissionsList.java @@ -1,17 +1,16 @@ package info.bukova.isspst.ui.users; -import java.util.Arrays; -import java.util.List; - -import org.zkoss.bind.annotation.Init; -import org.zkoss.zk.ui.select.annotation.WireVariable; - -import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.data.Role; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.ui.ListViewModel; +import java.util.List; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + public class PermissionsList extends ListViewModel { @WireVariable @@ -25,7 +24,7 @@ public class PermissionsList extends ListViewModel { } public List getModules() { - return Arrays.asList(Constants.MODULES); + return ModuleUtils.getActiveModules(); } } diff --git a/src/main/java/info/bukova/isspst/ui/users/UsersList.java b/src/main/java/info/bukova/isspst/ui/users/UsersList.java index 4b13cf27..ac42f6f8 100644 --- a/src/main/java/info/bukova/isspst/ui/users/UsersList.java +++ b/src/main/java/info/bukova/isspst/ui/users/UsersList.java @@ -1,16 +1,8 @@ package info.bukova.isspst.ui.users; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -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; - import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; @@ -18,6 +10,14 @@ import info.bukova.isspst.filters.UserFilter; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.ui.ListViewModel; +import java.util.ArrayList; +import java.util.List; + +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; + public class UsersList extends ListViewModel { @WireVariable @@ -32,7 +32,7 @@ public class UsersList extends ListViewModel { } public List getModules() { - return Arrays.asList(Constants.MODULES); + return ModuleUtils.getActiveModules(); } @Override diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 93457367..e920cc65 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -356,3 +356,8 @@ WorkgroupFormCannotAddUser=Uživatele nelze přidat WorkgroupFormCannotAddWorkgroup=Komisi nelze přidat WorkgroupFormOrderLimit=Limit nákupů WorkgroupIsInWorkgroup=Komisi nelze smazat, protože je členem některého střediska + +Help=Příručka +GoogleDriveUrl=Odkaz na Google Drive + +ModuleNotActive=Modul není aktivovaný diff --git a/src/main/webapp/WEB-INF/module.tld b/src/main/webapp/WEB-INF/module.tld new file mode 100644 index 00000000..55ba7a11 --- /dev/null +++ b/src/main/webapp/WEB-INF/module.tld @@ -0,0 +1,17 @@ + + + + + Methods and actions for ZK + application modules + + + + isActive + info.bukova.isspst.ModuleUtils + boolean isActive(java.lang.String id) + + + Return true if module represented by id is active. + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index da4c395b..3939089e 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -186,6 +186,11 @@ springSecurityFilterChain /* + + + java.lang.Throwable + /error.zul + index.zul diff --git a/src/main/webapp/app/mainMenu.zul b/src/main/webapp/app/mainMenu.zul index 91bfcf0d..415347fe 100644 --- a/src/main/webapp/app/mainMenu.zul +++ b/src/main/webapp/app/mainMenu.zul @@ -1,6 +1,7 @@ + + disabled="${not sec:isAllGranted('PERM_READ_INVOICING')}" + visible="${module:isActive('INVOICING') }" /> diff --git a/src/main/webapp/error.zul b/src/main/webapp/error.zul new file mode 100644 index 00000000..f8629569 --- /dev/null +++ b/src/main/webapp/error.zul @@ -0,0 +1,8 @@ + + + + String gridZul = "/errorWindow.zul"; + + + + \ No newline at end of file diff --git a/src/main/webapp/errorWindow.zul b/src/main/webapp/errorWindow.zul new file mode 100644 index 00000000..eb51272d --- /dev/null +++ b/src/main/webapp/errorWindow.zul @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file