Exemple #1
0
/**
 * Location Region Model (Value Object)
 *
 * @author Jorg Janke
 * @version $Id: MRegion.java 8755 2010-05-12 18:30:14Z nnayak $
 */
public final class MRegion extends X_C_Region implements Comparator<PO>, Serializable {
  /** Logger for class MRegion */
  private static final org.compiere.util.CLogger log =
      org.compiere.util.CLogger.getCLogger(MRegion.class);
  /** */
  private static final long serialVersionUID = 1L;

  /**
   * Load Regions (cached)
   *
   * @param ctx context
   */
  private static void loadAllRegions(Ctx ctx) {
    String sql = "SELECT * FROM C_Region WHERE IsActive='Y'";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, (Trx) null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        MRegion r = new MRegion(ctx, rs, null);
        s_regions.put(String.valueOf(r.getC_Region_ID()), r);
        if (r.isDefault()) s_default = r;
      }
    } catch (SQLException e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }

    s_log.fine(s_regions.size() + " - default=" + s_default);
  } //	loadAllRegions

  /**
   * Get Country (cached)
   *
   * @param ctx context
   * @param C_Region_ID ID
   * @return Country
   */
  public static MRegion get(Ctx ctx, int C_Region_ID) {
    if (s_regions.isEmpty()) loadAllRegions(ctx);
    String key = String.valueOf(C_Region_ID);
    MRegion r = s_regions.get(ctx, key);
    if (r != null) return r;
    r = new MRegion(ctx, C_Region_ID, null);
    if (r.getC_Region_ID() == C_Region_ID) {
      s_regions.put(key, r);
      return r;
    }
    return null;
  } //	get

  /**
   * Get Default Region
   *
   * @param ctx context
   * @return Region or null
   */
  public static MRegion getDefault(Ctx ctx) {
    if (s_regions.isEmpty()) loadAllRegions(ctx);
    return s_default;
  } //	get

  /**
   * Return Regions as Array
   *
   * @param ctx context
   * @return MCountry Array
   */
  public static MRegion[] getRegions(Ctx ctx) {
    if (s_regions.isEmpty()) loadAllRegions(ctx);
    MRegion[] retValue = new MRegion[s_regions.size()];
    s_regions.values().toArray(retValue);
    Arrays.sort(retValue, new MRegion(ctx, 0, null));
    return retValue;
  } //	getRegions

  /**
   * Return Array of Regions of Country
   *
   * @param ctx context
   * @param C_Country_ID country
   * @return MRegion Array
   */
  public static MRegion[] getRegions(Ctx ctx, int C_Country_ID) {
    if (s_regions.isEmpty()) loadAllRegions(ctx);
    ArrayList<MRegion> list = new ArrayList<MRegion>();
    Iterator<MRegion> it = s_regions.values().iterator();
    while (it.hasNext()) {
      MRegion r = it.next();
      if (r.getC_Country_ID() == C_Country_ID) list.add(r);
    }
    //  Sort it
    MRegion[] retValue = new MRegion[list.size()];
    list.toArray(retValue);
    Arrays.sort(retValue, new MRegion(ctx, 0, null));
    return retValue;
  } //	getRegions

  /** Region Cache */
  private static final CCachePerm<String, MRegion> s_regions =
      new CCachePerm<String, MRegion>("C_Region", 100);
  /** Default Region */
  private static MRegion s_default = null;
  /** Static Logger */
  private static CLogger s_log = CLogger.getCLogger(MRegion.class);

  /**
   * ************************************************************************ Create empty Region
   *
   * @param ctx context
   * @param C_Region_ID id
   * @param trx transaction
   */
  public MRegion(Ctx ctx, int C_Region_ID, Trx trx) {
    super(ctx, C_Region_ID, trx);
    if (C_Region_ID == 0) {}
  } //  MRegion

  /**
   * Create Region from current row in ResultSet
   *
   * @param ctx context
   * @param rs result set
   * @param trx transaction
   */
  public MRegion(Ctx ctx, ResultSet rs, Trx trx) {
    super(ctx, rs, trx);
  } //	MRegion

  /**
   * Parent Constructor
   *
   * @param country country
   * @param regionName Region Name
   */
  public MRegion(MCountry country, String regionName) {
    super(country.getCtx(), 0, country.get_Trx());
    setC_Country_ID(country.getC_Country_ID());
    setName(regionName);
  } //  MRegion

  /**
   * Return Name
   *
   * @return Name
   */
  @Override
  public String toString() {
    return getName();
  } //  toString

  /**
   * Compare
   *
   * @param o1 object 1
   * @param o2 object 2
   * @return -1,0, 1
   */
  @Override
  public int compare(PO o1, PO o2) {
    String s1 = o1.toString();
    if (s1 == null) s1 = "";
    String s2 = o2.toString();
    if (s2 == null) s2 = "";
    return s1.compareTo(s2);
  } //	compare

  /**
   * Test / Load
   *
   * @param args
   */
  public static void main(String[] args) {
    Compiere.startup(true);
    /**
     * To add your regions, complete the code below. Please make sure that the file is converted via
     * the Java utility native2ascii - i.e. all seven bit code with /u0000 unicode stuff
     */
    int C_Country_ID = 216; // 	Japan
    MCountry country = new MCountry(Env.getCtx(), C_Country_ID, null);
    // Hokkaido
    MRegion temp = new MRegion(country, "\u5317\u6d77\u9053");
    temp.setDescription("\u5317\u6d77\u9053(Hokkaido)");
    temp.save();
    // Aomori
    temp = new MRegion(country, "\u9752\u68ee\u770c");
    temp.setDescription("\u9752\u68ee\u770c(Aomori)");
    temp.save();
    // Iwate
    temp = new MRegion(country, "\u5ca9\u624b\u770c");
    temp.setDescription("\u5ca9\u624b\u770c(Iwate)");
    temp.save();
    // Miyagi
    temp = new MRegion(country, "\u5bae\u57ce\u770c");
    temp.setDescription("\u5bae\u57ce\u770c(Miyagi)");
    temp.save();
    // Akita
    temp = new MRegion(country, "\u79cb\u7530\u770c");
    temp.setDescription("\u79cb\u7530\u770c(Akita)");
    temp.save();
    // Yamagata
    temp = new MRegion(country, "\u5c71\u5f62\u770c");
    temp.setDescription("\u5c71\u5f62\u770c(Yamagata)");
    temp.save();
    // Fukushima
    temp = new MRegion(country, "\u798f\u5cf6\u770c");
    temp.setDescription("\u798f\u5cf6\u770c(Fukushima)");
    temp.save();
    // Ibaraki
    temp = new MRegion(country, "\u8328\u57ce\u770c");
    temp.setDescription("\u8328\u57ce\u770c(Ibaraki)");
    temp.save();
    // Gunma
    temp = new MRegion(country, "\u7fa4\u99ac\u770c");
    temp.setDescription("\u7fa4\u99ac\u770c(Gunma)");
    temp.save();
    // Saitama
    temp = new MRegion(country, "\u57fc\u7389\u770c");
    temp.setDescription("\u57fc\u7389\u770c(Saitama)");
    temp.save();
    // Chiba
    temp = new MRegion(country, "\u5343\u8449\u770c");
    temp.setDescription("\u5343\u8449\u770c(Chiba)");
    temp.save();
    // Tokyo
    temp = new MRegion(country, "\u6771\u4eac\u90fd");
    temp.setDescription("\u6771\u4eac\u90fd(Tokyo)");
    temp.save();
    // Kanagawa
    temp = new MRegion(country, "\u795e\u5948\u5ddd\u770c");
    temp.setDescription("\u795e\u5948\u5ddd\u770c(Kanagawa)");
    temp.save();
    // Niigata
    temp = new MRegion(country, "\u65b0\u6f5f\u770c");
    temp.setDescription("\u65b0\u6f5f\u770c(Niigata)");
    temp.save();
    // Toyama
    temp = new MRegion(country, "\u5bcc\u5c71\u770c");
    temp.setDescription("\u5bcc\u5c71\u770c(Toyama)");
    temp.save();
    // Ishikawa
    temp = new MRegion(country, "\u77f3\u5ddd\u770c");
    temp.setDescription("\u77f3\u5ddd\u770c(Ishikawa)");
    temp.save();
    // Fukui
    temp = new MRegion(country, "\u798f\u4e95\u770c");
    temp.setDescription("\u798f\u4e95\u770c(Fukui)");
    temp.save();
    // Yamanashi
    temp = new MRegion(country, "\u5c71\u68a8\u770c");
    temp.setDescription("\u5c71\u68a8\u770c(Yamanashi)");
    temp.save();
    // Gifu
    temp = new MRegion(country, "\u5c90\u961c\u770c");
    temp.setDescription("\u5c90\u961c\u770c(Gifu)");
    temp.save();
    // Shizuoka
    temp = new MRegion(country, "\u9759\u5ca1\u770c");
    temp.setDescription("\u9759\u5ca1\u770c(Shizuoka)");
    temp.save();
    // Aichi
    temp = new MRegion(country, "\u611b\u77e5\u770c");
    temp.setDescription("\u611b\u77e5\u770c(Aichi)");
    temp.save();
    // Mie
    temp = new MRegion(country, "\u4e09\u91cd\u770c");
    temp.setDescription("\u4e09\u91cd\u770c(Mie)");
    temp.save();
    // Siga
    temp = new MRegion(country, "\u6ecb\u8cc0\u770c");
    temp.setDescription("\u6ecb\u8cc0\u770c(Siga)");
    temp.save();
    // Kyoto
    temp = new MRegion(country, "\u4eac\u90fd\u5e9c");
    temp.setDescription("\u4eac\u90fd\u5e9c(Kyoto)");
    temp.save();
    // Osaka
    temp = new MRegion(country, "\u5927\u962a\u5e9c");
    temp.setDescription("\u5927\u962a\u5e9c(Osaka)");
    temp.save();
    // Hyogo
    temp = new MRegion(country, "\u5175\u5eab\u770c");
    temp.setDescription("\u5175\u5eab\u770c(Hyogo)");
    temp.save();
    // Nara
    temp = new MRegion(country, "\u5948\u826f\u770c");
    temp.setDescription("\u5948\u826f\u770c(Nara)");
    temp.save();
    // Wakayama
    temp = new MRegion(country, "\u548c\u6b4c\u5c71\u770c");
    temp.setDescription("\u548c\u6b4c\u5c71\u770c(Wakayama)");
    temp.save();
    // Tottori
    temp = new MRegion(country, "\u9ce5\u53d6\u770c");
    temp.setDescription("\u9ce5\u53d6\u770c(Tottori)");
    temp.save();
    // Shimane
    temp = new MRegion(country, "\u5cf6\u6839\u770c");
    temp.setDescription("\u5cf6\u6839\u770c(Shimane)");
    temp.save();
    // Okayama
    temp = new MRegion(country, "\u5ca1\u5c71\u770c");
    temp.setDescription("\u5ca1\u5c71\u770c(Okayama)");
    temp.save();
    // Hiroshima
    temp = new MRegion(country, "\u5e83\u5cf6\u770c");
    temp.setDescription("\u5e83\u5cf6\u770c(Hiroshima)");
    temp.save();
    // Yamaguchi
    temp = new MRegion(country, "\u5c71\u53e3\u770c");
    temp.setDescription("\u5c71\u53e3\u770c(Yamaguchi)");
    temp.save();
    // Tokushima
    temp = new MRegion(country, "\u5fb3\u5cf6\u770c");
    temp.setDescription("\u5fb3\u5cf6\u770c(Tokushima)");
    temp.save();
    // Kagawa
    temp = new MRegion(country, "\u9999\u5ddd\u770c");
    temp.setDescription("\u9999\u5ddd\u770c(Kagawa)");
    temp.save();
    // Ehime
    temp = new MRegion(country, "\u611b\u5a9b\u770c");
    temp.setDescription("\u611b\u5a9b\u770c(Ehime)");
    temp.save();
    // Kouchi
    temp = new MRegion(country, "\u9ad8\u77e5\u770c");
    temp.setDescription("\u9ad8\u77e5\u770c(Kouchi)");
    temp.save();
    // Fukuoka
    temp = new MRegion(country, "\u798f\u5ca1\u770c");
    temp.setDescription("\u798f\u5ca1\u770c(Fukuoka)");
    temp.save();
    // Saga
    temp = new MRegion(country, "\u4f50\u8cc0\u770c");
    temp.setDescription("\u4f50\u8cc0\u770c(Saga)");
    temp.save();
    // Nagasaki
    temp = new MRegion(country, "\u9577\u5d0e\u770c");
    temp.setDescription("\u9577\u5d0e\u770c(Nagasaki)");
    temp.save();
    // Kumamoto
    temp = new MRegion(country, "\u718a\u672c\u770c");
    temp.setDescription("\u718a\u672c\u770c(Kumamoto)");
    temp.save();
    // Ohita
    temp = new MRegion(country, "\u5927\u5206\u770c");
    temp.setDescription("\u5927\u5206\u770c(Ohita)");
    temp.save();
    // Miyasaki
    temp = new MRegion(country, "\u5bae\u5d0e\u770c");
    temp.setDescription("\u5bae\u5d0e\u770c(Miyasaki)");
    temp.save();
    // Kagoshima
    temp = new MRegion(country, "\u9e7f\u5150\u5cf6\u770c");
    temp.setDescription("\u9e7f\u5150\u5cf6\u770c(Kagoshima)");
    temp.save();
    // Okinawa
    temp = new MRegion(country, "\u6c96\u7e04\u770c");
    temp.setDescription("\u6c96\u7e04\u770c(Okinawa)");
    temp.save();
  } //	main
} //	MRegion
/**
 * Process Interface Controller.
 *
 * @author Jorg Janke
 * @version $Id: WProcessCtl.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $
 */
public class WProcessCtl extends Thread {
  /**
   * Async Process - Do it all. <code>
   * - Get Instance ID
   * - Get Parameters
   * - execute (lock - start process - unlock)
   *  </code> Creates a ProcessCtl instance, which calls lockUI and unlockUI if parent is a
   * ASyncProcess <br>
   * Called from ProcessCtl.startProcess, ProcessDialog.actionPerformed, APanel.cmd_print,
   * APanel.actionButton, VPaySelect.cmd_generate
   *
   * @param parent ASyncProcess & Container
   * @param WindowNo window no
   * @param pi ProcessInfo process info
   * @param trx Transaction
   * @return worker started ProcessCtl instance or null for workflow
   */
  public static WProcessCtl process(
      Object parent, int WindowNo, ProcessInfo pi, Trx trx, HttpServletRequest request) {
    log.fine("WindowNo=" + WindowNo + " - " + pi);
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MPInstance instance = new MPInstance(wsc.ctx, pi.getAD_Process_ID(), pi.getRecord_ID());

    if (!instance.save()) {
      pi.setSummary(Msg.getMsg(wsc.ctx, "ProcessNoInstance"));
      pi.setError(true);
      return null;
    }
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());

    //	Get Parameters (Dialog)
    /**
     * ProcessParameter para = new ProcessParameter (Env.getFrame((Container)parent), WindowNo, pi);
     * if (para.initDialog()) { para.setVisible(true); if (!para.isOK()) { pi.setSummary
     * (Msg.getMsg(Env.getCtx(), "ProcessCancelled")); pi.setError (true); return null; } }
     */
    //	execute
    WProcessCtl worker = new WProcessCtl(parent, pi, trx, wsc.ctx);
    worker.start(); // 	MUST be start!
    return worker;
  } //	execute

  /**
   * ************************************************************************ Constructor
   *
   * @param parent Container & ASyncProcess
   * @param pi Process info
   * @param trx Transaction Created in process(), VInvoiceGen.generateInvoices
   */
  public WProcessCtl(Object parent, ProcessInfo pi, Trx trx, Properties wscctx) {
    m_parent = parent;
    m_pi = pi;
    m_wscctx = wscctx;
    m_trx = trx; // 	handeled correctly
  } //  ProcessCtl

  private Object m_parent;
  private Properties m_wscctx;
  private ProcessInfo m_pi;
  private Trx m_trx;
  private Waiting m_waiting;
  private boolean m_IsServerProcess = false;

  /** Static Logger */
  private static CLogger log = CLogger.getCLogger(WProcessCtl.class);

  /**
   * Execute Process Instance and Lock UI. Calls lockUI and unlockUI if parent is a ASyncProcess
   *
   * <pre>
   * 	- Get Process Information
   *      - Call Class
   * 	- Submit SQL Procedure
   * 	- Run SQL Procedure
   * </pre>
   */
  public void run() {
    log.fine("AD_PInstance_ID=" + m_pi.getAD_PInstance_ID() + ", Record_ID=" + m_pi.getRecord_ID());

    //  Lock
    // lock();
    //	try {System.out.println(">> sleeping ..");sleep(20000);System.out.println(".. sleeping <<");}
    // catch (Exception e) {}

    //	Get Process Information: Name, Procedure Name, ClassName, IsReport, IsDirectPrint
    String ProcedureName = "";
    int AD_ReportView_ID = 0;
    int AD_Workflow_ID = 0;
    boolean IsReport = false;
    boolean IsDirectPrint = false;
    //
    String sql =
        "SELECT p.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," //	1..4
            + " p.isReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," //	5..8
            + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE,"
            + " p.IsServerProcess "
            + "FROM AD_Process p"
            + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
            + "WHERE p.IsActive='Y'"
            + " AND i.AD_PInstance_ID=?";
    if (!Env.isBaseLanguage(m_wscctx, "AD_Process"))
      sql =
          "SELECT t.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," //	1..4
              + " p.isReport, p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," //	5..8
              + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE,"
              + " p.IsServerProcess "
              + "FROM AD_Process p"
              + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
              + " INNER JOIN AD_Process_Trl t ON (p.AD_Process_ID=t.AD_Process_ID"
              + " AND t.AD_Language='"
              + Env.getAD_Language(m_wscctx)
              + "') "
              + "WHERE p.IsActive='Y'"
              + " AND i.AD_PInstance_ID=?";
    //
    try {
      PreparedStatement pstmt =
          DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, null);
      pstmt.setInt(1, m_pi.getAD_PInstance_ID());
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        m_pi.setTitle(rs.getString(1));
        if (m_waiting != null) m_waiting.setTitle(m_pi.getTitle());
        ProcedureName = rs.getString(2);
        m_pi.setClassName(rs.getString(3));
        m_pi.setAD_Process_ID(rs.getInt(4));
        //	Report
        if ("Y".equals(rs.getString(5))) {
          IsReport = true;
          if ("Y".equals(rs.getString(6)) && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW))
            IsDirectPrint = true;
        }
        AD_ReportView_ID = rs.getInt(7);
        AD_Workflow_ID = rs.getInt(8);
        //
        int estimate = rs.getInt(9);
        if (estimate != 0) {
          m_pi.setEstSeconds(estimate + 1); //  admin overhead
          if (m_waiting != null) m_waiting.setTimerEstimate(m_pi.getEstSeconds());
        }
        m_IsServerProcess = "Y".equals(rs.getString(10));
      } else log.log(Level.SEVERE, "No AD_PInstance_ID=" + m_pi.getAD_PInstance_ID());
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      m_pi.setSummary(
          Msg.getMsg(m_wscctx, "ProcessNoProcedure") + " " + e.getLocalizedMessage(), true);
      // unlock();
      log.log(Level.SEVERE, "run", e);
      return;
    }

    //  No PL/SQL Procedure
    if (ProcedureName == null) ProcedureName = "";

    /** ******************************************************************** Workflow */
    if (AD_Workflow_ID > 0) {
      startWorkflow(AD_Workflow_ID);
      // unlock();
      return;
    }

    /** ******************************************************************** Start Optional Class */
    if (m_pi.getClassName() != null) {
      //	Run Class
      if (!startProcess()) {
        // unlock();
        return;
      }

      //  No Optional SQL procedure ... done
      if (!IsReport && ProcedureName.length() == 0) {
        // unlock ();
        return;
      }
      //  No Optional Report ... done
      if (IsReport && AD_ReportView_ID == 0) {
        // unlock ();
        return;
      }
    }

    //  If not a report, we need a prodedure name
    if (!IsReport && ProcedureName.length() == 0) {
      m_pi.setSummary(Msg.getMsg(m_wscctx, "ProcessNoProcedure"), true);
      // unlock();
      return;
    }

    /** ******************************************************************** Report submission */
    if (IsReport) {
      //	Optional Pre-Report Process
      if (ProcedureName.length() > 0) {
        if (!startDBProcess(ProcedureName)) {
          // unlock();
          return;
        }
      } //	Pre-Report

      //	Start Report	-----------------------------------------------
      boolean ok = ReportCtl.start(m_pi, IsDirectPrint);
      m_pi.setSummary("Report", !ok);
      // unlock ();
    }
    /** ******************************************************************** Process submission */
    else {
      if (!startDBProcess(ProcedureName)) {
        // unlock();
        return;
      }
      //	Success - getResult
      ProcessInfoUtil.setSummaryFromDB(m_pi);
      // unlock();
    } //	*** Process submission ***
    //	log.fine(Log.l3_Util, "ProcessCtl.run - done");
  } //  run

  /** Lock UI & show Waiting */
  /**
   * private void lock () { // log.info("..."); JFrame frame = Env.getFrame((Container)m_parent); if
   * (frame instanceof AWindow) ((AWindow)frame).setBusyTimer(m_pi.getEstSeconds()); else m_waiting
   * = new Waiting (frame, Msg.getMsg(Env.getCtx(), "Processing"), false, m_pi.getEstSeconds());
   * SwingUtilities.invokeLater(new Runnable() { public void run() { log.finer("lock");
   * m_parent.lockUI(m_pi); } }); if (m_waiting != null) { m_waiting.toFront();
   * m_waiting.setVisible(true); } } // lock
   */
  /** Unlock UI & dispose Waiting. Called from run() */
  /**
   * private void unlock () { // log.info("..."); if (m_pi.isBatch()) m_pi.setIsTimeout(true);
   * SwingUtilities.invokeLater(new Runnable() { public void run() { String summary =
   * m_pi.getSummary(); log.finer("unlock - " + summary); if (summary != null &&
   * summary.indexOf("@") != -1) m_pi.setSummary(Msg.parseTranslation(Env.getCtx(), summary));
   * m_parent.unlockUI(m_pi); } }); // Remove Waiting/Processing Indicator if (m_waiting != null)
   * m_waiting.dispose(); m_waiting = null; } // unlock
   */
  /**
   * ************************************************************************ Start Workflow.
   *
   * @param AD_Workflow_ID workflow
   * @return true if started
   */
  private boolean startWorkflow(int AD_Workflow_ID) {
    log.fine(AD_Workflow_ID + " - " + m_pi);
    boolean started = false;
    if (DB.isRemoteProcess()) {
      log.info("trying to running on the server");
      Server server = CConnection.get().getServer();
      try {
        if (server != null) { // 	See ServerBean
          log.info("running on the server");
          m_pi = server.workflow(m_wscctx, m_pi, AD_Workflow_ID);
          log.finest("server => " + m_pi);
          started = true;
        }
      } catch (Exception ex) {
        log.log(Level.SEVERE, "AppsServer error", ex);
        started = false;
      }
    }
    //	Run locally
    if (!started && !m_IsServerProcess) {
      log.info("running locally");
      MWorkflow wf = MWorkflow.get(m_wscctx, AD_Workflow_ID);
      MWFProcess wfProcess = null;
      if (m_pi.isBatch()) wfProcess = wf.start(m_pi); // 	may return null
      else wfProcess = wf.startWait(m_pi); // 	may return null
      started = wfProcess != null;
    }
    return started;
  } //  startWorkflow

  /**
   * ************************************************************************ Start Java Process
   * Class. instanciate the class implementing the interface ProcessCall. The class can be a
   * Server/Client class (when in Package org compiere.process or org.compiere.model) or a client
   * only class (e.g. in org.compiere.report)
   *
   * @return true if success
   */
  private boolean startProcess() {
    log.fine(m_pi.toString());
    boolean started = false;
    if (DB.isRemoteProcess()) {
      Server server = CConnection.get().getServer();
      try {
        if (server != null) { // 	See ServerBean
          m_pi = server.process(m_wscctx, m_pi);
          log.finest("server => " + m_pi);
          started = true;
        }
      } catch (UndeclaredThrowableException ex) {
        Throwable cause = ex.getCause();
        if (cause != null) {
          if (cause instanceof InvalidClassException)
            log.log(
                Level.SEVERE, "Version Server <> Client: " + cause.toString() + " - " + m_pi, ex);
          else
            log.log(Level.SEVERE, "AppsServer error(1b): " + cause.toString() + " - " + m_pi, ex);
        } else log.log(Level.SEVERE, " AppsServer error(1) - " + m_pi, ex);
        started = false;
      } catch (Exception ex) {
        Throwable cause = ex.getCause();
        if (cause == null) cause = ex;
        log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause);
        started = false;
      }
    }
    //	Run locally
    if (!started && !m_IsServerProcess) {
      ProcessCall myObject = null;
      try {
        Class myClass = Class.forName(m_pi.getClassName());
        myObject = (ProcessCall) myClass.newInstance();
        if (myObject == null) m_pi.setSummary("No Instance for " + m_pi.getClassName(), true);
        else myObject.startProcess(m_wscctx, m_pi, m_trx);
        if (m_trx != null) {
          m_trx.commit();
          m_trx.close();
        }
      } catch (Exception e) {
        if (m_trx != null) {
          m_trx.rollback();
          m_trx.close();
        }
        m_pi.setSummary("Error starting Class " + m_pi.getClassName(), true);
        log.log(Level.SEVERE, m_pi.getClassName(), e);
      }
    }
    return !m_pi.isError();
  } //  startProcess

  /**
   * ************************************************************************ Start Database Process
   *
   * @param ProcedureName PL/SQL procedure name
   * @return true if success
   */
  private boolean startDBProcess(String ProcedureName) {
    //  execute on this thread/connection
    log.fine(ProcedureName + "(" + m_pi.getAD_PInstance_ID() + ")");
    String sql = "{call " + ProcedureName + "(?)}";
    try {
      CallableStatement cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, null); // 	ro??
      cstmt.setInt(1, m_pi.getAD_PInstance_ID());
      cstmt.executeUpdate();
      cstmt.close();
    } catch (Exception e) {
      log.log(Level.SEVERE, sql, e);
      m_pi.setSummary(Msg.getMsg(m_wscctx, "ProcessRunError") + " " + e.getLocalizedMessage());
      m_pi.setError(true);
      return false;
    }
    //	log.fine(Log.l4_Data, "ProcessCtl.startProcess - done");
    return true;
  } //  startDBProcess
} //	ProcessCtl