Package org.joget.apps.userview.model

Examples of org.joget.apps.userview.model.Userview


        requestParameters.put("appId", appDef.getAppId());
        requestParameters.put("appVersion", appDef.getVersion().toString());

        String appId = appDef.getId();
        String appVersion = appDef.getVersion().toString();
        Userview userview = new Userview();

        try {
            //set userview properties
            JSONObject userviewObj = new JSONObject(json);
            userview.setProperties(PropertyUtil.getPropertiesValueFromJson(userviewObj.getJSONObject("properties").toString()));

            //set Setting
            JSONObject settingObj = userviewObj.getJSONObject("setting");
            UserviewSetting setting = new UserviewSetting();
            setting.setProperties(PropertyUtil.getPropertiesValueFromJson(settingObj.getJSONObject("properties").toString()));

            //set theme & permission
            try {
                JSONObject themeObj = settingObj.getJSONObject("properties").getJSONObject("theme");
                UserviewTheme theme = (UserviewTheme) pluginManager.getPlugin(themeObj.getString("className"));
                theme.setProperties(PropertyUtil.getPropertiesValueFromJson(themeObj.getJSONObject("properties").toString()));
                theme.setRequestParameters(requestParameters);
                theme.setUserview(userview);
                setting.setTheme(theme);
            } catch (Exception e) {
                LogUtil.debug(getClass().getName(), "set theme error.");
            }
            try {
                JSONObject permissionObj = settingObj.getJSONObject("properties").getJSONObject("permission");
                UserviewPermission permission = null;
                String permissionClassName = permissionObj.getString("className");
                if (permissionClassName != null && !permissionClassName.isEmpty()) {
                    permission = (UserviewPermission) pluginManager.getPlugin(permissionClassName);
                }
                if (permission != null) {
                    permission.setProperties(PropertyUtil.getPropertiesValueFromJson(permissionObj.getJSONObject("properties").toString()));
                    permission.setRequestParameters(requestParameters);
                    permission.setCurrentUser(currentUser);
                    setting.setPermission(permission);
                }
            } catch (Exception e) {
                LogUtil.debug(getClass().getName(), "set permission error.");
            }
            userview.setSetting(setting);

            //set categories
            JSONArray categoriesArray = userviewObj.getJSONArray("categories");
            Collection<UserviewCategory> categories = new ArrayList<UserviewCategory>();
            for (int i = 0; i < categoriesArray.length(); i++) {
                JSONObject categoryObj = (JSONObject) categoriesArray.get(i);

                UserviewCategory category = new UserviewCategory();
                category.setProperties(PropertyUtil.getPropertiesValueFromJson(categoryObj.getJSONObject("properties").toString()));

                boolean hasPermis = false;
                if (preview) {
                    hasPermis = true;
                } else {
                    //check for permission
                    JSONObject permissionObj = null;
                    UserviewPermission permission = null;

                    try {
                        permissionObj = categoryObj.getJSONObject("properties").getJSONObject("permission");
                        String permissionClassName = permissionObj.getString("className");
                        if (permissionClassName != null && !permissionClassName.isEmpty()) {
                            permission = (UserviewPermission) pluginManager.getPlugin(permissionClassName);
                        }
                    } catch (Exception e) {
                        LogUtil.debug(getClass().getName(), "set category permission error.");
                    }

                    if (permission != null) {
                        permission.setProperties(PropertyUtil.getPropertiesValueFromJson(permissionObj.getJSONObject("properties").toString()));
                        permission.setRequestParameters(requestParameters);
                        permission.setCurrentUser(currentUser);

                        hasPermis = permission.isAuthorize();
                    } else {
                        hasPermis = true;
                    }
                }

                if (hasPermis) {
                    //set menus
                    JSONArray menusArray = categoryObj.getJSONArray("menus");
                    Collection<UserviewMenu> menus = new ArrayList<UserviewMenu>();
                    for (int j = 0; j < menusArray.length(); j++) {
                        try {
                            //set menu
                            JSONObject menuObj = (JSONObject) menusArray.get(j);
                            UserviewMenu menu = (UserviewMenu) pluginManager.getPlugin(menuObj.getString("className"));
                           
                            // check for mobile support
                            boolean isMobileView = MobileUtil.isMobileView();
                            if (isMobileView && (menu instanceof MobileElement) && !((MobileElement)menu).isMobileSupported()) {
                                // mobile not supported, skip this menu
                                continue;
                            }
           
                            menu.setProperties(PropertyUtil.getPropertiesValueFromJson(menuObj.getJSONObject("properties").toString()));
                            menu.setRequestParameters(requestParameters);
                            menu.setUserview(userview);
                            String mId = getMenuId(menu);
                            menu.setProperty("menuId", mId);

                            if (preview) {
                                menu.setUrl(contextPath + "/web/console/app/" + appId + "/" + appVersion + "/userview/builderPreview/" + userview.getPropertyString("id") + "/" + mId);
                            } else {
                                menu.setKey(key);
                                String prefix = "/web/userview/";
                               
                                if (embed) {
                                    prefix = "/web/embed/userview/";
                                }
                               
                                menu.setUrl(contextPath + prefix + appId + "/" + userview.getPropertyString("id") + "/" + ((key != null) ? URLEncoder.encode(key, "UTF-8") : "") + "/" + mId);
                            }

                            //set Current, if current menu id is empty, search the 1st valid menu
                            if ((("".equals(menuId) || menuId == null) && userview.getCurrent() == null && menu.isHomePageSupported())
                                    || (menuId != null && menuId.equals(mId))) {
                                userview.setCurrent(menu);
                                userview.setCurrentCategory(category);
                            }
                           
                            //set home menu Id
                            if (userview.getPropertyString("homeMenuId") == null || userview.getPropertyString("homeMenuId").isEmpty() && menu.isHomePageSupported()) {
                                userview.setProperty("homeMenuId", mId);
                            }

                            menus.add(menu);
                        } catch (Exception e) {
                            LogUtil.debug(getClass().getName(), "Userview Menu class file not found");
                        }
                    }

                    if (menus.size() > 0) {
                        category.setMenus(menus);
                        categories.add(category);
                    }
                }
            }
            userview.setCategories(categories);
        } catch (Exception ex) {
            LogUtil.error(getClass().getName(), ex, "Create Userview Error!!");
        }
        return userview;
    }
