/** 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;
  }
 public void setController(SessionController controller) {
   super.setController(controller);
   lastestVersion = controller.getAttribute("ActivePOSVersion", "2");
   downloadURL =
       controller.getAttribute(
           "ActivePOSURL", "ftp://*****:*****@sina.com@localhost/download/setup.exe");
   checkSum = controller.getAttribute("ActivePOSCheckSum", "unknown"); // "unknown" is keyword
   fileLength = controller.getAttribute("ActivePOSFileLength", "-1");
   cvsRoot = controller.getAttribute("CVSROOT", ":pserver:error@error:/error");
   cvsFileRoot = controller.getAttribute("CVSDir", "/cvs");
   cvsPassword = controller.getAttribute("CVSPassword", "abc123");
   cvsPOSModule = controller.getAttribute("CVSPOSModule", "pos");
   try {
     isLimitToSpecialUpdateClients =
         (new Boolean(controller.getAttribute("LimitSpecialUpdateClients", "false")))
             .booleanValue();
   } catch (Exception e) {
     isLimitToSpecialUpdateClients = false;
   }
   if (isLimitToSpecialUpdateClients) {
     specialUpdateClients = toArray(controller.getAttribute("SpecialUpdateClients", ""), ",");
     logger.debug(
         "Only these clients will be notified new version:"
             + Tools.toString(specialUpdateClients));
     this.specialNoUpdateClients =
         toArray(controller.getAttribute("SpecialNoUpdateClients", ""), ",");
     logger.debug(
         "Only these clients will *NOT* be notified new version:"
             + Tools.toString(specialNoUpdateClients));
   }
   sessionMsgPrefix = controller.getCommander().getSessionMsgPrefix();
 }
Beispiel #3
0
 public synchronized void reloadObjectActionListeners() throws Exception {
   this.objActionListeners.clear();
   List localList;
   try {
     localList =
         QueryEngine.getInstance()
             .doQueryList(
                 "select id from ad_monitor m where m.check_type='action' and m.monitor_type='obj' and m.isactive='Y'");
   } catch (Throwable e) {
     throw new NDSException("Fail to read ad_monitor table from db", e);
   }
   if (localList != null)
     for (int i = 0; i < localList.size(); i++) {
       int j = Tools.getInt(localList.get(i), -1);
       ObjectActionListener localObjectActionListener = createListener(j);
       logger.debug("reloadObjectActionListeners complet!");
       if (localObjectActionListener == null) {
         throw new NDSException(
             "No implementation for ObjectActionListener, check your plugin configuration");
       }
       this.objActionListeners.add(
           localObjectActionListener.getAdClientId()
               + "."
               + localObjectActionListener.getTableId(),
           localObjectActionListener);
       this.objActionListenersIds.put(Integer.valueOf(j), localObjectActionListener);
     }
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * Find report with input, throw exception if could not found. When there's more than one, use id
  * small one
  *
  * @param clientDomain
  * @param tableName
  * @param reportType
  * @return
  * @throws Exception
  */
 private int getReportId(String clientDomain, String tableName, String reportType)
     throws Exception {
   reportType = reportType.toUpperCase();
   Table table = nds.schema.TableManager.getInstance().findTable(tableName);
   if (table == null) throw new NDSException("table " + tableName + " not found.");
   String sql =
       "select r.id from ad_report r, ad_client c where c.domain='"
           + clientDomain
           + "' and r.ad_table_id="
           + table.getId()
           + " and r.reporttype='"
           + reportType
           + "' and c.id=r.ad_client_id order by id asc";
   return Tools.getInt(QueryEngine.getInstance().doQueryOne(sql), -1);
 }
Beispiel #6
0
 /**
  * 修改单据以下内容: status= JNDINames.STATUS_AUDITING auditorId=null, auditNote=null,
  * modifierid=Operator.UserId() modifieddate=sysdate
  */
 public ValueHolder execute(DefaultWebEvent event) throws NDSException, RemoteException {
   Integer pid = new Integer(Tools.getInt(event.getParameterValue("id"), -1));
   int userId = helper.getOperator(event).getId().intValue();
   String spName = (String) event.getParameterValue("spName");
   String tableName = spName.substring(0, spName.indexOf("Audit"));
   QueryEngine engine = QueryEngine.getInstance();
   int status = engine.getSheetStatus(tableName, pid.intValue());
   if (status == JNDINames.STATUS_AUDITING || status == JNDINames.STATUS_PERMIT) {
     throw new NDSEventException("该请求已经被提交过了!");
   }
   Vector sqls = new Vector();
   sqls.addElement(
       "update "
           + tableName
           + " set status="
           + JNDINames.STATUS_AUDITING
           + ",auditorId=null,auditNote=null,modifierid="
           + userId
           + ", modifieddate=sysdate where id="
           + pid);
   try {
     engine.doUpdate(sqls);
     // Notify
     java.sql.Connection con = null;
     try {
       con = engine.getConnection();
       helper.Notify(
           TableManager.getInstance().getTable(tableName),
           pid.intValue(),
           helper.getOperator(event).getDescription(),
           JNDINames.STATUS_AUDITING,
           con);
     } catch (Exception eee) {
     } finally {
       try {
         if (con != null) con.close();
       } catch (Exception eee) {
       }
     }
     ValueHolder v = new ValueHolder();
     v.put("message", "请求进入审核状态!");
     return v;
   } catch (Exception e) {
     throw new NDSEventException(e.getMessage());
   }
 }
