コード例 #1
0
ファイル: WProcessCtl.java プロジェクト: makezjdq/adempiere-1
 /**
  * ************************************************************************ 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
コード例 #2
0
 /**
  * ************************************************************************ Create Missing
  * Document Types
  *
  * @param ctx context
  * @param AD_Client_ID client
  * @param sp server process
  * @param trx transaction
  */
 public static void createDocumentTypes(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) {
   s_log.info("AD_Client_ID=" + AD_Client_ID);
   String sql =
       "SELECT rl.Value, rl.Name "
           + "FROM AD_Ref_List rl "
           + "WHERE rl.AD_Reference_ID=183"
           + " AND rl.IsActive='Y' AND NOT EXISTS "
           + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, trx);
     pstmt.setInt(1, AD_Client_ID);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       String name = rs.getString(2);
       String value = rs.getString(1);
       s_log.config(name + "=" + value);
       MDocType dt = new MDocType(ctx, value, name, trx);
       if (dt.save()) {
         if (sp != null) sp.addLog(0, null, null, name);
         else s_log.fine(name);
       } else {
         if (sp != null) sp.addLog(0, null, null, "Not created: " + name);
         else s_log.warning("Not created: " + name);
       }
     }
   } catch (Exception e) {
     s_log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeResultSet(rs);
     DB.closeStatement(pstmt);
   }
 } //	createDocumentTypes
コード例 #3
0
ファイル: LdapResult.java プロジェクト: WilkerDiaz/Compiere
 /**
  * Generate LDAPResult
  *
  * @param dn Distinguished Name
  * @param resultProtocol Result protocol/operation code
  * @param resultCode Result code
  * @param errMsg Error Message
  * @return reponse
  */
 private void generateResult(String dn, int resultProtocol, int resultCode, String errMsg) {
   try {
     m_encoder.beginSeq(48); // Hard coded here for Envelope header
     m_encoder.encodeInt(m_ldapMsg.getMsgId());
     m_encoder.beginSeq(resultProtocol);
     m_encoder.encodeInt(resultCode, 10); // Enumeration - 10
     // Adding LDAPDN
     m_encoder.encodeString(dn, true);
     // Adding error message
     m_encoder.encodeString(errMsg == null ? "" : errMsg, true);
     m_encoder.endSeq();
     m_encoder.endSeq();
     log.fine(
         "#"
             + m_ldapMsg.getMsgId()
             + ": "
             + "dn="
             + dn
             + ", op="
             + resultProtocol
             + ", result="
             + resultCode
             + ", errMsg="
             + errMsg);
   } catch (Exception ex) {
     log.log(Level.SEVERE, "", ex);
   }
 } // generateResult
