public List<AppModel> getAppById(String id) { String cql = "SELECT * FROM app WHERE appid = '%s';"; cql = String.format(cql, id); List<AppModel> apps = new ArrayList<AppModel>(); Iterator rows = this.bridge.excute(cql); while (rows.hasNext()) { AppModel app = new AppModel(); Row row = (Row) rows.next(); app.setAppid(row.getString("appid")); app.setName(row.getString("name")); app.setInstallUrl(row.getString("url")); app.setProfile(row.getString("profile")); app.setIsInnerApp(row.getString("isinnerapp")); try { JSONObject profile = JSONObject.fromObject(app.getProfile()); app.setImage(profile.getString("image")); apps.add(app); } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } } return apps; }
public List<AppModel> getAppsByRole(String groupname) { List<AppModel> apps = new ArrayList<AppModel>(); try { String cql = "SELECT * FROM group_app_map WHERE groupname = '%s';"; cql = String.format(cql, groupname); Iterator rows = this.bridge.excute(cql); while (rows.hasNext()) { Row row = (Row) rows.next(); AppModel app = this.getAppByid(row.getString("appid")); if (app == null) { continue; } app.setAppid(row.getString("appid")); app.setProfile(row.getString("permissions")); apps.add(app); // apps.addAll(getAppById(row.getString("appid"))); } } catch (Exception e) { log.error(e.getMessage()); } return apps; }
public ExeModel getExeById(String appkey, String username, JSONObject sessionobj) { String ip = sessionobj.getString("ip"); String cookie = sessionobj.getString("cookie"); ExeModel exe = new ExeModel(); try { if ((!AppCache.getInstance().getFirstLevelCache().containsKey(appkey)) && (!(AppCache.getInstance().getSecondLevelCache().containsKey(appkey)))) { String cql = "SELECT * FROM app WHERE appid = '%s';"; cql = String.format(cql, appkey); Iterator rows = this.bridge.excute(cql); if (!rows.hasNext()) { exe.setImage("images/icons/app-warning-icon.png"); exe.setLinkurl(""); exe.setName("Has uninstall"); exe.setWinsettings("{}"); return exe; } while (rows.hasNext()) { Row row = (Row) rows.next(); AppModel temp = new AppModel(); temp.setName(row.getString("name")); temp.setAppid(appkey); temp.setProfile(row.getString("profile")); JSONObject profile = JSONObject.fromObject(row.getString("profile")); temp.setImage(profile.getString("image")); temp.setInstallUrl(row.getString("url")); temp.setIsInnerApp(row.getString("isinnerapp")); AppCache.getInstance().getFirstLevelCache().put(appkey, temp); } } AppModel temp = AppCache.getInstance().getById(appkey); boolean isinner = temp.getIsInnerApp().equals("1"); exe.setName(temp.getName()); JSONObject profile = JSONObject.fromObject(temp.getProfile()); exe.setImage(profile.getString("image")); exe.setWinsettings(profile.getString("winSettings")); if (isinner) { JSONArray arr = profile.getJSONArray("funcs"); for (Object func : arr) { JSONObject funcobj = JSONObject.fromObject(func); if (funcobj.getString("id").equals("1000")) { exe.setLinkurl(funcobj.getString("url")); } } } else { exe.setLinkurl("/" + appkey + "/"); } String roles_str = UserDB.getInstance().getUser(username).getRoles(); Object[] roles = null; roles = JSONArray.fromObject(roles_str).toArray(); StringBuilder ids = new StringBuilder(); for (Object role : roles) { String cql = "SELECT permissions FROM group_app_map WHERE appid = '%s' AND groupname='%s';"; cql = String.format(cql, appkey, role.toString()); Iterator rows = this.bridge.excute(cql); if (rows.hasNext()) { Row row = (Row) rows.next(); String permissions = row.getString("permissions"); try { JSONArray perobj = JSONArray.fromObject(permissions); for (int j = 0; j < perobj.size(); j++) { JSONObject obj = perobj.getJSONObject(j); ids.append(obj.get("id")).append("_"); } } catch (Exception ex) { ex.printStackTrace(); log.error(ex.getMessage()); } } } if (ids.toString().equals("")) { exe.setImage(""); exe.setName("No permissions"); exe.setLinkurl(""); return exe; } String perm = "id=" + ids.toString(); if (perm.lastIndexOf("_") != -1) { perm = perm.substring(0, perm.lastIndexOf("_")); } exe.setLinkurl( exe.getLinkurl() + "?" + perm + "&" + "username="******"&" + "appid=" + appkey + "&ip=" + ip + "&cookie=" + cookie); } catch (Exception e) { exe.setImage(""); exe.setName("error"); exe.setLinkurl(""); e.printStackTrace(); log.error(e.getMessage()); return exe; } return exe; }