Package at.riemers.zero.base.controller

Examples of at.riemers.zero.base.controller.ZeroView


    @RequestMapping(value = "/user/roleList.do", method = RequestMethod.GET)
    public ModelAndView roleList(HttpServletRequest request, HttpSession session) throws Exception {
        log.debug("RoleListAction");

        long s = System.currentTimeMillis();
        ZeroView view = new ZeroView(getMessages(), request.getLocale());
        User user = getUser();
        logFunction("user-rolelist");
        if (user.checkAuthorisation(UserModule.AUTH_USER)) {

            view.addWidget(new SimpleWidget(ZeroView.DIV_CONTENT, "user_rolelist"));

            FormWidget filter = (FormWidget) getWidgetManager(session).getWidget("ROLELIST_FILTER");           
            if (filter == null) {
                filter = new FormWidget("ROLELIST_FILTER", getLocale(request));
                filter.setColumnCount(2);
                filter.setShowLabelAtTop(true);
                filter.addField(new StringField("name", "base.user.table.name", ""));
               
                ComboBoxField groupField = new ComboBoxField("userGroup", "base.user.label.usergroupkey", "");

                groupField.addOption("", "*");
                for (UserGroup userGroup : getUserGroups()) {
                    groupField.addOption(userGroup.getId(), userGroup.getGroupKey());
                }

                filter.addField(groupField);
                filter.setForm("RoleFilterForm");
                getWidgetManager(session).register(filter);
            }
            view.addWidget(filter);

            HtmlTableWidget roleWidget = (HtmlTableWidget) getWidgetManager(session).getWidget("ROLELIST");
            if (roleWidget == null) {
                DefaultTableModelColumn nameColumn = new DefaultTableModelColumn("base.user.table.rolename", "name");
                nameColumn.setStyleClass("emphasize");
                /* usernameColumn.addClickListener(new TableClickListener() {
               
                public void fireClicked(TableClickEvent event) {
                log.debug("fireClicked: " + event.getWidget().getModel().getData(event.getColumn(), event.getRow()));
                }
                });*/
                RoleTableModel model = new RoleTableModel(getRoles(user), getMessages(), request.getLocale());

                if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
                    model.setSelectable(true);
                    DefaultTableModelColumn editColumn = new DefaultTableModelColumn("", "");
                    editColumn.setRenderer(new TableColumnRenderer() {

                        public String getTemplate() {
                            return "v2js_widgets_tablelink";
                        }

                        public Object getData(Object obj) {
                            if (obj instanceof Role) {
                                JSONObject jLink = new JSONObject();
                                jLink.element("url", "user/roleEdit.do?selected=" + ((Role) obj).getId());
                                jLink.element("text", "Edit");
                                return jLink;
                            }
                            return "";
                        }
                    });
                    model.addColumn(editColumn);

                }

                model.addColumn(nameColumn);
                model.addColumn(new DefaultTableModelColumn("base.user.label.usergroupkey", "userGroup.groupKey"));

                model.setSort(1);
                roleWidget = new HtmlTableWidget("ROLELIST", model);
                roleWidget.setRowsPerPage(20);

                getWidgetManager(session).register(roleWidget);
            } else {
                ((RoleTableModel) roleWidget.getModel()).setCollection(getRoles(user));
            }

            view.addWidget(roleWidget);

            if (user.checkAuthorisation(UserModule.AUTH_ROLE_EDIT)) {
                view.getJson().element("edit", true);
            }
        }
        log.debug("role list: " + (System.currentTimeMillis() - s));
        return new ModelAndView(view, null);
    }