コード例 #4
0
ファイル: WProcessCtl.java プロジェクト: makezjdq/adempiere-1
 /**
  * ************************************************************************ 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
コード例 #5
0
ファイル: WProcessCtl.java プロジェクト: makezjdq/adempiere-1
 /**
  * ************************************************************************ 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
コード例 #6
0
  /**
   * Create Period Controls
   *
   * @param ctx context
   * @param AD_Client_ID client
   * @param sp server process
   * @param trx transaction
   */
  public static void createPeriodControls(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trx) {
    s_log.info("AD_Client_ID=" + AD_Client_ID);

    //	Delete Duplicates
    String sql =
        "DELETE FROM C_PeriodControl "
            + "WHERE (C_Period_ID, DocBaseType) IN "
            + "(SELECT C_Period_ID, DocBaseType "
            + "FROM C_PeriodControl pc2 "
            + "GROUP BY C_Period_ID, DocBaseType "
            + "HAVING COUNT(*) > 1)"
            + " AND C_PeriodControl_ID NOT IN "
            + "(SELECT MIN(C_PeriodControl_ID) "
            + "FROM C_PeriodControl pc3 "
            + "GROUP BY C_Period_ID, DocBaseType)";
    int no = DB.executeUpdate(trx, sql);
    s_log.info("Duplicates deleted #" + no);

    //	Insert Missing
    sql =
        "SELECT DISTINCT p.AD_Client_ID, p.C_Period_ID, dbt.DocBaseType "
            + "FROM C_Period p, "
            + "C_DocBaseType dbt "
            + "WHERE p.AD_Client_ID=? "
            + " AND NOT EXISTS"
            + " (SELECT * FROM C_PeriodControl pc "
            + "WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dbt.DocBaseType)"
            + " AND (dbt.AD_Client_ID = 0 OR p.AD_Client_ID = dbt.AD_Client_ID)";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int counter = 0;
    try {
      pstmt = DB.prepareStatement(sql, trx);
      pstmt.setInt(1, AD_Client_ID);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        int Client_ID = rs.getInt(1);
        int C_Period_ID = rs.getInt(2);
        String DocBaseType = rs.getString(3);
        s_log.config(
            "AD_Client_ID="
                + Client_ID
                + ", C_Period_ID="
                + C_Period_ID
                + ", DocBaseType="
                + DocBaseType);
        //
        MPeriodControl pc = new MPeriodControl(ctx, Client_ID, C_Period_ID, DocBaseType, trx);
        if (pc.save()) {
          counter++;
          s_log.fine(pc.toString());
        } else s_log.warning("Not saved: " + pc);
      }
    } catch (Exception e) {
      s_log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
    if (sp != null) sp.addLog(0, null, new BigDecimal(counter), "@C_PeriodControl_ID@ @Created@");
    s_log.info("Inserted #" + counter);
  } //	createPeriodControls
