protected String doIt() {
    boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue("SYSTEM_NATIVE_SEQUENCE", false);
    if (SYSTEM_NATIVE_SEQUENCE) {
      throw new AdempiereException("Native Sequence is Actived");
    }

    setSystemNativeSequence(true);
    boolean ok = false;
    try {
      createSequence("AD_Sequence", null);
      createSequence("AD_Issue", null);
      createSequence("AD_ChangeLog", null);
      //
      final String whereClause = "TableName NOT IN ('AD_Sequence', 'AD_Issue', 'AD_ChangeLog')";
      List<MTable> tables =
          new Query(getCtx(), X_AD_Table.Table_Name, whereClause, get_TrxName())
              .setOrderBy("TableName")
              .list();
      for (MTable table : tables) {
        createSequence(table, get_TrxName());
      }
      ok = true;
    } finally {
      if (!ok) {
        setSystemNativeSequence(false);
      }
    }

    return "@OK@";
  }
 private void setSystemNativeSequence(boolean value) {
   DB.executeUpdateEx(
       "UPDATE AD_SysConfig SET Value=? WHERE Name='SYSTEM_NATIVE_SEQUENCE'",
       new Object[] {value ? "Y" : "N"},
       null // trxName
       );
   MSysConfig.resetCache();
 }
Пример #3
0
  @Override
  public void setValue(Object value) {
    m_value = value;
    String text = m_text;

    //  Nothing to show or Record_ID
    if (value == null || super.getColumnName().equals("Record_ID")) {;
    } else if (super.getColumnName().equals("DocAction")
        && !MSysConfig.getBooleanValue(
            MSysConfig.DOCACTIONBUTTON_SHOWACTIONNAME, false, Env.getAD_Client_ID(Env.getCtx()))) {
      text = Msg.getElement(Env.getCtx(), "DocAction");
    } else if (m_values != null) {
      text = (String) m_values.get(value);
    } else if (m_lookup != null) {
      NamePair pp = m_lookup.get(value);
      if (pp != null) text = pp.getName();
    }
    getComponent().setLabel(text != null ? text : "");
  }
Пример #4
0
  /**
   * Process Alert
   *
   * @param alert alert
   * @return true if processed
   */
  private boolean processAlert(MAlert alert) {
    if (!alert.isValid()) return false;
    log.info("" + alert);

    StringBuffer message = new StringBuffer(alert.getAlertMessage()).append(Env.NL);
    //
    boolean valid = true;
    boolean processed = false;
    ArrayList<File> attachments = new ArrayList<File>();
    MAlertRule[] rules = alert.getRules(false);
    for (int i = 0; i < rules.length; i++) {
      if (i > 0) message.append(Env.NL);
      String trxName = null; // 	assume r/o

      MAlertRule rule = rules[i];
      if (!rule.isValid()) continue;
      log.fine("" + rule);

      //	Pre
      String sql = rule.getPreProcessing();
      if (sql != null && sql.length() > 0) {
        int no = DB.executeUpdate(sql, false, trxName);
        if (no == -1) {
          ValueNamePair error = CLogger.retrieveError();
          rule.setErrorMsg("Pre=" + error.getName());
          m_errors.append("Pre=" + error.getName());
          rule.setIsValid(false);
          rule.save();
          valid = false;
          break;
        }
      } //	Pre

      //	The processing
      sql = rule.getSql(true);
      try {
        String text = null;
        if (MSysConfig.getBooleanValue(
            "ALERT_SEND_ATTACHMENT_AS_XLS", true, Env.getAD_Client_ID(getCtx())))
          text = getExcelReport(rule, sql, trxName, attachments);
        else text = getPlainTextReport(rule, sql, trxName, attachments);
        if (text != null && text.length() > 0) {
          message.append(text);
          processed = true;
        }
      } catch (Exception e) {
        rule.setErrorMsg("Select=" + e.getLocalizedMessage());
        m_errors.append("Select=" + e.getLocalizedMessage());
        rule.setIsValid(false);
        rule.save();
        valid = false;
        break;
      }

      //	Post
      sql = rule.getPostProcessing();
      if (sql != null && sql.length() > 0) {
        int no = DB.executeUpdate(sql, false, trxName);
        if (no == -1) {
          ValueNamePair error = CLogger.retrieveError();
          rule.setErrorMsg("Post=" + error.getName());
          m_errors.append("Post=" + error.getName());
          rule.setIsValid(false);
          rule.save();
          valid = false;
          break;
        }
      } //	Post

      /** Trx */
      if (trxName != null) {
        Trx trx = Trx.get(trxName, false);
        if (trx != null) {
          trx.commit();
          trx.close();
        }
      }
    } //	 for all rules

    //	Update header if error
    if (!valid) {
      alert.setIsValid(false);
      alert.save();
      return false;
    }

    //	Nothing to report
    if (!processed) {
      m_summary.append(alert.getName()).append("=No Result - ");
      return true;
    }

    //
    // Report footer - Date Generated
    DateFormat df = DisplayType.getDateFormat(DisplayType.DateTime);
    message.append("\n\n");
    message
        .append(Msg.translate(getCtx(), "Date"))
        .append(" : ")
        .append(df.format(new Timestamp(System.currentTimeMillis())));

    Collection<Integer> users = alert.getRecipientUsers();
    int countMail = notifyUsers(users, alert.getAlertSubject(), message.toString(), attachments);

    m_summary.append(alert.getName()).append(" (EMails+Notes=").append(countMail).append(") - ");
    return valid;
  } //	processAlert
