Ladies_Man

proc2subj1Refeinment (another proc run)

Jun 8th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. import java.lang.reflect.Method;
  2. import java.util.Date;
  3. import java.util.Set;
  4. import java.util.UUID;
  5.  
  6. import org.apache.commons.logging.Log;
  7. import org.apache.commons.logging.LogFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9.  
  10. import com.jcom1.api.constants.Constants;
  11. import com.jcom1.api.dto.ProcessDescriptionBean;
  12. import com.jcom1.api.dto.init.InitProcessInstanceData;
  13. import com.jcom1.api.dto.interfaces.IProcessInstanceBean;
  14. import com.jcom1.api.dto.interfaces.IStorageInstanceBean;
  15. import com.jcom1.api.dto.interfaces.ISubjectInstanceBean;
  16. import com.jcom1.api.interfaces.IBo20AccessApi;
  17. import com.jcom1.api.interfaces.ICommonApi;
  18. import com.jcom1.runtime.refinement.AbstractRefinement;
  19. import com.jcom1.runtime.refinement.FunctionStateRequest;
  20. import com.jcom1.runtime.refinement.FunctionStateResponse;
  21. import com.jcom1.runtime.refinement.RefinementGenerator;
  22.  
  23. import de.metasonic.businessobjects.model.interfaces.IView;
  24.  
  25. @RefinementGenerator(id = "InternalSubjectDescription_XkdYwSyHEeaz1PLMMRSyYw")
  26. public class proc2Subj1Refinement extends AbstractRefinement {
  27.     /**
  28.      * @generated
  29.      */
  30.     private final static Log log = LogFactory
  31.             .getLog("com.jcom1.refinement.process2.proc2subj1");
  32.  
  33.     @Autowired
  34.     ICommonApi commonApi;
  35.     @Autowired
  36.     IBo20AccessApi accessApi;
  37.  
  38.     /**
  39.      * This method is called when the named function state is reached State:
  40.      * State3 StateType: FUNCTION
  41.      *
  42.      * Return values "FunctionTransitionDescription_jxVlUSyHEeaz1PLMMRSyYw" when
  43.      * result is "" to go to state State1
  44.      *
  45.      * @return return the id of the transition to follow e.g. // return new
  46.      *         FunctionStateResponse("transitionXXXXXXXX");
  47.      */
  48.     @RefinementGenerator(id = "FunctionStateDescription_gSVH0yyHEeaz1PLMMRSyYw")
  49.     public FunctionStateResponse functionState3(
  50.             FunctionStateRequest functionStateRequest) {
  51.         log.debug("start");
  52.  
  53.         String procDescId = "ProcessDescription_oJIX8Su2EeaVpLwktGFxww";
  54.         try {
  55.             String procVersId = null;
  56.             long maxUploadTime = 0;
  57.  
  58.             ProcessDescriptionBean[] procDescBeans = commonApi
  59.                     .getProcessVersions(procDescId);
  60.  
  61.             for (ProcessDescriptionBean procDescBean : procDescBeans) {
  62.                 long uploadTime = procDescBean.getUploadDate();
  63.                 boolean isProductive = procDescBean.isProductive();
  64.  
  65.                 if (isProductive && uploadTime > maxUploadTime) {
  66.  
  67.                     maxUploadTime = uploadTime;
  68.                     procVersId = procDescBean.getVersion();
  69.  
  70.                     log.trace("procVersId: " + procVersId);
  71.                 }
  72.             }
  73.  
  74.             String procName = "Process1 / " + new Date();
  75.             String subjInstId = functionStateRequest.getSubjectInstanceId();
  76.             ISubjectInstanceBean subjInstBean = commonApi
  77.                     .getSubjectInstanceBean(subjInstId);
  78.             String creatorId = subjInstBean.getEditor();
  79.             int priority = 3;
  80.  
  81.             log.debug("subjInstId: " + subjInstId);
  82.             log.debug("creatorId: " + creatorId);
  83.  
  84.             InitProcessInstanceData initProcInstDat = new InitProcessInstanceData();
  85.             initProcInstDat.setProcessVersionId(procVersId);
  86.             initProcInstDat.setMode(Constants.Process.Mode.PRODUCTIVE);
  87.             initProcInstDat.setName(procName);
  88.             initProcInstDat.setCreatorId(creatorId);
  89.             initProcInstDat.setPriority(priority);
  90.  
  91.             String procInstId = commonApi
  92.                     .createProcessInstance(initProcInstDat);
  93.             log.debug("procInstId:" + procInstId);
  94.  
  95.             IProcessInstanceBean procInstBean = commonApi
  96.                     .getProcessInstanceBean(procInstId);
  97.             String[] subjInstIds = procInstBean.getSubjectInstances();
  98.             log.debug("subjInstIds[0]: " + subjInstIds[0]);
  99.  
  100.             ISubjectInstanceBean subjInstBeanNew = commonApi
  101.                     .getSubjectInstanceBean(subjInstIds[0]);
  102.             Set<IStorageInstanceBean> storeInstBeans = accessApi.getStorages(
  103.                     subjInstBeanNew, null);
  104.             IStorageInstanceBean storeInstBean = storeInstBeans.iterator()
  105.                     .next();
  106.             IView iView = accessApi.createIViewOnStorage(subjInstBeanNew,
  107.                     storeInstBean);
  108.             // log.debug("iView.getId():" + iView.getId());
  109.  
  110.             String string1 = UUID.randomUUID().toString();
  111.             // BO1View bo1View = (BO1View)iView;
  112.             // bo1View.setString1(string1);
  113.             Method[] methods = iView.getClass().getMethods();
  114.             for (Method method : methods) {
  115.                 if (method.getName().equals("setString1")) {
  116.                     method.invoke(iView, string1);
  117.                     break;
  118.                 }
  119.             }
  120.             accessApi.saveNewIViewInStorage(subjInstBeanNew, iView,
  121.                     storeInstBean);
  122.  
  123.         } catch (Exception e) {
  124.             // TODO Auto-generated catch block
  125.             // e.printStackTrace();
  126.             log.error(e);
  127.         }
  128.  
  129.         return null;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment