Exemplo n.º 1
0
  /**
   * Notify users
   *
   * @param users AD_User_ID list
   * @param subject email subject
   * @param message email message
   * @param attachments
   * @return how many email were sent
   */
  private int notifyUsers(
      Collection<Integer> users, String subject, String message, Collection<File> attachments) {
    int countMail = 0;
    for (int user_id : users) {
      MUser user = MUser.get(getCtx(), user_id);
      if (user.isNotificationEMail()) {
        if (m_client.sendEMailAttachments(user_id, subject, message, attachments)) {
          countMail++;
        }
      }

      if (user.isNotificationNote()) {
        Trx trx = null;
        try {
          trx = Trx.get(Trx.createTrxName("AP_NU"), true);
          // Notice
          int AD_Message_ID = 52244; /* TODO - Hardcoded message=notes */
          MNote note = new MNote(getCtx(), AD_Message_ID, user_id, trx.getTrxName());
          note.setClientOrg(m_model.getAD_Client_ID(), m_model.getAD_Org_ID());
          note.setTextMsg(message);
          note.saveEx();
          // Attachment
          MAttachment attachment =
              new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), trx.getTrxName());
          for (File f : attachments) {
            attachment.addEntry(f);
          }
          attachment.setTextMsg(message);
          attachment.saveEx();
          countMail++;
          trx.commit();
        } catch (Throwable e) {
          if (trx != null) trx.rollback();
        } finally {
          if (trx != null) trx.close();
        }
      }
    }
    return countMail;
  }
Exemplo n.º 2
0
  /** Save */
  public void onOK() {
    log.config("Activity=" + m_activity);
    if (m_activity == null) {
      Clients.showBusy(null, false);
      return;
    }
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    String textMsg = fTextMsg.getValue();
    //
    MWFNode node = m_activity.getNode();

    Object forward = null; // fForward.getValue();

    // ensure activity is ran within a transaction - [ 1953628 ]
    Trx trx = null;
    try {
      trx = Trx.get(Trx.createTrxName("FWFA"), true);
      m_activity.set_TrxName(trx.getTrxName());

      if (forward != null) {
        log.config("Forward to " + forward);
        int fw = ((Integer) forward).intValue();
        if (fw == AD_User_ID || fw == 0) {
          log.log(Level.SEVERE, "Forward User="******"CannotForward");
          trx.rollback();
          trx.close();
          return;
        }
      }
      //	User Choice - Answer
      else if (MWFNode.ACTION_UserChoice.equals(node.getAction())) {
        if (m_column == null) m_column = node.getColumn();
        //	Do we have an answer?
        int dt = m_column.getAD_Reference_ID();
        String value = fAnswerText.getText();
        if (dt == DisplayType.YesNo || dt == DisplayType.List) {
          ListItem li = fAnswerList.getSelectedItem();
          if (li != null) value = li.getValue().toString();
        }
        if (value == null || value.length() == 0) {
          FDialog.error(m_WindowNo, this, "FillMandatory", Msg.getMsg(Env.getCtx(), "Answer"));
          trx.rollback();
          trx.close();
          return;
        }
        //
        log.config("Answer=" + value + " - " + textMsg);
        try {
          m_activity.setUserChoice(AD_User_ID, value, dt, textMsg);
        } catch (Exception e) {
          log.log(Level.SEVERE, node.getName(), e);
          FDialog.error(m_WindowNo, this, "Error", e.toString());
          trx.rollback();
          trx.close();
          return;
        }
      }
      //	User Action
      else {
        log.config("Action=" + node.getAction() + " - " + textMsg);
        try {
          // ensure activity is ran within a transaction
          m_activity.setUserConfirmation(AD_User_ID, textMsg);
        } catch (Exception e) {
          log.log(Level.SEVERE, node.getName(), e);
          FDialog.error(m_WindowNo, this, "Error", e.toString());
          trx.rollback();
          trx.close();
          return;
        }
      }

      trx.commit();
    } finally {
      Clients.showBusy(null, false);
      if (trx != null) trx.close();
    }

    //	Next
    loadActivities();
    display(-1);
  } //	onOK