Пример #5
0
  /**
   * Load Activities
   *
   * @return int
   */
  public int loadActivities() {
    long start = System.currentTimeMillis();

    int MAX_ACTIVITIES_IN_LIST =
        MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx()));

    model = new ListModelTable();

    ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
    String sql =
        "SELECT * FROM AD_WF_Activity a "
            + "WHERE a.Processed='N' AND a.WFState='OS' AND ("
            //	Owner of Activity
            + " a.AD_User_ID=?" //	#1
            //	Invoker (if no invoker = all)
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" //	#2
            // Responsible User
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
            + " AND r.AD_User_ID=?)" //	#3
            //	Responsible Role
            + " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
            + " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" //	#4
            //
            + ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      pstmt.setInt(1, AD_User_ID);
      pstmt.setInt(2, AD_User_ID);
      pstmt.setInt(3, AD_User_ID);
      pstmt.setInt(4, AD_User_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null);
        list.add(activity);
        List<Object> rowData = new ArrayList<Object>();
        rowData.add(activity.getPriority());
        rowData.add(activity.getNodeName());
        rowData.add(activity.getSummary());
        model.add(rowData);
        if (list.size() > MAX_ACTIVITIES_IN_LIST && MAX_ACTIVITIES_IN_LIST > 0) {
          log.warning("More then 200 Activities - ignored");
          break;
        }
      }
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.close(rs, pstmt);
      rs = null;
      pstmt = null;
    }
    m_activities = new MWFActivity[list.size()];
    list.toArray(m_activities);
    //
    log.fine("#" + m_activities.length + "(" + (System.currentTimeMillis() - start) + "ms)");
    m_index = 0;

    String[] columns =
        new String[] {
          Msg.translate(Env.getCtx(), "Priority"),
          Msg.translate(Env.getCtx(), "AD_WF_Node_ID"),
          Msg.translate(Env.getCtx(), "Summary")
        };

    WListItemRenderer renderer = new WListItemRenderer(Arrays.asList(columns));
    ListHeader header = new ListHeader();
    header.setWidth("30px");
    renderer.setListHeader(0, header);
    renderer.addTableValueChangeListener(listbox);
    model.setNoColumns(columns.length);
    listbox.setModel(model);
    listbox.setItemRenderer(renderer);
    listbox.repaint();
    listbox.setFixedLayout(true);

    return m_activities.length;
  } //	loadActivities