View Full Code Here


                    requestParameters.put("contextPath", request.getContextPath());
                    requestParameters.put("appId", appDef.getAppId());
                    requestParameters.put("appVersion", appDef.getVersion().toString());
                   
                    try {
                        Userview userview = new Userview();
                       
                        //set userview properties
                        JSONObject userviewObj = new JSONObject(json);
                        userview.setProperties(PropertyUtil.getPropertiesValueFromJson(userviewObj.getJSONObject("properties").toString()));
                       
                        JSONObject settingObj = userviewObj.getJSONObject("setting");
                        JSONObject themeObj = settingObj.getJSONObject("properties").getJSONObject("theme");
                       
                        theme = (UserviewTheme) pluginManager.getPlugin(themeObj.getString("className"));
View Full Code Here

            Collection<UserviewDefinition> uvDefList = appDef.getUserviewDefinitionList();
            Collection<UserviewDefinition> newUvDefList = new ArrayList<UserviewDefinition>();

            for (UserviewDefinition uvDef : uvDefList) {
                Userview userview = userviewService.createUserview(appDef, uvDef.getJson(), null, false, null, null, null, false);
                if (userview != null && (userview.getSetting().getPermission() == null || (userview.getSetting().getPermission() != null && userview.getSetting().getPermission().isAuthorize()))
                        && (!mobileView || !"true".equals(userview.getSetting().getProperty("mobileViewDisabled")))
                        && (!mobileCache || "true".equals(userview.getSetting().getProperty("mobileCacheEnabled")))) {
                    newUvDefList.add(uvDef);
                }
            }

            if (newUvDefList != null && !newUvDefList.isEmpty()) {
View Full Code Here

        map.addAttribute("embed", embed);
        MobileUtil.setMobileView(request, Boolean.TRUE);
        UserviewDefinition userviewDef = userviewDefinitionDao.loadById(userviewId, appDef);
        if (userviewDef != null) {
            String json = userviewDef.getJson();
            Userview userview = userviewService.createUserview(json, menuId, false, request.getContextPath(), request.getParameterMap(), key, embed);
            boolean loginRequired = "true".equals(userview.getSetting().getProperty("mobileLoginRequired"));
            if (loginRequired) {
                boolean isAnonymous = WorkflowUtil.isCurrentUserAnonymous();
                if (isAnonymous) {
                    return "redirect:/web/mlogin/" + appId + "/" + userviewId + "//landing";
                }
View Full Code Here

        if (userviewDef == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        String json = userviewDef.getJson();
        Userview userview = userviewService.createUserview(json, null, false, request.getContextPath(), request.getParameterMap(), null, false);
        boolean cacheEnabled = "true".equals(userview.getSetting().getProperty("mobileCacheEnabled"));
        if (!cacheEnabled) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        // set response type
        response.setContentType("text/cache-manifest");

        // set expires header
        response.addDateHeader("Expires", 0);

        // generate cache manifest for the app userview
        String contextPath = AppUtil.getRequestContextPath();
        String currentUser = WorkflowUtil.getCurrentUsername();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        String manifest = "CACHE MANIFEST\n"
                + "# " + appDef.getAppId() + " v" + appDef.getVersion() + " " + userviewDef.getId() + " " + userviewDef.getDateModified() + " " + currentUser + " " + cal.getTime() + "\n"
                + "NETWORK:\n"
                + "*\n"
                + "\n"
                + "CACHE:\n"
                + contextPath + "/home/logo.png\n"
                + contextPath + "/home/style.css\n"
                + contextPath + "/js/jquery/themes/ui-lightness/jquery-ui-1.10.3.custom.css\n"
                + contextPath + "/mobile/jqm/jquery.mobile-1.4.0-rc.1.css\n"
                + contextPath + "/mobile/mobile.css\n"
                + contextPath + "/js/jquery/jquery-1.9.1.min.js\n"
                + contextPath + "/js/jquery/jquery-migrate-1.2.1.min.js\n"
                + contextPath + "/js/jquery/ui/jquery-ui-1.10.3.min.js\n"
                + contextPath + "/mobile/jqm/jquery.mobile-1.4.0-rc.1.min.js\n"
                + contextPath + "/mobile/jqm/jquery.cookie.js\n"
                + contextPath + "/mobile/mobile.js\n"
                + contextPath + "/mobile/mobile_util.js\n"
                + contextPath + "/js/json/ui.js\n"
                + contextPath + "/js/json/ui_ext.js\n"
                + contextPath + "/js/json/util.js\n"
                + contextPath + "/mobile/jqm/images/ajax-loader.gif\n"
                + contextPath + "/css/form.css\n"
                + contextPath + "/plugin/org.joget.apps.form.model.Section/js/section.js\n";

        UserviewSetting setting = userview.getSetting();
        String backgroundUrl = setting.getPropertyString("mobileViewBackgroundUrl");
        String logoUrl = setting.getPropertyString("mobileViewLogoUrl");
        if (backgroundUrl != null && !backgroundUrl.trim().isEmpty()) {
            manifest += backgroundUrl + "\n";
        }
        if (logoUrl != null && !logoUrl.trim().isEmpty()) {
            manifest += logoUrl + "\n";
        }

        Collection<UserviewCategory> categories = userview.getCategories();
        for (UserviewCategory cat : categories) {
            Collection<UserviewMenu> menus = cat.getMenus();
            for (UserviewMenu menu : menus) {
                String menuId = userviewService.getMenuId(menu);
                manifest += contextPath + "/web/mobile/" + appDef.getId() + "/" + userviewDef.getId() + "//" + menuId + "\n";
View Full Code Here

        //try to support more by not setting mobile view
        //MobileUtil.setMobileView(request, Boolean.TRUE);
        UserviewDefinition userviewDef = userviewDefinitionDao.loadById(userviewId, appDef);
        if (userviewDef != null) {
            String json = userviewDef.getJson();
            Userview userview = userviewService.createUserview(json, menuId, false, request.getContextPath(), request.getParameterMap(), key, false);
            boolean loginRequired = "true".equals(userview.getSetting().getProperty("mobileLoginRequired"));
            if (loginRequired) {
                boolean isAnonymous = WorkflowUtil.isCurrentUserAnonymous();
                if (isAnonymous) {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                    return null;
View Full Code Here

TOP

Related Classes of org.joget.apps.userview.model.Userview

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.