Ladies_Man

#sonic 819 autorun DEMO

Sep 8th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 19.91 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.ResultSet;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Set;
  10.  
  11. import org.apache.commons.logging.Log;
  12. import org.apache.commons.logging.LogFactory;
  13. import org.joda.time.DateTime;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15.  
  16. import ru.it.metasonic.ruspost.infopoint.utils.BOHelper;
  17. import ru.lbpm.metasonic.businessobjects.DbHelper;
  18. import ru.lbpm.metasonic.businessobjects.DbHelper.ValueWrapper;
  19.  
  20. import com.jcom1.api.dto.init.InitProcessInstanceData;
  21. import com.jcom1.api.dto.interfaces.IProcessInstanceBean;
  22. import com.jcom1.api.dto.interfaces.IStorageInstanceBean;
  23. import com.jcom1.api.dto.interfaces.ISubjectInstanceBean;
  24. import com.jcom1.api.exceptions.ConnectionException;
  25. import com.jcom1.api.interfaces.IAuthorizationAdministrationApi;
  26. import com.jcom1.api.interfaces.IAuthorizationApi;
  27. import com.jcom1.api.interfaces.IBo20AccessApi;
  28. import com.jcom1.api.interfaces.ICommonApi;
  29. import com.jcom1.api.interfaces.IInstanceAdministrationApi;
  30. import com.jcom1.api.util.Pair;
  31. import com.jcom1.runtime.refinement.AbstractRefinement;
  32. import com.jcom1.runtime.refinement.FunctionStateRequest;
  33. import com.jcom1.runtime.refinement.FunctionStateResponse;
  34. import com.jcom1.runtime.refinement.RefinementGenerator;
  35.  
  36. import de.metasonic.businessobjects.model.interfaces.IView;
  37. import de.metasonic.refinement.global.api.ApiUtils;
  38.  
  39. /**
  40.  * @generated
  41.  */
  42. /**
  43.  * This method is called when the named function state is reached State:
  44.  * автозапуск формирования StateType: FUNCTION
  45.  *
  46.  * Return values "FunctionTransitionDescription_WZGO8WRYEeaW6tb5t7D8Ag" when
  47.  * result is "" to go to state Ожидание запуска
  48.  *
  49.  * @return return the id of the transition to follow e.g. // return new
  50.  *         FunctionStateResponse("transitionXXXXXXXX");
  51.  */
  52. @RefinementGenerator(id = "InternalSubjectDescription_rhsOwWRXEeaW6tb5t7D8Ag")
  53. public class Оператор_по_контролю_ОПС_ОтделаRefinement extends
  54.         AbstractRefinement {
  55.  
  56.     @Autowired
  57.     ICommonApi commonApi;
  58.  
  59.     @Autowired
  60.     IBo20AccessApi accessApi;
  61.  
  62.     @Autowired
  63.     IAuthorizationApi authApi;
  64.  
  65.     @Autowired
  66.     IAuthorizationAdministrationApi administrationApi;
  67.  
  68.     private final String opsControlDescriptionId = "ProcessDescription_pn9a4VMdEeaL5PGyiwnPkA";
  69.     private final String opsControlFirstStateDescrId = "FunctionStateDescription_NZI2wWqtEeaiwr50C3BsOA";
  70.  
  71.     private final String DB_URL = "jdbc:hsqldb:hsql://localhost/jcom1";
  72.     private final String DB_USER = "sa";
  73.     private final String DB_PSW = "";
  74.  
  75.     private final String UFPS_INDEX = "UFPS_INDEX";
  76.     private final String UFPS_NAME = "UFPS_NAME";
  77.     private final String POSTAMT_INDEX = "POSTAMT_INDEX";
  78.     private final String POSTAMT_NAME = "POSTAMT_NAME";
  79.     private final String UM_GROUP = "UM_GROUP";
  80.     private final String UM_USER = "UM_USER";
  81.     private final String UM_GROUP_AS_INDEX = "INDX";
  82.     private final String UM_GROUP_AS_ROLE = "ROLE";
  83.     private final String RUSPOST_DEPARTMENT_CONTROLLER = "RUSPOST-DEPARTMENT-CONTROLLER";
  84.     private final String DEPARTMENT_CONTROLLER_GROUP_ID = "DEPARTMENT_CONTROLLER_GROUP_ID";
  85.  
  86.     private final String COMMON_INFO = "commonInfo";
  87.     private final String POSTAMT = "infoPoint";
  88.     private final String METADATA = "metaData";
  89.  
  90.     private int departmentControllerGroupId;
  91.     /**
  92.      * @generated
  93.      */
  94.     private final static Log log = LogFactory
  95.             .getLog("com.jcom1.refinement.автозапуск_автоформирования_плана.оператор_по_контролю_опс_отделаrefinement");
  96.  
  97.     /**
  98.      * This method is called when the named function state is reached State:
  99.      * автозапуск формирования StateType: FUNCTION
  100.      *
  101.      * Return values "FunctionTransitionDescription_WZGO8WRYEeaW6tb5t7D8Ag" when
  102.      * result is "" to go to state Ожидание запуска
  103.      *
  104.      * @return return the id of the transition to follow e.g. // return new
  105.      *         FunctionStateResponse("transitionXXXXXXXX");
  106.      */
  107.     @RefinementGenerator(id = "FunctionStateDescription_G_53Y2RYEeaW6tb5t7D8Ag")
  108.     public FunctionStateResponse functionавтозапуск_формирования(
  109.             FunctionStateRequest functionStateRequest) {
  110.         log.debug("\n");
  111.  
  112.         IInstanceAdministrationApi instanceAdminApi = null;
  113.         try {
  114.             instanceAdminApi = ApiUtils.lookupInstanceAdministrationApi();
  115.         } catch (ConnectionException e1) {
  116.             log.debug("error retrieving instanceAdministrationApi");
  117.         }
  118.  
  119.         String departmentControllerGroupIdQuery = "SELECT ID AS DEPARTMENT_CONTROLLER_GROUP_ID FROM UM_GROUP WHERE NAME = ?";
  120.  
  121.         String ufpsQuery = "SELECT DISTINCT UFPS_INDEX, UFPS_NAME FROM POSTAMT_VIEW";
  122.  
  123.         String potentialOwnersQuery = "SELECT A.UM_GROUP AS UFPS_INDEX, A.UM_USER, B.UM_GROUP AS DEPARTMENT_CONTROLLER_GROUP_ID "
  124.                 + "FROM UM_GROUP_UM_USER A "
  125.                 + "LEFT JOIN UM_GROUP_UM_USER B "
  126.                 + "ON A.UM_USER = B.UM_USER "
  127.                 + "WHERE A.UM_GROUP = ? AND B.UM_GROUP = ?";
  128.  
  129.         String postamtQuery = "SELECT POSTAMT_INDEX, POSTAMT_NAME FROM POSTAMT_VIEW WHERE UFPS_INDEX = ?";
  130.  
  131.         try (final Connection connection = DbHelper
  132.                 .getConnection(DbHelper.PROP_DB_INT);) {
  133.             log.debug("connection has been set");
  134.  
  135.             // form query as SELECT TOP 1 ID AS ...
  136.             departmentControllerGroupId = getDepartmentControllerGroupId(
  137.                     connection, departmentControllerGroupIdQuery,
  138.                     RUSPOST_DEPARTMENT_CONTROLLER);
  139.             log.debug(DEPARTMENT_CONTROLLER_GROUP_ID + ": "
  140.                     + departmentControllerGroupId);
  141.  
  142.             List<Pair> ufpsIndexNamePairs = getUfpsIndexNamePairs(connection,
  143.                     ufpsQuery);
  144.  
  145.             for (Pair ufpsIndexNamePair : ufpsIndexNamePairs) {
  146.  
  147.                 String ufpsIndex = ufpsIndexNamePair.getFirstElement();
  148.                 String ufpsName = ufpsIndexNamePair.getSecondElement();
  149.                 log.debug("     ufps: " + ufpsIndex + " / " + ufpsName);
  150.  
  151.                 // retrieve potential owners as:
  152.                 // users from current Ufps group that also belong to
  153.                 // RUSPOST-DEPARTMENT-CONTROLLER group
  154.                 // form query as ... WHERE a.UM_GROUP = 249030 AND b.UM_GROUP =
  155.                 // 13
  156.                 List<String> potentialOwners = getPotentialOwners(connection,
  157.                         potentialOwnersQuery, Integer.valueOf(ufpsIndex),
  158.                         departmentControllerGroupId);
  159.  
  160.                 if (0 == potentialOwners.size()) {
  161.                     log.debug("Skipping process creation for Ufps: "
  162.                             + ufpsIndex + "/" + ufpsName);
  163.                     log.debug("Reason: no potential owners were found for this Ufps");
  164.                     continue;
  165.                 }
  166.  
  167.                 // now as we got potOwners list
  168.                 // lets iterate over all postamts of current ufps
  169.                 List<Pair> postamtIndexNamePairs = getPostamtIndexNamePairs(
  170.                         connection, postamtQuery, ufpsIndex);
  171.  
  172.                 for (Pair postamtIndexNamePair : postamtIndexNamePairs) {
  173.  
  174.                     String postamtIndex = postamtIndexNamePair
  175.                             .getFirstElement();
  176.                     String postamtName = postamtIndexNamePair
  177.                             .getSecondElement();
  178.                     log.debug("     postamt: " + postamtIndex + " / "
  179.                             + postamtName);
  180.  
  181.                     // ============================================================================================================
  182.                     // now as we got single postamt
  183.                     // lets create a process for it
  184.                     log.debug("launching process");
  185.                     IProcessInstanceBean processInstanceBean = null;
  186.                     String procName = null;
  187.                     try {
  188.                         SimpleDateFormat sdf = new SimpleDateFormat(
  189.                                 "dd/MM/yyyy HH:mm:ss");
  190.                         procName = postamtName + " Контроль ОПС ["
  191.                                 + sdf.format(new Date()) + "]";
  192.                         String creatorId = commonApi.getSubjectInstanceBean(
  193.                                 functionStateRequest.getSubjectInstanceId())
  194.                                 .getEditor();
  195.                         int priority = 3;
  196.  
  197.                         processInstanceBean = createProcessInstance(
  198.                                 opsControlDescriptionId, procName, creatorId,
  199.                                 priority);
  200.  
  201.                         log.debug("process '" + procName + "' has been created");
  202.                     } catch (Exception e) {
  203.                         log.debug("error creating process instance with name: "
  204.                                 + procName);
  205.                     }
  206.  
  207.                     if (null != processInstanceBean) {
  208.                         log.debug("retrieving prime BO ad setting pot :) owners");
  209.                         ISubjectInstanceBean primeSubjectInstanceBean = getPrimeSubject(processInstanceBean);
  210.  
  211.                         // setting potential owners
  212.                         commonApi.releaseSubjectInstance(
  213.                                 Long.valueOf(primeSubjectInstanceBean.getId()),
  214.                                 opsControlFirstStateDescrId);
  215.                         instanceAdminApi.setPotentialOwners(
  216.                                 Long.valueOf(primeSubjectInstanceBean.getId()),
  217.                                 potentialOwners.toArray(new String[0]));
  218.  
  219.                         // retrieve prime BO to preset it's attributes
  220.                         IView operationPlan = createPrimeBO(primeSubjectInstanceBean);
  221.                         ISubjectInstanceBean newPrimeBean = getPrimeSubject(processInstanceBean);
  222.  
  223.                         log.debug("Editor has been removed. Potential owners["
  224.                                 + newPrimeBean.getPotentialOwners().length
  225.                                 + "/" + potentialOwners.size() + "]:");
  226.                         for (String o : newPrimeBean.getPotentialOwners())
  227.                             log.debug("-->" + o);
  228.  
  229.                         if (null != operationPlan) {
  230.                             // ============================================================================================================
  231.                             log.debug("retrieving opPlanCommonInfo");
  232.  
  233.                             // explicitly create commonInfo BO
  234.                             Class<?> opPlanCommonInfoType = BOHelper.getType(
  235.                                     operationPlan, COMMON_INFO);
  236.                             log.debug("comInfoTypeClass:"
  237.                                     + opPlanCommonInfoType);
  238.                             Object opPlanCommonInfoImpl = opPlanCommonInfoType
  239.                                     .newInstance();
  240.                             BOHelper.setAttribute(operationPlan, COMMON_INFO,
  241.                                     opPlanCommonInfoImpl);
  242.  
  243.                             Object commonInfo = BOHelper.getAttribute(
  244.                                     operationPlan, COMMON_INFO);
  245.  
  246.                             // retrieve newly created commonInfo and set
  247.                             // it'sattributes
  248.                             if (null != commonInfo) {
  249.                                 log.debug("commonInfo retrieved. setting date attributes");
  250.  
  251.                                 Date periodStart = DateTime.now()
  252.                                         .minusMonths(1).toDate();
  253.                                 Date periodEnd = DateTime.now().toDate();
  254.  
  255.                                 BOHelper.setAttribute(commonInfo,
  256.                                         "periodStart", periodStart);
  257.                                 BOHelper.setAttribute(commonInfo, "periodEnd",
  258.                                         periodEnd);
  259.                                 log.debug("date attribuites has been set");
  260.                             } else {
  261.                                 log.debug("error retrieving commonInfo");
  262.                             }
  263.  
  264.                             // ============================================================================================================
  265.                             log.debug("retrieving opPlanPostamt");
  266.  
  267.                             // explicitly create postamt BO
  268.                             Class<?> postamtType = BOHelper.getType(
  269.                                     operationPlan, POSTAMT);
  270.                             log.debug("postamtTypeCLass: " + postamtType);
  271.                             IView postamtImpl = (IView) (postamtType
  272.                                     .newInstance());
  273.                             BOHelper.setAttribute(postamtImpl,
  274.                                     "postamtPostamtIndex", postamtIndex);
  275.  
  276.                             List<IView> postamtViews = accessApi.getViews(
  277.                                     primeSubjectInstanceBean, postamtImpl);
  278.  
  279.                             if (1 == postamtViews.size()) {
  280.                                 BOHelper.setAttribute(operationPlan, POSTAMT,
  281.                                         postamtViews.get(0));
  282.                                 log.debug("postamt has been set");
  283.                             } else {
  284.                                 log.debug("error retrieving postamt by index: "
  285.                                         + postamtIndex
  286.                                         + " - no postamts at all or more than one postamt exists");
  287.                             }
  288.  
  289.                             // ============================================================================================================
  290.                             log.debug("saving BO changes");
  291.                             saveNewPrimeBO(primeSubjectInstanceBean,
  292.                                     operationPlan);
  293.  
  294.                         } else {
  295.                             log.debug("theres no opPlan BO for process: "
  296.                                     + procName);
  297.                         }
  298.                     } else {
  299.                         log.debug("theres no procInstanceBean for process: "
  300.                                 + procName);
  301.                     }
  302.                     log.debug("all done");
  303.                     log.debug("\n");
  304.  
  305.                 }
  306.             }
  307.  
  308.         } catch (Exception e2) {
  309.             e2.printStackTrace();
  310.         }
  311.  
  312.         return null;
  313.     }
  314.  
  315.     private int getDepartmentControllerGroupId(Connection connection,
  316.             String query, String departmentControllerGroupId) throws Exception {
  317.         log.debug("getRuspostDepartmentControllerGroupId begin");
  318.         log.debug("executing: " + query);
  319.  
  320.         List<ValueWrapper> valueWrappers = new ArrayList<ValueWrapper>();
  321.  
  322.         valueWrappers.add(new ValueWrapper(departmentControllerGroupId,
  323.                 String.class));
  324.  
  325.         int id = (int) DbHelper.executeQuery(connection, query, valueWrappers,
  326.                 true, new DbHelper.ResulSetHandler() {
  327.                     @Override
  328.                     public Object processResultSet(ResultSet rerSet)
  329.                             throws Exception {
  330.  
  331.                         if (rerSet.next())
  332.                             return rerSet
  333.                                     .getInt(DEPARTMENT_CONTROLLER_GROUP_ID);
  334.  
  335.                         return -1;
  336.                     }
  337.                 });
  338.  
  339.         log.debug("getRuspostDepartmentControllerGroupId end");
  340.         return id;
  341.     }
  342.  
  343.     private List<Pair> getUfpsIndexNamePairs(Connection connection, String query)
  344.             throws Exception {
  345.         log.debug("getUfpsIndexNamePairs begin");
  346.         log.debug("executing: " + query);
  347.  
  348.         List<ValueWrapper> valueWrappers = new ArrayList<ValueWrapper>();
  349.  
  350.         List<Pair> ufpsIndexNamePairs = (List<Pair>) DbHelper.executeQuery(
  351.                 connection, query, valueWrappers, true,
  352.                 new DbHelper.ResulSetHandler() {
  353.                     @Override
  354.                     public Object processResultSet(ResultSet result)
  355.                             throws Exception {
  356.                         List<Pair> ufpsIndexNamePairs = new ArrayList<Pair>();
  357.  
  358.                         while (result.next()) {
  359.  
  360.                             int ufpsIndex = result.getInt(UFPS_INDEX);
  361.                             String ufpsName = result.getString(UFPS_NAME);
  362.                             log.error("  ufps: " + ufpsIndex + " / " + ufpsName);
  363.  
  364.                             ufpsIndexNamePairs.add(new Pair(String
  365.                                     .valueOf(ufpsIndex), ufpsName));
  366.                         }
  367.  
  368.                         return ufpsIndexNamePairs;
  369.                     }
  370.                 });
  371.  
  372.         log.debug("getUfpsIndexNamePairs end");
  373.         return ufpsIndexNamePairs;
  374.     }
  375.  
  376.     private List<Pair> getPostamtIndexNamePairs(Connection connection,
  377.             String query, String ufpsIndex) throws Exception {
  378.         log.debug("getPostamtIndexNamePairs begin");
  379.         log.debug("executing: " + query);
  380.         int ufpsIndexInt = Integer.valueOf(ufpsIndex);
  381.  
  382.         List<ValueWrapper> valueWrappers = new ArrayList<ValueWrapper>();
  383.  
  384.         valueWrappers.add(new ValueWrapper(ufpsIndexInt, Integer.class));
  385.  
  386.         List<Pair> postamtIndexNamePairs = (List<Pair>) DbHelper.executeQuery(
  387.                 connection, query, valueWrappers, true,
  388.                 new DbHelper.ResulSetHandler() {
  389.                     @Override
  390.                     public Object processResultSet(ResultSet result)
  391.                             throws Exception {
  392.                         List<Pair> postamtIndexNamePairs = new ArrayList<Pair>();
  393.  
  394.                         while (result.next()) {
  395.  
  396.                             int postamtIndex = result.getInt(POSTAMT_INDEX);
  397.                             String postamtName = result.getString(POSTAMT_NAME);
  398.                             log.debug("  postamt: " + postamtIndex + " / "
  399.                                     + postamtName);
  400.  
  401.                             postamtIndexNamePairs.add(new Pair(String
  402.                                     .valueOf(postamtIndex), postamtName));
  403.                         }
  404.  
  405.                         return postamtIndexNamePairs;
  406.                     }
  407.                 });
  408.  
  409.         log.debug("getPostamtIndexNamePairs end");
  410.         return postamtIndexNamePairs;
  411.     }
  412.  
  413.     private List<String> getPotentialOwners(Connection connection,
  414.             String query, int ufpsIndex, int departmentControllerGroupId)
  415.             throws Exception {
  416.         log.debug("getPotentialOwners begin");
  417.         log.debug("executing: " + query);
  418.  
  419.         List<ValueWrapper> valueWrappers = new ArrayList<ValueWrapper>();
  420.  
  421.         valueWrappers.add(new ValueWrapper(ufpsIndex, Integer.class));
  422.         valueWrappers.add(new ValueWrapper(departmentControllerGroupId,
  423.                 Integer.class));
  424.  
  425.         List<String> potOwnersIds = (List<String>) DbHelper.executeQuery(
  426.                 connection, query, valueWrappers, true,
  427.                 new DbHelper.ResulSetHandler() {
  428.                     @Override
  429.                     public Object processResultSet(ResultSet result)
  430.                             throws Exception {
  431.                         List<String> potOwnersIds = new ArrayList<String>();
  432.  
  433.                         while (result.next()) {
  434.  
  435.                             int ufpsIndex = result.getInt(UFPS_INDEX);
  436.                             int userId = result.getInt(UM_USER);
  437.                             int departmentControllerGroupId = result
  438.                                     .getInt(DEPARTMENT_CONTROLLER_GROUP_ID);
  439.  
  440.                             log.debug("  user: " + ufpsIndex + " / [" + userId
  441.                                     + "] / " + departmentControllerGroupId);
  442.  
  443.                             potOwnersIds.add(String.valueOf(userId));
  444.                         }
  445.  
  446.                         return potOwnersIds;
  447.                     }
  448.                 });
  449.  
  450.         log.debug("getPotentialOwners end");
  451.         return potOwnersIds;
  452.     }
  453.  
  454.     private ISubjectInstanceBean getPrimeSubject(
  455.             IProcessInstanceBean processInstanceBean) throws Exception {
  456.         ICommonApi commonApi = ApiUtils.lookupCommonApi();
  457.         String subjectInstanceId = processInstanceBean.getSubjectInstances()[0];
  458.         ISubjectInstanceBean subjectInstanceBean = commonApi
  459.                 .getSubjectInstanceBean(subjectInstanceId);
  460.         return subjectInstanceBean;
  461.     }
  462.  
  463.     private IView createPrimeBO(ISubjectInstanceBean subjectInstanceBean)
  464.             throws Exception {
  465.         IBo20AccessApi bo20AccessApi = ApiUtils.lookupBo20AccessApi();
  466.         Set<IStorageInstanceBean> storages = bo20AccessApi.getStorages(
  467.                 subjectInstanceBean, null);
  468.         IStorageInstanceBean storage = storages.iterator().next();
  469.         IView iView = bo20AccessApi.createIViewOnStorage(subjectInstanceBean,
  470.                 storage);
  471.         return iView;
  472.     }
  473.  
  474.     private void saveNewPrimeBO(ISubjectInstanceBean subjectInstanceBean,
  475.             IView iView) throws Exception {
  476.         IBo20AccessApi bo20AccessApi = ApiUtils.lookupBo20AccessApi();
  477.         Set<IStorageInstanceBean> storages = bo20AccessApi.getStorages(
  478.                 subjectInstanceBean, null);
  479.         IStorageInstanceBean storage = storages.iterator().next();
  480.         bo20AccessApi
  481.                 .saveNewIViewInStorage(subjectInstanceBean, iView, storage);
  482.     }
  483.  
  484.     private Map<String, String> processVersions = new HashMap<String, String>();
  485.  
  486.     private IProcessInstanceBean createProcessInstance(
  487.             String processDescriptionId, String name, String userId,
  488.             int priority) throws Exception {
  489.         ICommonApi commonApi = ApiUtils.lookupCommonApi();
  490.  
  491.         String processVersionId = getLatestProcessVersionId(processDescriptionId);
  492.  
  493.         InitProcessInstanceData initProcessInstanceData = new InitProcessInstanceData(
  494.                 processVersionId,
  495.                 com.jcom1.api.constants.Constants.Process.Mode.PRODUCTIVE);
  496.  
  497.         initProcessInstanceData.setName(name);
  498.         initProcessInstanceData.setCreatorId(userId);
  499.         initProcessInstanceData.setPriority(priority);
  500.  
  501.         String processInstanceId = commonApi
  502.                 .createProcessInstance(initProcessInstanceData);
  503.  
  504.         IProcessInstanceBean processInstance = commonApi
  505.                 .getProcessInstanceBean(processInstanceId);
  506.  
  507.         return processInstance;
  508.     }
  509.  
  510.     private String getLatestProcessVersionIdFromDB(Connection connection,
  511.             String query, String processDescriptionId) throws Exception {
  512.         log.debug("getLatestProcessVersionIdFromDB begin");
  513.         log.debug("executing: " + query);
  514.         final String LATEST_VER_ID = "LATEST_VER_ID";
  515.  
  516.         List<ValueWrapper> valueWrappers = new ArrayList<ValueWrapper>();
  517.  
  518.         valueWrappers.add(new ValueWrapper(processDescriptionId, String.class));
  519.  
  520.         String lastestVerId = (String) DbHelper.executeQuery(connection, query,
  521.                 valueWrappers, true, new DbHelper.ResulSetHandler() {
  522.                     @Override
  523.                     public Object processResultSet(ResultSet rerSet)
  524.                             throws Exception {
  525.  
  526.                         if (rerSet.next())
  527.                             return rerSet.getString(LATEST_VER_ID);
  528.  
  529.                         return String.valueOf(-1);
  530.                     }
  531.                 });
  532.  
  533.         return lastestVerId;
  534.     }
  535.  
  536.     private String getLatestProcessVersionId(String processDescriptionId)
  537.             throws Exception {
  538.         log.debug("getLatestProcessVersionId begin");
  539.         String processVersion = processVersions.get(processDescriptionId);
  540.  
  541.         if (processVersion == null) {
  542.  
  543.             String latestProcVersionQuery = "SELECT ID AS LATEST_VER_ID "
  544.                     + "FROM RT_PROCDESC " + "WHERE UPLOADDATE = ( "
  545.                     + "     SELECT MAX(UPLOADDATE) " + "        FROM RT_PROCDESC "
  546.                     + "     WHERE JPASS_ID = ?)";
  547.  
  548.             try (final Connection connection = DbHelper
  549.                     .getConnection(DbHelper.PROP_DB_INT);) {
  550.  
  551.                 processVersion = getLatestProcessVersionIdFromDB(connection,
  552.                         latestProcVersionQuery, processDescriptionId);
  553.                 processVersions.put(processDescriptionId, processVersion);
  554.  
  555.             } catch (Exception e2) {
  556.                 log.debug("error while retrieving latest process version for process: "
  557.                         + processDescriptionId);
  558.             }
  559.         }
  560.         log.debug("latest ver: " + processVersion);
  561.         log.debug("getLatestProcessVersionId end");
  562.         return processVersion;
  563.     }
  564.  
  565. }
Advertisement
Add Comment
Please, Sign In to add comment