Umožněna deaktivace modulu prostřednictvím nastavení objektu modulu ve

třídě Constants. Položku neaktivního modulu v menu lze skrýt funkcí
isActive definovanou v module.tld (viz mainMenu.zul).
Verze_2.0
Josef Rokos 10 years ago
parent b1818546c0
commit cf6c523698

@ -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());

@ -11,6 +11,8 @@ public class Module {
private String name;
private Class<?> serviceClass;
private List<Report> 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<Report>();
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;
}
}

@ -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<Module> getActiveModules() {
List<Module> modules = new ArrayList<Module>();
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();
}
}

@ -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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
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<T extends DataModel> implements Service<T>
@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<Report> getReports() {

@ -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");
}
}

@ -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;
}
}

@ -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<NumberSeries>(numericSeriesService.getAll());
moduleMap = new HashMap<String, Module>();
for (Module m : Constants.MODULES) {
for (Module m : ModuleUtils.getActiveModules()) {
moduleMap.put(m.getId(), m);
}
}

@ -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<Role> {
}
public List<Module> getModules() {
return Arrays.asList(Constants.MODULES);
return ModuleUtils.getActiveModules();
}
public RolePermissions getRolePerms() {

@ -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<Role> {
@WireVariable
@ -25,7 +24,7 @@ public class PermissionsList extends ListViewModel<Role> {
}
public List<Module> getModules() {
return Arrays.asList(Constants.MODULES);
return ModuleUtils.getActiveModules();
}
}

@ -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<User> {
@WireVariable
@ -32,7 +32,7 @@ public class UsersList extends ListViewModel<User> {
}
public List<Module> getModules() {
return Arrays.asList(Constants.MODULES);
return ModuleUtils.getActiveModules();
}
@Override

@ -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ý

@ -0,0 +1,17 @@
<!DOCTYPE xml>
<taglib>
<uri></uri>
<description>
Methods and actions for ZK + application modules
</description>
<function>
<name>isActive</name>
<function-class>info.bukova.isspst.ModuleUtils</function-class>
<function-signature> boolean isActive(java.lang.String id)
</function-signature>
<description>
Return true if module represented by id is active.
</description>
</function>
</taglib>

@ -187,6 +187,11 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.zul</location>
</error-page>
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
<welcome-file>index.zhtml</welcome-file>

@ -1,6 +1,7 @@
<?page title="Main Menu" contentType="text/html;charset=UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?taglib uri="/WEB-INF/security.tld" prefix="sec"?>
<?taglib uri="/WEB-INF/module.tld" prefix="module"?>
<zk xmlns:n="native">
<menubar
id="menubar"
@ -39,7 +40,8 @@
image="/img/invoicing-016.png"
label="${labels.Invoicing}"
href="/main/invoicing/"
disabled="${not sec:isAllGranted('PERM_READ_INVOICING')}" />
disabled="${not sec:isAllGranted('PERM_READ_INVOICING')}"
visible="${module:isActive('INVOICING') }" />
</menupopup>
</menu>
<menu label="${labels.BussinessTrips}">

@ -0,0 +1,8 @@
<?page title="${labels.Error}" contentType="text/html;charset=UTF-8"?>
<zk>
<zscript>
String gridZul = "/errorWindow.zul";
</zscript>
<include src="/app/template.zhtml"/>
</zk>

@ -0,0 +1,12 @@
<?page title="${labels.Error}" contentType="text/html;charset=UTF-8"?>
<zk>
<window border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.ErrorVM')"
vflex="1">
<caption zclass="form-caption" label="${labels.Error}" />
<label value="@load(vm.message)"/>
</window>
</zk>
Loading…
Cancel
Save