Beispiel #7
0
  /**
   * return OutputStream of JasperReport object, this page could only be viewed from localhost for
   * security concern. parameter can be (id), or (table and type)
   *
   * @param id - report id, or
   * @param table - table name
   * @param type - reporttype "s","l","o", case insensitive
   * @param client(*) - client domain
   * @param version - version number, default to -1
   */
  public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String clientName = request.getParameter("client");
    int objectId = ParamUtils.getIntAttributeOrParameter(request, "id", -1);
    if (objectId == -1) {
      // try using table and type
      objectId =
          getReportId(clientName, request.getParameter("table"), request.getParameter("type"));
    }
    if (objectId == -1) {
      logger.error("report not found, request is:" + Tools.toString(request));
      throw new NDSException("report not found");
    }
    int version = ParamUtils.getIntAttributeOrParameter(request, "version", -1);
    File reportXMLFile = new File(ReportTools.getReportFile(objectId, clientName));
    if (reportXMLFile.exists()) {
      // generate jasperreport if file not exists or not newer
      String reportName =
          reportXMLFile.getName().substring(0, reportXMLFile.getName().lastIndexOf("."));
      File reportJasperFile = new File(reportXMLFile.getParent(), reportName + ".jasper");
      if (!reportJasperFile.exists()
          || reportJasperFile.lastModified() < reportXMLFile.lastModified()) {
        JasperCompileManager.compileReportToFile(
            reportXMLFile.getAbsolutePath(), reportJasperFile.getAbsolutePath());
      }
      InputStream is = new FileInputStream(reportJasperFile);
      response.setContentType("application/octetstream;");
      response.setContentLength((int) reportJasperFile.length());

      // response.setHeader("Content-Disposition","inline;filename=\""+reportJasperFile.getName()+"\"");
      ServletOutputStream os = response.getOutputStream();

      byte[] b = new byte[8192];
      int bInt;
      while ((bInt = is.read(b, 0, b.length)) != -1) {
        os.write(b, 0, bInt);
      }
      is.close();
      os.flush();
      os.close();
    } else {
      throw new NDSException("Not found report template");
    }
  }
Beispiel #8
0
  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) {
      }
    }
  }
Beispiel #9
0
  /**
   * 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;
  }
Beispiel #10
0
  /**
   * @param request
   * @param permissionType PERMISSION_VIEWABLE, PERMISSION_NO_PERM or PERMISSION_NO_LICENSE
   * @return never null, elements are nds.schema.SubSystem
   */
  public List<SubSystem> getSubSystems(HttpServletRequest request, int permissionType)
      throws Exception {
    if (permissionType == PERMISSION_VIEWABLE) return getSubSystems(request);

    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));

    String subsystems =
        (String)
            QueryEngine.getInstance()
                .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId());
    if (Validator.isNotNull(subsystems)) {
      return Collections.EMPTY_LIST;
    }
    TableManager manager = TableManager.getInstance();

    if (permissionType == PERMISSION_NO_PERM) {
      ArrayList subs = new ArrayList();
      List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id
      if (al == null) {
        getSubSystems(request);
        al = (List) userWeb.getProperty("subsystems");
      }
      //			 no perm
      List ss = manager.getSubSystems();
      for (int i = 0; i < ss.size(); i++) {
        SubSystem sa = (SubSystem) ss.get(i);
        boolean found = false;
        for (int j = 0; j < al.size(); j++) {
          if (((Integer) al.get(j)).intValue() == sa.getId()) {
            found = true;
            break;
          }
        }
        if (!found) subs.add(sa);
      }
      return subs;
    } // else{
    // no license
    if (subSystemNoLicense == null) {
      subSystemNoLicense = new ArrayList<SubSystem>();
      List al =
          QueryEngine.getInstance()
              .doQueryList(
                  "select id, name, orderno, iconurl,url from ad_subsystem s where exists(select 1 from ad_tablecategory c where c.ad_subsystem_id=s.id) order by orderno asc");
      for (int i = 0; i < al.size(); i++) {
        List als = (List) al.get(i);
        if (manager.getSubSystem(Tools.getInt(als.get(0), -1)) == null) {
          SubSystem ss = new SubSystem();
          ss.setId(Tools.getInt(als.get(0), -1));
          ss.setName((String) als.get(1));
          ss.setOrderno(Tools.getInt(als.get(2), -1));
          ss.setIconURL((String) als.get(3));
          ss.setPageURL((String) als.get(4));
          subSystemNoLicense.add(ss);
        }
      }
    }
    return subSystemNoLicense;
    // }

  }