/** * MU_FAVORITE * * @throws Exception cyl * @param request * @return elements are Table or WebAction and menu list * @paqram includeAction if true?not now */ public List getSubSystemsOfmufavorite(HttpServletRequest request) throws Exception { ArrayList mufavorite = new ArrayList(); TableManager manager = TableManager.getInstance(); // Table table; try { UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); int userid = userWeb.getUserId(); List al = QueryEngine.getInstance() .doQueryList( "select t.ad_table_id,t.fa_menu,t.menu_re,t.IS_REPORT from MU_FAVORITE t where t.ownerid=" + String.valueOf(userid) + " group by t.ad_table_id,t.menu_no,t.fa_menu,t.menu_re,t.IS_REPORT,t.creationdate order by t.menu_no,t.creationdate asc"); logger.debug("MU_FAVORITE size is " + String.valueOf(al.size())); if (al.size() > 0) { for (int i = 0; i < al.size(); i++) { // ArrayList catschild= new ArrayList(); List als = (List) al.get(i); String fa_menu = (String) als.get(1); String menu_re = (String) als.get(2); String isreport = (String) als.get(3); int table_id = Tools.getInt(als.get(0), -1); Table table = manager.getTable(table_id); logger.debug(table.getName()); /* if(!table.isMenuObject()){ continue; //because many table is webaction not ismenuobject }*/ try { WebUtils.checkTableQueryPermission(table.getName(), request); } catch (NDSSecurityException e) { continue; } logger.debug("add_table ->" + table.getName()); ArrayList row = new ArrayList(); row.add(fa_menu); row.add(menu_re); row.add(isreport); row.add(table); mufavorite.add(row); } } } catch (Throwable t) { logger.error("Fail to load mufavorite", t); } return mufavorite; }
public List getModifiableMonitors(Table paramTable, UserWebImpl usr) throws Exception { // this = (this = TableManager.getInstance()).getTable("ad_monitor"); Table mo_table = TableManager.getInstance().getTable("ad_monitor"); QueryRequestImpl query; query = QueryEngine.getInstance().createRequest(usr.getSession()); query.setMainTable(mo_table.getId()); query.addSelection(mo_table.getColumn("id").getId()); query.addSelection(mo_table.getColumn("name").getId()); query.addSelection(mo_table.getColumn("monitor_type").getId()); query.addSelection(mo_table.getColumn("check_type").getId()); query.addSelection(mo_table.getColumn("isactive").getId()); query.addOrderBy(new int[] {mo_table.getColumn("name").getId()}, true); Expression localExpression = (localExpression = (localExpression = (localExpression = new Expression( new ColumnLink("ad_monitor.monitor_type"), "=obj", null)) .combine( new Expression( new ColumnLink("ad_monitor.monitor_type"), "=list", null), 2, null)) .combine(usr.getSecurityFilter(mo_table.getName(), 3), 1, null)) .combine( new Expression( new ColumnLink("ad_monitor.ad_table_id"), "=" + paramTable.getId(), null), 1, null); query.addParam(localExpression); logger.debug("getModifiableMonitors sql is:" + query.toSQL()); return QueryEngine.getInstance().doQueryList(query.toSQL()); }
/** objectid will be one of following table: ad_listuiconf, ad_listdataconf, ad_objuiconf */ public ValueHolder execute(DefaultWebEvent event) throws RemoteException, NDSException { User usr = helper.getOperator(event); TableManager manager = TableManager.getInstance(); int columnId = Tools.getInt(event.getParameterValue("columnid", true), -1); Table table = manager.getColumn(columnId).getTable(); int tableId = table.getId(); int objectId = Tools.getInt(event.getParameterValue("objectid", true), -1); int type; if (tableId == manager.getTable("ad_listdataconf").getId()) { type = PortletConfig.TYPE_LIST_DATA; } else if (tableId == manager.getTable("ad_listuiconf").getId()) { type = PortletConfig.TYPE_LIST_UI; } else if (tableId == manager.getTable("ad_objuiconf").getId()) { type = PortletConfig.TYPE_OBJECT_UI; } else { throw new NDSException("Internal Error: table is not supported for PortletConfig:" + table); } PortletConfigManager pcManager = (PortletConfigManager) WebUtils.getServletContextManager().getActor(nds.util.WebKeys.PORTLETCONFIG_MANAGER); pcManager.removePortletConfig(objectId, type); // also try to clear config of specified name String name = (String) nds.query.QueryEngine.getInstance() .doQueryOne("select name from " + table.getName() + " where id=" + objectId); logger.debug("name=" + name); pcManager.removePortletConfig(name, type); ValueHolder holder = new ValueHolder(); holder.put("message", "@complete@(cache size:" + pcManager.getCacheSize() + ")"); holder.put("code", "0"); return holder; }
/** * @param request * @param tableCategoryId * @paqram includeAction if true, will load webactions also * @return elements are Table or WebAction */ public List getChildrenOfTableCategory( HttpServletRequest request, int tableCategoryId, boolean includeAction) { TableManager manager = TableManager.getInstance(); WebAction action; ArrayList cats = new ArrayList(); Connection conn = null; HashMap webActionEnv = null; Table table; UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); TableCategory tc = manager.getTableCategory(tableCategoryId); List children = tc.children(); ArrayList catschild = new ArrayList(); try { if (includeAction) { conn = QueryEngine.getInstance().getConnection(); webActionEnv = new HashMap(); webActionEnv.put("connection", conn); webActionEnv.put("httpservletrequest", request); webActionEnv.put("userweb", userWeb); } for (int j = 0; j < children.size(); j++) { if (children.get(j) instanceof Table) { table = (Table) children.get(j); if (!table.isMenuObject()) { continue; } try { WebUtils.checkTableQueryPermission(table.getName(), request); } catch (NDSSecurityException e) { continue; } // table is ok for current user to list catschild.add(table); } else if (children.get(j) instanceof WebAction) { if (includeAction) { action = (WebAction) children.get(j); if (action.canDisplay(webActionEnv)) catschild.add(action); } } else { throw new NDSRuntimeException( "Unsupported element in TableCategory children:" + children.get(j).getClass()); } } } catch (Throwable t) { logger.error("Fail to load subsystem tree", t); } finally { try { if (conn != null) conn.close(); } catch (Throwable e) { } } return catschild; }
/** @return error message, and null if ok */ private String voidOne(Table table, int itemid, int userId, Connection con) { try { QueryUtils.lockRecord(table, itemid, con); /** Unsubmit status check */ QueryUtils.checkStatus(table, itemid, con); String sql = ObjectVoid.getSql(table, itemid, userId); logger.debug(sql); int cnt = con.createStatement().executeUpdate(sql); return null; } catch (Exception e) { logger.error("Could not void record(table=" + table.getName() + ",id=" + itemid + ")", e); return e.getMessage(); } }
public ValueHolder execute(DefaultWebEvent event) throws NDSException, RemoteException { manager = helper.getTableManager(); Table table = manager.findTable(event.getParameterValue("table", true)); int tableId = table.getId(); String[] itemidStr = event.getParameterValues("itemid", true); User user = helper.getOperator(event); String operatorDesc = user.getDescription(); String tableName = table.getRealTableName(); String tableDesc = table.getDescription(event.getLocale()); if (itemidStr == null) itemidStr = new String[0]; java.sql.Connection con = null; QueryEngine engine = QueryEngine.getInstance(); con = engine.getConnection(); try { // logger.debug(" parent table of " + table + " is " + parent); int[] oids = new int[itemidStr.length]; for (int i = 0; i < oids.length; i++) oids[i] = Integer.parseInt(itemidStr[i]); ValueHolder v = new ValueHolder(); // 由于界面上无法控制所有的对象都具有相同层次的权限,故需要在此进行权限认证 // check permissions on all objects if (!SecurityUtils.hasPermissionOnAll( user.getId().intValue(), user.getName(), table.getName(), itemidStr, Directory.WRITE, event.getQuerySession())) { v.put("message", "@no-void-permission-on-all-pls-do-one-by-one@"); return v; } String res = "", s; int errCount = 0; for (int i = 0; i < itemidStr.length; i++) { int itemid = Tools.getInt(itemidStr[i], -1); s = voidOne(table, itemid, user.getId().intValue(), con); if (s != null) { res += s + "<br>"; errCount++; } else { logger.info( "Invalidate table=" + table + ", id=" + itemid + " by " + user.name + " of id " + user.id); } } String message = null; message = itemidStr.length + "@line@ @request-to-void@"; if (errCount > 0) message += ", @failed-count@:" + errCount + ", @detail-msg@:" + res; else message += ",@complete@"; v.put("message", message); return v; } catch (Exception t) { if (t instanceof NDSException) throw (NDSException) t; else { logger.error("Failed", t); throw new NDSException(t.getMessage(), t); } } finally { try { con.close(); } catch (Exception e) { } } }
/** * Return table categories and table that user has view permission * * @param request * @param subSystemId * @return never null, elements are List, containing 2 elements: 1)when first element is * nds.schema.TableCategory, then second will be java.util.List (nds.schema.Table or * nds.schema.WebAction) 2) when first element is nds.schema.WebAction, then second is null */ public List getTableCategories( HttpServletRequest request, int subSystemId, boolean includeActions) { // Create categories and their tables in hashtable TableManager manager = TableManager.getInstance(); // Iterator tables = manager.getAllTables().iterator(); // Hashtable categories = new Hashtable(50,20); // key:Integer(category id), values :List of // table SubSystem ss; Integer tableCategoryId; Table table; WebAction action; ArrayList cats = new ArrayList(); Connection conn = null; HashMap webActionEnv = null; try { UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); if (includeActions) { conn = QueryEngine.getInstance().getConnection(); webActionEnv = new HashMap(); webActionEnv.put("connection", conn); webActionEnv.put("httpservletrequest", request); webActionEnv.put("userweb", userWeb); } List categories = manager.getSubSystem(subSystemId).children(); for (int i = 0; i < categories.size(); i++) { Object o = categories.get(i); // TableCategory or WebAction if (o instanceof TableCategory) { TableCategory tc = (TableCategory) o; List children = tc.children(); ArrayList catschild = new ArrayList(); for (int j = 0; j < children.size(); j++) { if (children.get(j) instanceof Table) { table = (Table) children.get(j); if (!table.isMenuObject()) { continue; } try { WebUtils.checkTableQueryPermission(table.getName(), request); } catch (NDSSecurityException e) { continue; } // table is ok for current user to list catschild.add(table); } else if (children.get(j) instanceof WebAction) { if (includeActions) { action = (WebAction) children.get(j); if (action.canDisplay(webActionEnv)) catschild.add(action); } } else { throw new NDSRuntimeException( "Unsupported element in TableCategory children:" + children.get(j).getClass()); } } if (catschild.size() > 0) { // show this category ArrayList row = new ArrayList(); row.add(tc); row.add(catschild); cats.add(row); } } else if (o instanceof WebAction) { if (includeActions && ((WebAction) o).canDisplay(webActionEnv)) { ArrayList row = new ArrayList(); row.add(o); row.add(Collections.EMPTY_LIST); cats.add(row); } } else { throw new NDSException( "Unexpected class in subsystem (id=" + subSystemId + "), class is " + o.getClass()); } } } catch (Throwable t) { logger.error("Fail to load subsystem tree", t); } finally { try { if (conn != null) conn.close(); } catch (Throwable e) { } } return cats; }
/** * menu action * * @throws Exception cyl * @param request * @param tableCategoryId desgin menu list * @paqram includeAction if true, will load webactions also * @return elements are Table or WebAction and menu list */ public List getChildrenOfTableCategorybymenu( HttpServletRequest request, int tableCategoryId, boolean includeAction) throws Exception { TableManager manager = TableManager.getInstance(); WebAction action; ArrayList cats = new ArrayList(); List children = new ArrayList(); Connection conn = null; HashMap webActionEnv = null; Table table; List al = QueryEngine.getInstance() .doQueryList( "select e.id,e.name from ad_table g,AD_ACCORDION e where g.AD_ACCORDION_id=e.id and g.ad_tablecategory_id=" + tableCategoryId + " group by e.id,e.name,e.orderno order by e.orderno asc"); UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); TableCategory tc = manager.getTableCategory(tableCategoryId); if (tc != null) children = tc.children(); // ArrayList prow= new ArrayList(); if (al.size() > 0) { for (int i = 0; i < al.size(); i++) { List als = (List) al.get(i); int ACCORDION = Tools.getInt(als.get(0), -1); logger.debug("ACCORDION~~~~~~~~~~" + String.valueOf(ACCORDION)); ArrayList catschild = new ArrayList(); String ACCORDION_name = (String) als.get(1); try { if (includeAction) { conn = QueryEngine.getInstance().getConnection(); webActionEnv = new HashMap(); webActionEnv.put("connection", conn); webActionEnv.put("httpservletrequest", request); webActionEnv.put("userweb", userWeb); } for (int j = 0; j < children.size(); j++) { if (children.get(j) instanceof Table) { table = (Table) children.get(j); // logger.debug("getAccordid~~~~~~~~~~"+String.valueOf(table.getAccordid())); if (!table.isMenuObject()) { continue; } else if (ACCORDION != table.getAccordid()) { // logger.debug(String.valueOf(ACCORDION)+"!="+String.valueOf(table.getAccordid())); continue; } try { WebUtils.checkTableQueryPermission(table.getName(), request); } catch (NDSSecurityException e) { continue; } // table is ok for current user to list logger.debug(String.valueOf(ACCORDION) + "&&" + String.valueOf(table.getAccordid())); catschild.add(table); } else if (children.get(j) instanceof WebAction) { if (includeAction) { action = (WebAction) children.get(j); if (action.canDisplay(webActionEnv) && (action.getAcordionId() == ACCORDION)) { logger.debug("add action" + String.valueOf(ACCORDION)); // System.out.print("add action"+String.valueOf(ACCORDION)); // System.out.print("action name"+String.valueOf(action.getName())); // System.out.print("ACCORDION name"+String.valueOf(ACCORDION)); // System.out.print("action // name"+String.valueOf(action.getAcordionId())); catschild.add(action); } } } else { throw new NDSRuntimeException( "Unsupported element in TableCategory children:" + children.get(j).getClass()); } } } catch (Throwable t) { logger.error("Fail to load subsystem tree", t); } finally { try { if (conn != null) conn.close(); } catch (Throwable e) { } } if (catschild.size() > 0) { // show this category ArrayList row = new ArrayList(); row.add(ACCORDION_name); row.add(catschild); cats.add(row); } } return cats; } else { ArrayList catschild1 = new ArrayList(); try { if (includeAction) { conn = QueryEngine.getInstance().getConnection(); webActionEnv = new HashMap(); webActionEnv.put("connection", conn); webActionEnv.put("httpservletrequest", request); webActionEnv.put("userweb", userWeb); } for (int j = 0; j < children.size(); j++) { if (children.get(j) instanceof Table) { table = (Table) children.get(j); if (!table.isMenuObject()) { continue; } try { WebUtils.checkTableQueryPermission(table.getName(), request); } catch (NDSSecurityException e) { continue; } // table is ok for current user to list catschild1.add(table); } else if (children.get(j) instanceof WebAction) { if (includeAction) { action = (WebAction) children.get(j); if (action.canDisplay(webActionEnv)) catschild1.add(action); } } else { throw new NDSRuntimeException( "Unsupported element in TableCategory children:" + children.get(j).getClass()); } } } catch (Throwable t) { logger.error("Fail to load subsystem tree", t); } finally { try { if (conn != null) conn.close(); } catch (Throwable e) { } } if (catschild1.size() > 0) { // show this category ArrayList row = new ArrayList(); row.add(tc.getName()); row.add(catschild1); cats.add(row); } } return cats; }
/** * 事实表和关联报表属于当前传入数组的交叉报表 * * @param request * @param tables elements are table.id * @return elements are ArrayList, first is cxtab id, second is cxtab name */ public List getCxtabs(HttpServletRequest request, List<Integer> tables) { TableManager manager = TableManager.getInstance(); UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); StringBuffer sb = new StringBuffer(); for (int i = 0; i < tables.size(); i++) { // Table t= tables.get(i); if (i > 0) sb.append(","); sb.append(tables.get(i)); } String ts = sb.toString(); try { Table cxtabTable = manager.getTable("AD_CXTAB"); QueryRequestImpl queryData; // only pk,dk will be selected, order by ak asc queryData = QueryEngine.getInstance().createRequest(userWeb.getSession()); queryData.setMainTable(cxtabTable.getId()); queryData.addSelection(cxtabTable.getPrimaryKey().getId()); queryData.addSelection(cxtabTable.getDisplayKey().getId()); Column colOrderNo = cxtabTable.getColumn("orderno"); queryData.setOrderBy(new int[] {colOrderNo.getId()}, true); queryData.setRange(0, Integer.MAX_VALUE); Expression expr = new Expression( null, "(AD_CXTAB.AD_TABLE_ID in (" + ts + ") or exists (select 1 from ad_cxtab_reftable r where r.ad_cxtab_id=AD_CXTAB.id and r.ad_table_id in (" + ts + ")))", null); // set reporttype to "S" expr = expr.combine( new Expression(new ColumnLink("AD_CXTAB.REPORTTYPE"), "=S", null), SQLCombination.SQL_AND, null); expr = expr.combine( new Expression(new ColumnLink("AD_CXTAB.ISACTIVE"), "=Y", null), SQLCombination.SQL_AND, null); expr = expr.combine( new Expression(new ColumnLink("AD_CXTAB.ISPUBLIC"), "=Y", null), SQLCombination.SQL_AND, null); expr = expr.combine( userWeb.getSecurityFilter(cxtabTable.getName(), 1), SQLCombination.SQL_AND, null); queryData.addParam(expr); // read permission return QueryEngine.getInstance().doQueryList(queryData.toSQL()); } catch (Throwable t) { logger.error( "Fail to load reports for user " + userWeb.getUserId() + " with table ids: " + ts, t); } return Collections.EMPTY_LIST; }