Exemplo n.º 3
0
  /** @param e */
  public void valueChange(ValueChangeEvent e) {
    if (gridTab.isProcessed()) //  only active records
    {
      Object source = e.getSource();
      if (source instanceof WEditor) {
        // Elaine 2009/05/06
        WEditor editor = (WEditor) source;
        GridField gridField = editor.getGridField();

        if (gridField != null) {
          if (!gridField.isEditable(true)) {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
          }
        } else if (!editor.isReadWrite()) {
          logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
          return;
        }
      } else {
        logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
        return;
      }
    } //  processed
    logger.config(
        "("
            + gridTab.toString()
            + ") "
            + e.getPropertyName()
            + "="
            + e.getNewValue()
            + " ("
            + e.getOldValue()
            + ") "
            + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));

    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null
        && e.getOldValue() != null
        && e.getOldValue().toString().length() > 0) //  some editors return "" instead of null
      //        	  this is the original code from GridController, don't know what it does there but
      // it breaks ignore button for web ui
      //            mTable.setChanged (true);
      mTable.setValueAt(e.getNewValue(), row, col);
    else {

      Object newValue = e.getNewValue();
      Integer newValues[] = null;

      if (newValue instanceof Integer[]) {
        newValues = ((Integer[]) newValue);
        newValue = newValues[0];

        if (newValues.length > 1) {
          Integer valuesCopy[] = new Integer[newValues.length - 1];
          System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
          newValues = valuesCopy;
        } else {
          newValues = null;
        }
      } else if (newValue instanceof Object[]) {
        logger.severe("Multiple values can only be processed for IDs (Integer)");
        throw new IllegalArgumentException(
            "Multiple Selection values not available for this field. " + e.getPropertyName());
      }

      mTable.setValueAt(newValue, row, col);
      //  Force Callout
      if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
        GridField mField = gridTab.getField(col);
        if (mField != null && mField.getCallout().length() > 0) {
          gridTab.processFieldChange(mField); //  Dependencies & Callout
        }
      }

      if (newValues != null && newValues.length > 0) {
        // Save data, since record need to be used for generating clones.
        if (!gridTab.dataSave(false)) {
          throw new AdempiereException("SaveError");
        }

        // Retrieve the current record ID
        int recordId = gridTab.getKeyID(gridTab.getCurrentRow());

        Trx trx = Trx.get(Trx.createTrxName(), true);
        trx.start();
        try {
          saveMultipleRecords(
              Env.getCtx(),
              gridTab.getTableName(),
              e.getPropertyName(),
              recordId,
              newValues,
              trx.getTrxName());
          trx.commit();
          gridTab.dataRefreshAll();
        } catch (Exception ex) {
          trx.rollback();
          logger.severe(ex.getMessage());
          throw new AdempiereException("SaveError");
        } finally {
          trx.close();
        }
      }
    }
  } // ValueChange
Exemplo n.º 4
0
  // @emmie custom
  public String generate(
      IStatusBar statusBar, KeyNamePair docTypeKNPair, int C_POS_ID, String docActionSelected)
        // @emmie custom
      {
    String info = "";
    String trxName = Trx.createTrxName("IVG");
    Trx trx = Trx.get(trxName, true); // trx needs to be committed too

    setSelectionActive(false); //  prevents from being called twice
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));

    //	Prepare Process
    int AD_Process_ID = 0;

    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
      AD_Process_ID =
          PROCESS_C_INVOICE_GENERATERMA_MANUAL; // C_Invoice_GenerateRMA -
                                                // org.adempiere.process.InvoiceGenerateRMA
    } else {
      AD_Process_ID = PROCESS_C_INVOICE_GENERATE_MANUAL; // HARDCODED    C_InvoiceCreate
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
      info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
      return info;
    }

    // insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : getSelection()) {
      counter++;
      if (counter > 1) insert.append(" UNION ");
      insert.append("SELECT ");
      insert.append(instance.getAD_PInstance_ID());
      insert.append(", ");
      insert.append(selectedId);
      insert.append(" FROM DUAL ");

      if (counter == 1000) {
        if (DB.executeUpdate(insert.toString(), trxName) < 0) {
          String msg = "No Invoices"; //  not translated!
          info = msg;
          log.config(msg);
          trx.rollback();
          return info;
        }
        insert = new StringBuffer();
        insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
        counter = 0;
      }
    }
    if (counter > 0) {
      if (DB.executeUpdate(insert.toString(), trxName) < 0) {
        String msg = "No Invoices"; //  not translated!
        info = msg;
        log.config(msg);
        trx.rollback();
        return info;
      }
    }

    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());

    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter("Selection", "Y");
    if (!para.save()) {
      String msg = "No Selection Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }

    para = new MPInstancePara(instance, 20);
    para.setParameter("DocAction", docActionSelected);

    if (!para.save()) {
      String msg = "No DocAction Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }
    // @emmie custom
    para = new MPInstancePara(instance, 30);
    para.setParameter("C_POS_ID", C_POS_ID);

    if (!para.save()) {
      String msg = "No C_POS_ID Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }
    // @emmie custom

    setTrx(trx);
    setProcessInfo(pi);

    return info;
  } //	generateInvoices