Package org.openbravo.model.ad.process

Examples of org.openbravo.model.ad.process.ProcessInstance


      Map<String, String> parameters) {

    final boolean currentAdminMode = OBContext.getOBContext().setInAdministratorMode(true);
    try {
      // Create the pInstance
      final ProcessInstance pInstance = OBProvider.getInstance().get(ProcessInstance.class);
      // sets its process
      pInstance.setProcess(process);
      // must be set to true
      pInstance.setActive(true);
      if (recordID != null) {
        pInstance.setRecordID(recordID);
      } else {
        pInstance.setRecordID("0");
      }

      // get the user from the context
      pInstance.setUserContact(OBContext.getOBContext().getUser());

      // now create the parameters and set their values
      if (parameters != null) {
        int index = 0;
        for (String key : parameters.keySet()) {
          index++;
          final String value = parameters.get(key);
          final Parameter parameter = OBProvider.getInstance().get(Parameter.class);
          parameter.setSequenceNumber(index + "");
          parameter.setParameterName(key);
          parameter.setString(value);

          // set both sides of the bidirectional association
          pInstance.getADParameterList().add(parameter);
          parameter.setProcessInstance(pInstance);
        }
      }

      // persist to the db
      OBDal.getInstance().save(pInstance);

      // flush, this gives pInstance an ID
      OBDal.getInstance().flush();

      // call the SP
      try {
        // first get a connection
        final Connection connection = OBDal.getInstance().getConnection();
        // connection.createStatement().execute("CALL M_InOut_Create0(?)");

        final Properties obProps = OBPropertiesProvider.getInstance().getOpenbravoProperties();
        final PreparedStatement ps;
        if (obProps.getProperty("bbdd.rdbms") != null
            && obProps.getProperty("bbdd.rdbms").equals("POSTGRE")) {
          ps = connection.prepareStatement("SELECT * FROM " + process.getProcedure() + "(?)");
        } else {
          ps = connection.prepareStatement(" CALL " + process.getProcedure() + "(?)");
        }

        ps.setString(1, pInstance.getId());
        ps.execute();
      } catch (Exception e) {
        throw new IllegalStateException(e);
      }

View Full Code Here

TOP

Related Classes of org.openbravo.model.ad.process.ProcessInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.