コード例 #7
0
ファイル: LdapResult.java プロジェクト: WilkerDiaz/Compiere
  /**
   * Get the response according to the request message
   *
   * @param model model
   * @param remoteHost remote host name
   * @param remoteAddr remote host ip address
   * @return response
   */
  public byte[] getResult(MLdapProcessor model, String remoteHost, String remoteAddr) {
    if (m_errNo != LDAP_SUCCESS) {
      generateResult(
          "",
          (m_ldapMsg.getOperation() == LdapMessage.BIND_REQUEST
              ? LdapMessage.BIND_RESPONSE
              : LdapMessage.SEARCH_RES_RESULT),
          m_errNo,
          ldapErrorMessage[m_errNo] + ": " + m_errStr);
      m_encoder.getTrimmedBuf();
    }

    try {
      String usrId = m_ldapMsg.getUserId();
      String o = m_ldapMsg.getOrg();
      String ou = m_ldapMsg.getOrgUnit();
      int msgId = m_ldapMsg.getMsgId();

      // Adding the Application 1 Sequence
      if (m_ldapMsg.getOperation() == LdapMessage.BIND_REQUEST) {
        String pwd = m_ldapMsg.getUserPasswd();
        if (pwd == null || pwd.length() <= 0) {
          // 1st anonymous bind
          generateResult(m_ldapMsg.getDN(), LdapMessage.BIND_RESPONSE, LDAP_SUCCESS, null);
          log.config("#" + msgId + ": Success on anonymous bind");
          return m_encoder.getTrimmedBuf();
        }

        // Authenticate with Compiere data
        if (m_ldapUser.getUserId()
            == null) { // Try to authenticate on the 1st bind, must be java client
          m_ldapUser.reset();
          model.authenticate(m_ldapUser, usrId, o, ou, remoteHost, remoteAddr);
          if (m_ldapUser.getErrorMsg() != null) { // Failed to authenticated with compiere
            m_errNo = LDAP_NO_SUCH_OBJECT;
            generateResult(
                m_ldapMsg.getBaseObj(),
                LdapMessage.SEARCH_RES_RESULT,
                LDAP_NO_SUCH_OBJECT,
                ldapErrorMessage[LDAP_NO_SUCH_OBJECT] + m_ldapUser.getErrorMsg());
            log.config("#" + msgId + ": Failed with bind");
            return m_encoder.getTrimmedBuf();
          }
        }

        // Check to see if the input passwd is match to the one
        // in compiere database
        if (m_ldapUser.getUserId() != null
            && m_ldapUser.getPassword() != null
            && usrId.compareTo(m_ldapUser.getUserId()) == 0
            && !SecureEngine.isEncrypted(pwd)
            && (pwd.compareTo(m_ldapUser.getPassword()) == 0
                || pwd.compareTo(SecureEngine.decrypt(m_ldapUser.getPassword()))
                    == 0)) { // Successfully authenticated
          generateResult("", LdapMessage.BIND_RESPONSE, LDAP_SUCCESS, null);
          // Close the connection to client since most of the client
          // application might cache the connection but we can't afford
          // to have too many such client connection
          m_disconnect = true;
          log.config("#" + msgId + ": Success authenticate with password");
        } else { // Unsuccessfully authenticated
          m_errNo = LDAP_INAPPROPRIATE_AUTHENTICATION;
          generateResult(
              "",
              LdapMessage.BIND_RESPONSE,
              LDAP_INAPPROPRIATE_AUTHENTICATION,
              ldapErrorMessage[LDAP_INAPPROPRIATE_AUTHENTICATION]);
          log.info(
              "#" + msgId + ": Failed : " + ldapErrorMessage[LDAP_INAPPROPRIATE_AUTHENTICATION]);
        }
      } else if (m_ldapMsg.getOperation() == LdapMessage.SEARCH_REQUEST) {
        // Authenticate with compiere database
        m_ldapUser.reset();
        model.authenticate(m_ldapUser, usrId, o, ou, remoteHost, remoteAddr);
        if (m_ldapUser.getErrorMsg() != null) {
          m_errNo = LDAP_NO_SUCH_OBJECT;
          generateResult(
              m_ldapMsg.getBaseObj(),
              LdapMessage.SEARCH_RES_RESULT,
              LDAP_NO_SUCH_OBJECT,
              ldapErrorMessage[LDAP_NO_SUCH_OBJECT] + m_ldapUser.getErrorMsg());
          log.info("#" + msgId + ": Failed with SEARCH_REQUEST");
          return m_encoder.getTrimmedBuf();
        }

        m_encoder.beginSeq(48); // Hard coded here for Envelope header
        m_encoder.encodeInt(msgId);
        m_encoder.beginSeq(LdapMessage.SEARCH_REP_ENTRY); // Application 4
        m_encoder.encodeString("cn=" + m_ldapMsg.getUserId(), true); // this should be object name
        // not going to put in any attributes for this
        m_encoder.beginSeq(48);
        m_encoder.endSeq();
        m_encoder.endSeq();
        m_encoder.endSeq();

        // SearchResultDone Application 5 for bind
        // Result 0 = success
        // No error message
        generateResult(m_ldapMsg.getBaseObj(), LdapMessage.SEARCH_RES_RESULT, LDAP_SUCCESS, null);
        log.config("#" + msgId + ": Success with SEARCH_REQUEST");
      }

      return m_encoder.getTrimmedBuf();
    } catch (Exception e) {
      log.log(Level.SEVERE, "", e);

      // Get the response operation
      int responseOp = LdapMessage.BIND_RESPONSE;
      if (m_ldapMsg.getOperation() == LdapMessage.SEARCH_REQUEST)
        responseOp = LdapMessage.SEARCH_RES_RESULT;

      // Send the response to the client and disconnect
      m_errNo = LDAP_OTHER;
      generateResult(
          m_ldapMsg.getBaseObj(),
          responseOp,
          LDAP_OTHER,
          ldapErrorMessage[LDAP_OTHER] + e.getMessage());
      m_disconnect = true;
    }

    return m_encoder.getTrimmedBuf();
  } //	getResult
コード例 #8
0
ファイル: WProcessCtl.java プロジェクト: makezjdq/adempiere-1
  /**
   * 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