Ladies_Man

#sonic 819_fri_stable2 operationPlanActions

Aug 29th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.62 KB | None | 0 0
  1. package ru.it.metasonic.ruspost.infopoint.actions;
  2.  
  3. import org.apache.commons.logging.Log;
  4. import org.apache.commons.logging.LogFactory;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6.  
  7. import ru.it.metasonic.ruspost.infopoint.utils.AttributeHelper;
  8. import ru.it.metasonic.ruspost.infopoint.utils.BOHelper;
  9. import ru.it.metasonic.ruspost.infopoint.utils.RusPostException;
  10.  
  11. import com.jcom1.api.dto.interfaces.ISubjectInstanceBean;
  12. import com.jcom1.api.interfaces.IAuthorizationAdministrationApi;
  13. import com.jcom1.api.interfaces.IAuthorizationApi;
  14. import com.jcom1.api.interfaces.IBo20AccessApi;
  15. import com.jcom1.api.interfaces.ICommonApi;
  16.  
  17. import de.metasonic.businessobjects.exceptions.ServerRuleExecutionException;
  18. import de.metasonic.businessobjects.model.context.ContextInformation;
  19. import de.metasonic.businessobjects.model.interfaces.IView;
  20. import de.metasonic.businessobjects.model.rules.AbstractServerAction;
  21.  
  22. /**
  23.  * Just implement your action methods here.
  24.  */
  25. public class OperationPlanActions extends AbstractServerAction {
  26.  
  27.     @Autowired
  28.     ICommonApi commonApi;
  29.    
  30.     @Autowired
  31.     IBo20AccessApi accessApi;
  32.    
  33.     @Autowired
  34.     IAuthorizationApi authApi;
  35.    
  36.     @Autowired
  37.     private IAuthorizationAdministrationApi administrationApi;
  38.    
  39.     private final static Log log = LogFactory.getLog(OperationPlanActions.class);
  40.    
  41.  
  42.     /*public void myServerAction() throws ServerRuleExecutionException {
  43.         log.error("myServerAction begin");
  44.         IView iView = getBean();
  45.         try {
  46.        
  47.        
  48.            
  49.         } catch (ServerRuleExecutionException ex) {
  50.             throw ex;
  51.         } catch (RusPostException ex) {
  52.             throw ex;
  53.         } catch (Throwable th) {
  54.             throw new RusPostException(th);
  55.         }
  56.         log.error("myServerAction end");
  57.     }*/
  58.    
  59.    
  60.    
  61.    
  62.     public void setPlanNumber() throws ServerRuleExecutionException, RusPostException {
  63.         log.debug("setPlanNumber begin");
  64.         IView iView = getBean();
  65.         ContextInformation context = getContextInformation();
  66.         try {
  67.             Object commonInfo = BOHelper.getAttribute(iView, "commonInfo");
  68.             if (null == commonInfo) {
  69.                 commonInfo = BOHelper.getType(iView, "commonInfo").newInstance();
  70.                 BOHelper.setAttribute(iView, "commonInfo", commonInfo);
  71.             }
  72.  
  73.             String userId = context.getEditorId();
  74.             if (null == userId || userId.isEmpty()) {
  75.                 userId = context.getAgentId();
  76.             }
  77.             if (null == userId) {
  78.                 log.debug("There is no editor-user id. Retrieving potentialOwner as user-editor");
  79.                 ISubjectInstanceBean subjectInstanceBean = commonApi.getSubjectInstanceBean(
  80.                         String.valueOf(context.getSubjectInstanceId()));
  81.                
  82.                 if (0 != subjectInstanceBean.getPotentialOwners().length) {
  83.                     userId = subjectInstanceBean.getPotentialOwners()[0];
  84.                     log.error("userId:" + userId);
  85.                 } else {
  86.                     log.error("no potential owners were found");
  87.                 }
  88.             }
  89.            
  90.             String planNumber = new AttributeHelper(administrationApi).generateNumber(userId, this);
  91.    
  92.             if (null != planNumber) {
  93.                 BOHelper.setAttribute(commonInfo, "planNumber", planNumber);
  94.             } else {
  95.                 log.error("failed to compose planNumber");
  96.             }
  97.         } catch (ServerRuleExecutionException ex) {
  98.             throw ex;
  99.         } catch (RusPostException ex) {
  100.             throw ex;
  101.         } catch (Throwable th) {
  102.             throw new RusPostException(th);
  103.         }
  104.         log.debug("setPlanNumber end");
  105.     }
  106.    
  107.  
  108.     public void updateProcessTitle() throws ServerRuleExecutionException, RusPostException {
  109.         log.debug("updateProcessTitle begin");
  110.         IView iView = getBean();
  111.         try {
  112.             Object commonInfo = BOHelper.getAttribute(iView, "commonInfo");
  113.            
  114.             if (null == commonInfo) {
  115.                 commonInfo = BOHelper.getType(iView, "commonInfo").newInstance();
  116.                 BOHelper.setAttribute(iView, "commonInfo", commonInfo);
  117.             }
  118.            
  119.             String planNumber = (String) BOHelper.getAttribute(commonInfo, "planNumber");
  120.            
  121.             if (null != planNumber) {
  122.                 commonApi.setProcessInstanceTitle(
  123.                         (int)getContextInformation().getProcessInstanceId(), planNumber);
  124.             } else {
  125.                 log.error("failed to update process title (no planNumber)");
  126.             }
  127.            
  128.         } catch (ServerRuleExecutionException ex) {
  129.             throw ex;
  130.         } catch (RusPostException ex) {
  131.             throw ex;
  132.         } catch (Throwable th) {
  133.             throw new RusPostException(th);
  134.         }
  135.         log.debug("updateProcessTitle end");
  136.     }
  137.    
  138.    
  139.     public void updateOuterUfps() throws RusPostException, ServerRuleExecutionException  {
  140.         log.error("updateOuterUfps begin");
  141.         IView iView = getBean();
  142.         ContextInformation context = getContextInformation();
  143.         try {
  144.             IView metaData = (IView)BOHelper.getAttribute(iView, "metaData");
  145.            
  146.             if (null == metaData) {
  147.                 //explicitly get inline BO because it can be not initialized yet
  148.                 Class<?> metaDataClass = BOHelper.getType(iView, "metaData");
  149.                 log.debug("mdataType: " + metaDataClass);
  150.                 metaData = (IView) (metaDataClass.newInstance());  
  151.                 BOHelper.setAttribute(iView, "metaData", metaData);
  152.             }
  153.  
  154.             String userId = context.getEditorId();
  155.             if (null == userId || userId.isEmpty()) {
  156.                 userId = context.getAgentId();
  157.             }
  158.             if (null == userId) {
  159.                 log.debug("There is no editor-user id. Retrieving potentialOwner as user-editor");
  160.                 ISubjectInstanceBean subjectInstanceBean = commonApi.getSubjectInstanceBean(
  161.                         String.valueOf(context.getSubjectInstanceId()));
  162.                
  163.                 if (0 != subjectInstanceBean.getPotentialOwners().length) {
  164.                     userId = subjectInstanceBean.getPotentialOwners()[0];
  165.                     log.error("userId:" + userId);
  166.                 } else {
  167.                     log.error("no potential owners were found");
  168.                 }
  169.             }
  170.            
  171.             String ufpsIndex = "dummy id";
  172.             String ufpsName = "dummy name";
  173.  
  174.             AttributeHelper ah = new AttributeHelper(administrationApi);
  175.             ufpsIndex = ah.getRegionGroupId(userId);
  176.             ufpsName = ah.getRegionGroupName(userId);
  177.  
  178.             log.debug("current user's regionGroupId/Name: " + ufpsIndex + " " + ufpsName);
  179.            
  180.             BOHelper.setAttribute(metaData, "regionGroupIndex", ufpsIndex);
  181.             BOHelper.setAttribute(metaData, "regionGroupName", ufpsName);
  182.            
  183.         } catch (ServerRuleExecutionException ex) {
  184.             throw ex;
  185.         } catch (RusPostException ex) {
  186.             throw ex;
  187.         } catch (Throwable th) {
  188.             throw new RusPostException(th);
  189.         }
  190.        
  191.         log.error("updateOuterUfps end");
  192.     }
  193.    
  194.    
  195.     public void updateOuterPostamt() throws RusPostException, ServerRuleExecutionException  {
  196.         log.debug("updateOuterPostamt begin");
  197.         IView iView = getBean();
  198.         try {
  199.             Object postamt = BOHelper.getAttribute(iView, "postamt");
  200.            
  201.             if (null == postamt) {
  202.                 log.debug("bad postamt");
  203.             }
  204.            
  205.             String postamtIndex = (String)BOHelper.getAttribute(postamt, "postamtPostamtIndex");
  206.             String postamtName = (String)BOHelper.getAttribute(postamt, "postamtPostamtName");
  207.            
  208.             log.debug("index/name:" + postamtIndex + " " + postamtName);
  209.            
  210.             IView selectedPostamt = (IView)BOHelper.getAttribute(iView, "metaData");
  211.            
  212.             if (null == selectedPostamt) {
  213.                 Class<?> metaDataClass = BOHelper.getType(iView, "metaData");
  214.                 selectedPostamt = (IView) (metaDataClass.newInstance());           
  215.                 BOHelper.setAttribute(iView, "metaData", selectedPostamt);
  216.             }
  217.            
  218.             if (null != postamtIndex && null != postamtName && null!= selectedPostamt) {
  219.                 BOHelper.setAttribute(selectedPostamt, "postamtIndex", postamtIndex);
  220.                 BOHelper.setAttribute(selectedPostamt, "postamtName", postamtName);
  221.                 log.debug("meta data values set");
  222.             }
  223.            
  224.            
  225.         } catch (ServerRuleExecutionException ex) {
  226.             throw ex;
  227.         } catch (RusPostException ex) {
  228.             throw ex;
  229.         } catch (Throwable th) {
  230.             throw new RusPostException(th);
  231.         }
  232.         log.debug("updateOuterPostamt end");
  233.        
  234.     }
  235.    
  236.    
  237.     public void finilizeOperationPlan() throws RusPostException {
  238.         log.debug("begin finilizeOperationPlan ");
  239.         IView iView = getBean();
  240.         try {
  241.         ContextInformation context = getContextInformation();
  242.         Object postamt = BOHelper.getAttribute(iView, "postamt");
  243.         String postamtName =(String) BOHelper.getAttribute(postamt, "postamtPostamtName");
  244.         String postamtIndex =(String) BOHelper.getAttribute(postamt, "postamtPostamtIndex");
  245.        
  246.         //set postamt data
  247.         Object planCommonInfo = (Object) (BOHelper.getAttribute(
  248.                 iView, "commonInfo"));
  249.         BOHelper.setAttribute(planCommonInfo, "postamtIndex", postamtIndex);
  250.         BOHelper.setAttribute(planCommonInfo, "postamtName", postamtName);
  251.        
  252.         } catch (Throwable th) {
  253.             throw new RusPostException(th);
  254.         }
  255.         log.debug("end finilizeOperationPlan");
  256.        
  257.     }
  258.    
  259. }
Advertisement
Add Comment
Please, Sign In to add comment