View Full Code Here


    @RequestMapping(value = "/user/roleAddPermission.do", method = RequestMethod.POST)
    public ModelAndView addPermission(
            @ModelAttribute("selected") Selected selected,
            HttpSession session,
            HttpServletRequest request) throws Exception {
        ZeroView view = new ZeroView(getMessages(), request.getLocale());

        User user = getUser();
        if (user.checkAuthorisation(UserModule.AUTH_ROLE_EDIT)) {


            Set<Permission> permissions = (Set<Permission>) session.getAttribute("permissions");
            try {
                for (String key : selected.getSelected().keySet()) {
                    log.info("key: " + key);
                    PermissionTemplate permissionTemplate = getModuleManager().getPermissionTemplate(key);

                    if (permissionTemplate != null) {
                        Permission permission = permissionTemplate.createPermission();
                        permissions.add(permission);
                    } else {
                        log.warn("permission not found");
                    }
                }
            } catch (Exception ex) {
                log.error("getPermission", ex);
            }


            Role role = new Role();
            role.setPermissions(permissions);
            view.getJson().element("role", UserJSONizer.createRole(role, getModuleManager()));
            view.addWidget(new SimpleWidget("role_tabs", "user_roleEdit_tabs"));


        }

        return new ModelAndView(view, null);
View Full Code Here

    @RequestMapping(value = "/user/roleRemovePermission.do", method = RequestMethod.POST)
    public ModelAndView removePermission(
            @ModelAttribute("selected") Selected selected,
            HttpSession session,
            HttpServletRequest request) throws Exception {
        ZeroView view = new ZeroView(getMessages(), request.getLocale());

        User user = getUser();
        if (user.checkAuthorisation(UserModule.AUTH_ROLE_EDIT)) {

            Set<Permission> permissions = (Set<Permission>) session.getAttribute("permissions");

            try {
                for (String key : selected.getSelected().keySet()) {
                    log.info("key: " + key);

                    PermissionTemplate permissionTemplate = getModuleManager().getPermissionTemplate(key);

                    if (permissionTemplate != null) {
                        for (Permission p : new ArrayList<Permission>(permissions)) {
                            if (p.getKey().equals(permissionTemplate.getKey())) {
                                permissions.remove(p);
                            }
                        }
                    } else {
                        log.warn("permission not found");
                    }
                }
            } catch (Exception ex) {
                log.error("getPermission", ex);
            }

            Role role = new Role();

            role.setPermissions(permissions);
            view.getJson().element("role", UserJSONizer.createRole(role, getModuleManager()));
            view.addWidget(new SimpleWidget("role_tabs", "user_roleEdit_tabs"));

        }

        return new ModelAndView(view, null);
    }
View Full Code Here

    public ModelAndView edit(
            @RequestParam("selected") String selected,
            HttpSession session,
            HttpServletRequest request) throws Exception {

        ZeroView view = new ZeroView(getMessages(), request.getLocale());
        log.debug("EditRoleAction");

        User user = getUser();
        if (user.checkAuthorisation(UserModule.AUTH_USER)) {

            session.setAttribute(SESSION_ROLE_TRANSACTION, new RoleTransaction());
            Role role = null;
            if (selected.equals("")) {
                log.debug("create role");
                role = new Role();
                session.removeAttribute(SESSION_ROLE_SELECTEDROLE);
            } else {
                role = roleDao.findById(selected);
                session.setAttribute(SESSION_ROLE_SELECTEDROLE, role.getId());
            }


            session.setAttribute("permissions", role.getPermissions());

            view.addWidget(new SimpleWidget(ZeroView.DIV_CONTENT, "user_roleEdit"));

            view.getJson().element("role", UserJSONizer.createRole(role, getModuleManager()));


            JSONArray jUserGroups = new JSONArray();
            view.getJson().element("userGroups", jUserGroups);

            Collection<Role> roles = user.getRoles(UserModule.AUTH_USER);
            Set<UserGroup> userGroups = new HashSet<UserGroup>();
            for (Role r : roles) {
                if (r.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
View Full Code Here

            @ModelAttribute("roleForm") RoleForm roleForm,
            HttpSession session,
            HttpServletRequest request) throws Exception {
        log.debug("SAVEROLE");

        ZeroView view = new ZeroView(getMessages(), request.getLocale());
        User user = getUser();
        logFunction("user-roleedit");
        if (user.checkAuthorisation(UserModule.AUTH_ROLE_EDIT)) {


            String roleId = (String) session.getAttribute(SESSION_ROLE_SELECTEDROLE);

            Role role = null;
            if (roleId != null) {
                try {
                    role = roleDao.findById(roleId, true);
                } catch (Exception e) {
                }
            }

            if (role == null) {
                role = new Role();
            }

            role.setName(roleForm.getName());

            if (roleForm.getUserGroup().equals("")) {
                role.setUserGroup(null);
            } else {
                UserGroup userGroup = userGroupDao.getUserGroup(roleForm.getUserGroup());
                role.setUserGroup(userGroup);
            }


            Set<Permission> permissions = (Set<Permission>) session.getAttribute("permissions");
            // add new permissions
            for (Permission p : permissions) {
                if (role.getPermission(p.getKey()) == null) {
                    log.debug("add permission");
                    role.addPermission(p);
                } else {
                    role.getPermission(p.getKey()).setValue(p.getValue());
                }
            }
            // remove deleted permissions
            for (Permission p : new ArrayList<Permission>(role.getPermissions())) {
                if (!permissions.contains(p)) {
                    log.debug("remove permission");
                    role.removePermission(p);
                }
            }


            boolean error = false;
            for (String permissionKey : roleForm.getValues().keySet()) {
                Permission permission = role.getPermission(permissionKey);
                if (permission != null) {
                    PermissionTemplate permissionTemplate = getModuleManager().getPermissionTemplate(permissionKey);
                    if (permissionTemplate != null) {
                        String value = roleForm.getValues().get(permissionKey);
                        if (permissionTemplate.isValuePermission()) {
                            if (permissionTemplate.checkValue(value)) {
                                permission.setValue(value);
                            } else {
                                if (permissionTemplate.getValueRangeMessage() != null) {
                                    view.setMessage(permissionTemplate.getValueRangeMessage());
                                    error = true;
                                }
                            }
                        }
                    }
View Full Code Here

    public ModelAndView delete(
            @ModelAttribute("selected") Selected selected,
            HttpSession session,
            HttpServletRequest request) throws Exception {
        log.debug("delete role");
        ZeroView view = new ZeroView(getMessages(), request.getLocale());
        User user = getUser();

        if (user.checkAuthorisation(UserModule.AUTH_ROLE_EDIT)) {

            for (String roleName : selected.getSelected().keySet()) {
View Full Code Here

    }

    @RequestMapping(value = "/user/roleFilter.do", method = RequestMethod.POST)
    public ModelAndView filter(@ModelAttribute("RoleFilterForm") Form form, BindingResult result, SessionStatus status, HttpSession session, HttpServletRequest request) throws Exception {

        ZeroView view = new ZeroView(getMessages(), request.getLocale());
        log.debug("filter User");

        User user = getUser();

        if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {
View Full Code Here

    @RequestMapping(value = "/user/rolePermissionList.do", method = RequestMethod.GET)
    public ModelAndView list(HttpSession session,
            HttpServletRequest request) throws Exception {
        log.debug("permissionList");

        ZeroView view = new ZeroView(getMessages(), request.getLocale());

        User user = getUser();

        if (user.checkAuthorisation(UserModule.AUTH_USER_EDIT)) {

            view.addWidget(new PopupWidget("user_permissionlist_select", "base.user.select_permission", PopupWidget.TYPE_SAVE));

            JSONArray jmodules = new JSONArray();
            view.getJson().element("modules", jmodules);
            for (Module module : getModuleManager().getModules()) {
                JSONObject jmodule = new JSONObject();
                jmodules.element(jmodule);
                jmodule.element("name", module.getName());
                JSONArray jpermissions = new JSONArray();
                jmodule.element("permissions", jpermissions);
                List<PermissionTemplate> templates = module.getPermissionTemplates();
                Collections.sort(templates);
                for (PermissionTemplate permissionTemplate : templates) {
                    JSONObject jPermission = new JSONObject();
                    jpermissions.element(jPermission);
                    jPermission.element("key", permissionTemplate.getKey());
                    jPermission.element("name", permissionTemplate.getName());
                    jPermission.element("highlight", permissionTemplate.isHighlight());
                    String code = "permissioninfo_" + permissionTemplate.getKey().toLowerCase();
                    jPermission.element("description", getMessages().getMessage(code, null, getLocale(request)));

                }
            }

            view.getJson().element("funcSelect", "user/roleAddPermission.do");
            view.getJson().element("selectName", "Add");


        }

        return new ModelAndView(view, null);
View Full Code Here

    @RequestMapping(value="/user/statistic.do", method = RequestMethod.GET)   
    public ModelAndView statistic(HttpSession session, HttpServletRequest request) throws Exception {
        log.debug("user statistic action");
        User user = getUser();
       
        ZeroView view = new ZeroView(getMessages(), request.getLocale());
               
        view.addWidget(new SimpleWidget(ZeroView.DIV_CONTENT, "user_userstatistic"));           
        view.addWidget(new SimpleWidget("functions", "user_userstatistic_func"));           
       
        return new ModelAndView(view, null);
    }
View Full Code Here

        log.debug("user statistic action");
                       
        User user = getUser();
       
        logFunction("user-statistic");
        ZeroView view = new ZeroView(getMessages(), request.getLocale());
              
        view.addWidget(new SimpleWidget(ZeroView.DIV_CONTENT, "user_userstatistic"));           
      
        //view.addCall("v2js_userstatistic_func", "functions");     
       
        List<FunctionLog> logs = getFunctionLogDao().getLogs(statisticForm.getYear(), statisticForm.getFunction(), statisticForm.getUser(), statisticForm.getUserGroup());
       
        Set<String> columns = new HashSet<String>();
        Map<String, Integer> count = new HashMap<String, Integer>();
       
        Calendar c = Calendar.getInstance();
        for(FunctionLog log : logs) {
            String column = "";
           
            switch (statisticForm.getType()) {
                case 1: column = log.getUser().getUsername();
                break;
                case 2: if(log.getUser().getUserGroup()!=null) column = log.getUser().getUserGroup().getGroupKey();
                else column = "no-group";
                break;
                default: column = log.getFunction();
            }
            columns.add(column);
           
            c.setTime(log.getDate());
           
            String key = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + column;
            if (count.get(key) == null) {
                count.put(key, 1);
            } else {
                count.put(key, count.get(key) + 1);
            }
        }
       
        JSONObject jchart = new JSONObject();
        JSONArray jdata = new JSONArray();
       
        int year = statisticForm.getYear();
        for(int i=0;i<12;i++) {
            JSONObject jline = new JSONObject();
            jline.element("month", i+1);
            for (String column : columns) {
                String key = year + "-" + i + "-" + column;  
                if (count.get(key)!=null) {
                    jline.element(column, count.get(key));
                } else {
                    jline.element(column, 0);
                }
            }
            jdata.element(jline);
        }       
       
        jchart.element("data", jdata);
       
        JSONArray jfields = new JSONArray();
        jfields.element("month");
        for (String column : columns) {                                                                 
            jfields.element(column);
        }
       
        jchart.element("fields", jfields);
       
        JSONArray jSeriesDef = new JSONArray();
        jchart.element("seriesDef", jSeriesDef);
        for (String column : columns) {                                                                        
            JSONObject serie = new JSONObject();       
            serie.element("displayName", column);
            serie.element("yField", column);
            jSeriesDef.element(serie);
        }
       
       
        view.getJson().element("chart", jchart);
        view.addWidget(new JavascriptWidget("zero_chart"));                   
        return new ModelAndView(view, null);
    }
View Full Code Here

TOP

Related Classes of at.riemers.zero.base.controller.ZeroView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.