Advertisement
Guest User

Untitled

a guest
May 14th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 120.51 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package org.igov.service.controller.interceptor;
  6.  
  7. import com.google.gson.JsonObject;
  8. import com.google.gson.JsonParser;
  9. import org.activiti.engine.*;
  10. import org.activiti.engine.history.HistoricProcessInstance;
  11. import org.activiti.engine.history.HistoricTaskInstance;
  12. import org.activiti.engine.history.HistoricVariableInstance;
  13. import org.activiti.engine.identity.Group;
  14. import org.activiti.engine.identity.User;
  15. import org.activiti.engine.repository.ProcessDefinition;
  16. import org.activiti.engine.task.Task;
  17. import org.apache.commons.mail.EmailException;
  18. import org.igov.io.GeneralConfig;
  19. import org.igov.io.Log;
  20. import org.igov.io.mail.NotificationPatterns;
  21. import org.igov.io.web.HttpRequester;
  22. import org.igov.model.action.event.HistoryEvent_Service_StatusType;
  23. import org.igov.model.core.GenericEntityDao;
  24. import org.igov.model.document.*;
  25. import org.igov.model.process.ProcessSubject;
  26. import org.igov.model.process.ProcessSubjectDao;
  27. import org.igov.model.process.processChat.ProcessChatMessage;
  28. import org.igov.model.process.processChat.ProcessChatMessageDao;
  29. import org.igov.model.subject.SubjectGroup;
  30. import org.igov.model.subject.SubjectGroupDao;
  31. import org.igov.service.business.action.event.ActionEventHistoryService;
  32. import org.igov.service.business.action.event.CloseTaskEvent;
  33. import org.igov.service.business.action.event.HistoryEventService;
  34. import org.igov.service.business.action.task.bp.handler.BpServiceHandler;
  35. import org.igov.service.business.action.task.core.ActionTaskService;
  36. import org.igov.service.business.action.task.core.UsersService;
  37. import org.igov.service.business.document.DocumentStepService;
  38. import org.igov.service.business.escalation.EscalationHistoryService;
  39. import org.igov.service.business.process.ProcessSubjectService;
  40. import org.igov.service.business.process.processLink.ProcessLinkService;
  41. import org.igov.service.business.subject.SubjectGroupService;
  42. import org.igov.service.exception.DocumentAccessException;
  43. import org.igov.service.exception.ExceptionMessage;
  44. import org.igov.service.exception.TaskAlreadyUnboundException;
  45. import org.joda.time.DateTime;
  46. import org.json.simple.JSONArray;
  47. import org.json.simple.JSONObject;
  48. import org.json.simple.parser.JSONParser;
  49. import org.json.simple.parser.ParseException;
  50. import org.slf4j.Logger;
  51. import org.slf4j.LoggerFactory;
  52. import org.springframework.beans.factory.annotation.Autowired;
  53. import org.springframework.beans.factory.annotation.Qualifier;
  54. import org.springframework.beans.factory.annotation.Value;
  55. import org.springframework.http.HttpStatus;
  56. import org.springframework.web.servlet.ModelAndView;
  57. import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
  58.  
  59. import javax.servlet.http.HttpServletRequest;
  60. import javax.servlet.http.HttpServletResponse;
  61. import javax.servlet.http.HttpSession;
  62. import java.io.BufferedReader;
  63. import java.io.IOException;
  64. import java.text.DecimalFormat;
  65. import java.text.SimpleDateFormat;
  66. import java.util.*;
  67. import java.util.regex.Matcher;
  68. import java.util.regex.Pattern;
  69. import java.util.stream.Collectors;
  70.  
  71. /**
  72.  * @author olya
  73.  */
  74. public class RequestProcessingInterceptor extends HandlerInterceptorAdapter implements ConstantsInterceptor, ExceptionMessage{
  75.  
  76.  
  77.     private static final Logger LOG = LoggerFactory.getLogger(RequestProcessingInterceptor.class);
  78.     private static final Logger LOG_BIG = LoggerFactory.getLogger("ControllerBig");
  79.  
  80.     @Autowired
  81.     protected RuntimeService runtimeService;
  82.     @Autowired
  83.     GeneralConfig generalConfig;
  84.     @Autowired
  85.     HttpRequester httpRequester;
  86.     @Autowired
  87.     NotificationPatterns oNotificationPatterns;
  88.     @Autowired
  89.     private HistoryService historyService;
  90.     @Autowired
  91.     private RepositoryService repositoryService;
  92.     @Autowired
  93.     private TaskService taskService;
  94.     @Autowired
  95.     private ActionTaskService actionTaskService;
  96.     @Autowired
  97.     private IdentityService identityService;
  98.     @Autowired
  99.     private HistoryEventService historyEventService;
  100.     @Autowired
  101.     private EscalationHistoryService escalationHistoryService;
  102.     @Autowired
  103.     private CloseTaskEvent closeTaskEvent;
  104.     @Autowired
  105.     private ActionEventHistoryService oActionEventHistoryService;
  106.     @Autowired
  107.     @Qualifier("documentStepDao")
  108.     private GenericEntityDao<Long, DocumentStep> documentStepDao;
  109.     @Autowired
  110.     private DocumentStepSubjectRightDao oDocumentStepSubjectRightDao;
  111.    
  112.     @Autowired
  113.     private DocumentStepSubjectSignTypeDao oDocumentStepSubjectSignTypeDao;
  114.  
  115.     @Autowired
  116.     private ProcessLinkService oProcessLinkService;
  117.  
  118.     @Autowired
  119.     private SubjectGroupDao oSubjectGroupDao;
  120.  
  121.     @Autowired
  122.     private UsersService usersService;
  123.    
  124.     @Autowired
  125.     private DocumentStepService oDocumentStepService;
  126.    
  127.     @Autowired
  128.     private DocumentStepDao oDocumentStepDao;
  129.    
  130.     @Autowired
  131.     private HistoryService oHistoryService;
  132.    
  133.     @Autowired
  134.     private ProcessSubjectDao oProcessSubjectDao;  
  135.    
  136.     @Autowired
  137.     private ProcessSubjectService oProcessSubjectService;
  138.    
  139.     @Autowired
  140.     private ProcessChatMessageDao oProcessChatMessageDao;
  141.    @Autowired
  142.     private SubjectGroupService oSubjectGroupService;
  143.            
  144.    
  145.     @Value("${asID_BP_SendMail}")
  146.     private String[] asID_BP_SendMail;
  147.    
  148.     private JSONParser oJSONParser = new JSONParser();
  149.  
  150.     @Override
  151.     public boolean preHandle(HttpServletRequest oRequest,
  152.             HttpServletResponse response, Object handler) throws Exception {
  153.         long startTime = System.currentTimeMillis();
  154.         LOG.info("(getMethod()={}, getRequestURL()={})", oRequest.getMethod().trim(), oRequest.getRequestURL().toString());
  155.         oRequest.setAttribute("startTime", startTime);
  156.         protocolize(oRequest, response, false);
  157.         documentHistoryPreProcessing(oRequest, response);
  158.         processSubjectStatusHistoryWritingPreHandle(oRequest);
  159.         chatDocumentSubmit(oRequest);
  160.         deleteMessagePreHandle(oRequest);
  161.         return true;
  162.     }
  163.  
  164.     @Override
  165.     public void postHandle(HttpServletRequest oRequest,
  166.             HttpServletResponse response, Object handler,
  167.             ModelAndView modelAndView) throws Exception {
  168.         oRequest.setAttribute("sLogin", "testsLogin");
  169.         //checkSessionLogin(oRequest);
  170.         processSubjectStatusHistoryWritingPostHandle(oRequest);
  171.         taskHistoryProcessing(oRequest, response);
  172.         processIpayHistory(oRequest);
  173.         //setSessionLogin(oRequest);
  174.         deleteMessagePostHandle(oRequest);
  175.     }
  176.        
  177.     @Override
  178.     public void afterCompletion(HttpServletRequest oRequest,
  179.             HttpServletResponse oResponse, Object handler, Exception ex)
  180.             throws Exception {
  181.         oRequest.setAttribute("sLogin", "testsLogin");
  182.         LOG.info("(nElapsedMS={})", System.currentTimeMillis() - (Long) oRequest.getAttribute("startTime"));
  183.         oResponse = ((MultiReaderHttpServletResponse) oRequest.getAttribute("responseMultiRead") != null
  184.                 ? (MultiReaderHttpServletResponse) oRequest.getAttribute("responseMultiRead") : oResponse);
  185.         protocolize(oRequest, oResponse, true);
  186.         documentHistoryPostProcessing(oRequest, oResponse, true);
  187.     }
  188.    
  189.     /*private void setSessionLogin(HttpServletRequest oRequest){
  190.         if(isAutentification(oRequest)){
  191.             LOG.info("isAutentification started...");
  192.            
  193.             Map<String, String> mRequestParam = new HashMap<>();
  194.             Enumeration<String> paramsName = oRequest.getParameterNames();
  195.  
  196.             while (paramsName.hasMoreElements()) {
  197.                 String sKey = (String) paramsName.nextElement();
  198.                 mRequestParam.put(sKey, oRequest.getParameter(sKey));
  199.             }
  200.            
  201.             LOG.info("mRequestParam is {}", mRequestParam);
  202.  
  203.             String sLogin = mRequestParam.get("sLogin");
  204.  
  205.             SubjectGroup oSubjectGroup = oSubjectGroupService.getValidSubjectGroupByLogin(sLogin);
  206.             if (oSubjectGroup != null) {
  207.                 sLogin = oSubjectGroup.getsID_Group_Activiti();
  208.             }
  209.  
  210.             LOG.info("set valid login: {}", sLogin);
  211.             oRequest.getSession().setAttribute("sLogin", sLogin);
  212.         }
  213.     }*/
  214.    
  215.     private void checkSessionLogin(HttpServletRequest oRequest){
  216.         HttpSession oSession = oRequest.getSession(false);
  217.        
  218.         if(oSession != null){
  219.             String sSessionsLogin = (String)oRequest.getSession(false).getAttribute("sLogin");
  220.             //LOG.info("sSessionsLogin checkSessionLogin {}", sSessionsLogin);
  221.             if(sSessionsLogin != null){
  222.                     //oRequest. ("sLogin", sSessionsLogin);
  223.             }
  224.         }
  225.     }
  226.    
  227.     private void documentHistoryPostProcessing(HttpServletRequest oRequest, HttpServletResponse oResponse, boolean bFinish) {
  228.         try {
  229.            
  230.             Map<String, String> mRequestParam = getmRequestParam(oRequest);
  231.            
  232.             String sResponseBody = !bFinish ? "" : oResponse.toString();
  233.  
  234.             if (isCloseTask(oRequest, sResponseBody) || isDocumentSubmit(oRequest) || isUpdateTask(oRequest)
  235.                     || ((mRequestParam.containsKey("sID_BP") || mRequestParam.containsKey("snID_Process_Activiti"))
  236.                     && mRequestParam.get("sID_BP") != null && mRequestParam.get("sID_BP").startsWith("_doc"))) {
  237.  
  238.                 StringBuilder osRequestBody = new StringBuilder();
  239.                 BufferedReader oReader = oRequest.getReader();
  240.                 String line;
  241.  
  242.                 if (oReader != null) {
  243.                     while ((line = oReader.readLine()) != null) {
  244.                         osRequestBody.append(line);
  245.                     }
  246.                 }
  247.  
  248.                 String sRequestBody = osRequestBody.toString();
  249.  
  250.                 String sURL = oRequest.getRequestURL().toString();
  251.  
  252.                 JSONObject omRequestBody = null;
  253.                 JSONObject omResponseBody = null;
  254.  
  255.                 try {
  256.                     if (!sRequestBody.trim().equals("")) {
  257.                         omRequestBody = (JSONObject) oJSONParser.parse(sRequestBody);
  258.                     }
  259.                 } catch (Exception ex) {
  260.                     LOG.info("Error parsing sRequestBody: {}", ex);
  261.                     //LOG.info("sRequestBody is: {}", sRequestBody);
  262.                 }
  263.  
  264.                 try {
  265.                     if (!sResponseBody.trim().equals("")) {
  266.                         omResponseBody = (JSONObject) oJSONParser.parse(sResponseBody);
  267.                     }
  268.                 } catch (Exception ex) {
  269.                     LOG.debug("Error parsing sResponseBody: {}", ex);
  270.                     //LOG.debug("sRequestBody is: {}", sResponseBody);
  271.                 }
  272.  
  273.                 if (isCloseTask(oRequest, sResponseBody)) {
  274.                     if (omRequestBody != null && omRequestBody.containsKey("taskId") && mRequestParam.isEmpty()) {
  275.                         String sTaskId = (String) omRequestBody.get("taskId");
  276.                         LOG.info("sTaskId is: {}", sTaskId);
  277.                         HistoricTaskInstance oHistoricTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(sTaskId).singleResult();
  278.                         String processInstanceId = oHistoricTaskInstance.getProcessInstanceId();
  279.  
  280.                         LOG.info("oHistoricTaskInstance.getProcessDefinitionId {}", oHistoricTaskInstance.getProcessDefinitionId());
  281.  
  282.                         if (oHistoricTaskInstance.getProcessDefinitionId().startsWith("_doc_")) {
  283.  
  284.                             LOG.info("Close document is started...");
  285.                             Map<String, String> mParam = new HashMap<>();
  286.                             String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(processInstanceId));
  287.                             mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  288.  
  289.                             List<Task> aTask = taskService.createTaskQuery().processInstanceId(processInstanceId).active().list();
  290.  
  291.                             boolean bProcessClosed = aTask == null || aTask.size() == 0;
  292.                             String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  293.  
  294.                             if (aTask.isEmpty()) {
  295.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 18L);
  296.                             }
  297.                         }
  298.                     }
  299.                 }
  300.  
  301.                 if (isDocumentSubmit(oRequest)) {
  302.                     if (omRequestBody != null && omRequestBody.containsKey("nID_Process")) {
  303.                         String snID_Process =  String.valueOf(omRequestBody.get("nID_Process"));
  304.                         HistoricProcessInstance oProcess = historyService.createHistoricProcessInstanceQuery()
  305.                                 .processInstanceId(snID_Process)
  306.                                 .singleResult();
  307.                         if (oProcess != null && oProcess.getEndTime() != null) {
  308.                             LOG.info("after completion syncProcessLinks below, closed process={}", snID_Process);
  309.                             oProcessLinkService.syncProcessLinks(snID_Process, null, false, null);
  310.                         }
  311.                     }
  312.                 }
  313.  
  314.                 if (((mRequestParam.containsKey("sID_BP") || mRequestParam.containsKey("snID_Process_Activiti"))
  315.                         && mRequestParam.get("sID_BP") != null && mRequestParam.get("sID_BP").startsWith("_doc"))) {
  316.                     LOG.info("--------------ALL REQUEST DOCUMENT PARAMS (POSTPROCESSING)--------------");
  317.                     sURL = oRequest.getRequestURL().toString();
  318.                     /*LOG.info("protocolize sURL is: " + sURL);
  319.                     LOG.info("-----------------------------------------------");
  320.                     LOG.info("sRequestBody: {}", sRequestBody);
  321.                     LOG.info("-----------------------------------------------");
  322.                     LOG.info("sResponseBody: {}", sResponseBody);
  323.                     LOG.info("-----------------------------------------------");
  324.                     LOG.info("mRequestParam {}", mRequestParam);
  325.                     LOG.info("-----------------------------------------------");*/
  326.  
  327.                     String sID_Process = null;
  328.                     //String sID_Order = null;
  329.  
  330.                     if (omResponseBody != null) {
  331.                         sID_Process = (String) omResponseBody.get("snID_Process");
  332.                         if (sID_Process != null) {
  333.                             String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(sID_Process));
  334.                             HistoricProcessInstance oHistoricProcessInstance
  335.                                     = historyService.createHistoricProcessInstanceQuery().processInstanceId(sID_Process).singleResult();
  336.                             ProcessDefinition oProcessDefinition = repositoryService.createProcessDefinitionQuery()
  337.                                     .processDefinitionId(oHistoricProcessInstance.getProcessDefinitionId()).singleResult();
  338.                             String sProcessName = oProcessDefinition.getName() != null ? oProcessDefinition.getName() : "";
  339.  
  340.                             List<Task> aTask = taskService.createTaskQuery().processInstanceId(sID_Process).active().list();
  341.                             boolean bProcessClosed = aTask == null || aTask.size() == 0;
  342.                             String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  343.  
  344.                             Map<String, String> mParam = new HashMap<>();
  345.  
  346.                             LOG.info("document nID_StatusType in interceptor {}", HistoryEvent_Service_StatusType.CREATED.getnID());
  347.                             mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  348.                             LOG.info("document sID_Order in interceptor {}", sID_Order);
  349.                             LOG.info("document sUserTaskName in interceptor {}", sUserTaskName);
  350.  
  351.                             if (!(oResponse.getStatus() < 200 || oResponse.getStatus() >= 300
  352.                                     || (sResponseBody != null && sResponseBody.contains(SYSTEM_ERR)))) {
  353.                                 if (isSetDocumentService(oRequest, sResponseBody, bFinish)) {
  354.                                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 11L);
  355.                                 }
  356.                             }
  357.                         }
  358.                     }
  359.                 }
  360.             }
  361.  
  362.         } catch (Exception ex) {
  363.             LOG.info("Error during document processing in interceptor: {} ", ex);
  364.         }
  365.     }
  366.  
  367.     private void documentHistoryPreProcessing(HttpServletRequest oRequest, HttpServletResponse oResponse) {
  368.         try {
  369.  
  370.             Map<String, String> mRequestParam = getmRequestParam(oRequest);
  371.                    
  372.             if(isSetUrgent(oRequest)){
  373.                 //LOG.info("mRequestParam in isSetUrgent {}", mRequestParam);
  374.                 Map<String, String> mParam = new HashMap<>();
  375.                 String sID_Order = generalConfig.getOrderId_ByProcess(generalConfig.getSelfServerId(), Long.parseLong(mRequestParam.get("snID_Process_Activiti")));
  376.                 mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  377.                
  378.                 String sInitials = "";
  379.                 if (mRequestParam.get("sKey_Group_Editor") != null) {
  380.                     String sLogin = (String) mRequestParam.get("sKey_Group_Editor");
  381.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  382.                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  383.                     sInitials = usersService.getUserInitials(sFIO);
  384.                     mParam.put("sLogin", sInitials);
  385.                 }
  386.                
  387.                 String sReferentInitials = "";
  388.                 String sLoginReferent = (String) mRequestParam.get("sLoginReferent");
  389.                 if (sLoginReferent != null && !sLoginReferent.isEmpty()) {                    
  390.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginReferent);
  391.                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  392.                     sReferentInitials = usersService.getUserInitials(sFIO);
  393.                     mParam.put("sBody", sReferentInitials);
  394.                 }
  395.                 else {
  396.                     mParam.put("sBody", sInitials);
  397.                 }
  398.                
  399.                 //mParam.put("sLogin", mRequestParam.get("sKey_Group_Editor"));
  400.                
  401.                 if (mRequestParam.get("bUrgent") == null){
  402.                     oActionEventHistoryService.addHistoryEvent(sID_Order, "", mParam, 50L);
  403.                 }
  404.                 else if(Boolean.parseBoolean(mRequestParam.get("bUrgent"))){
  405.                     oActionEventHistoryService.addHistoryEvent(sID_Order, "", mParam, 48L);
  406.                 }else if(!Boolean.parseBoolean(mRequestParam.get("bUrgent"))){
  407.                     oActionEventHistoryService.addHistoryEvent(sID_Order, "", mParam, 49L);
  408.                 }
  409.             }
  410.            
  411.             //LOG.info("mRequestParam pre {}", mRequestParam);
  412.            
  413.             if (isUpdateTask(oRequest) || isDocumentSubmit(oRequest)) {
  414.  
  415.                 StringBuilder osRequestBody = new StringBuilder();
  416.                 BufferedReader oReader = oRequest.getReader();
  417.                 String line;
  418.  
  419.                 if (oReader != null) {
  420.                     while ((line = oReader.readLine()) != null) {
  421.                         osRequestBody.append(line);
  422.                     }
  423.                 }
  424.  
  425.                 String sRequestBody = osRequestBody.toString();
  426.                 //String sResponseBody = !bFinish ? "" : oResponse.toString();
  427.  
  428.                 String sURL = oRequest.getRequestURL().toString();
  429.  
  430.                 JSONObject omRequestBody = null;
  431.                 //JSONObject omResponseBody = null;
  432.  
  433.                 try {
  434.                     if (!sRequestBody.trim().equals("")) {
  435.                         omRequestBody = (JSONObject) oJSONParser.parse(sRequestBody);
  436.                     }
  437.                 } catch (Exception ex) {
  438.                     LOG.error("Error parsing sRequestBody: {}", ex);
  439.                 }
  440.  
  441.                 if (isUpdateTask(oRequest)) {
  442.                    /* LOG.info("--------------ALL PARAMS IN SUBMIT DOCUMENT (PREPROCESSING)--------------");
  443.                     LOG.info("protocolize sURL is: " + sURL);*/
  444.                 }
  445.  
  446.                 if (isDocumentSubmit(oRequest)) {
  447.                     /*LOG.info("--------------ALL PARAMS IN SUBMIT(REGION - PreProcessing)--------------");
  448.                     LOG.info("protocolize sURL is: " + sURL);
  449.                     LOG.info("-----------------------------------------------");
  450.                     LOG.info("sRequestBody: {}", sRequestBody);
  451.                     LOG.info("-----------------------------------------------");
  452.                     LOG.info("-----------------------------------------------");
  453.                     LOG.info("mRequestParam {}", mRequestParam);
  454.                     LOG.info("-----------------------------------------------");
  455.                     LOG.info("oRequest.getSession(false): " + oRequest.getSession(false) + " sURL: " + sURL);*/
  456.                     /*if(oRequest.getSession(false) != null && oRequest.getSession(false).getAttribute("sLoginReferent") != null){
  457.                         LOG.info("oRequest.getSession(false).getAttribute(\"sLoginReferent\"): " + oRequest.getSession(false).getAttribute("sLoginReferent") + " sURL: " + sURL);
  458.                         mRequestParam.put("sLoginReferent", (String)oRequest.getSession(false).getAttribute("sLoginReferent"));
  459.                     }*/
  460.                     String sLoginAssigne = mRequestParam.get("sLoginAssigne");
  461.                     String sKey_Step = omRequestBody != null ? (String) omRequestBody.get("sKey_Step") : null;
  462.                     String taskId = omRequestBody != null ? String.valueOf(omRequestBody.get("taskId")) : null;
  463.                     //блок валидации вынесен перед асайном таски
  464.                     if (sKey_Step != null && taskId != null) {
  465.                         String processInstanceId = historyService.createHistoricTaskInstanceQuery()
  466.                                 .taskId(taskId)
  467.                                 .singleResult()
  468.                                 .getProcessInstanceId();
  469.  
  470.                         String sLogin = mRequestParam.get("sLogin");
  471.                         //валидация таски
  472.                         actionTaskService.validateTask(processInstanceId, taskId, sLogin);
  473.                         //валидация степа
  474.                         actionTaskService.validateDocumentStep(processInstanceId, sKey_Step);
  475.                         //если sAssignLogin == sLogin значит автор взял документ на редактирование
  476.                         if (!sLogin.equals(sLoginAssigne)) {
  477.                             //валидация права на подпись
  478.                             oDocumentStepService.validateSubmitRights(processInstanceId, sKey_Step, sLogin);
  479.                         }
  480.                     }
  481.                     try {
  482.                         if(sLoginAssigne != null && taskId != null){
  483.                             LOG.info("sLoginAssigne is {} and taskId is {} ", sLoginAssigne, taskId);
  484.                             taskService.setAssignee(taskId, sLoginAssigne);
  485.                         }
  486.                         processDocumentSubmit(mRequestParam, omRequestBody);
  487.                     }  catch (Exception oException){
  488.                         LOG.info("Exception during assigne {}", oException.getMessage());
  489.                         if (taskId != null){
  490.                             actionTaskService.unclaimUserTask(taskId);
  491.                           }
  492.                         throw oException;
  493.                     }
  494.                 }
  495.             }
  496.         } catch (DocumentAccessException oDocumentAccessException) {
  497.             LOG.error("Validation fail {} ", oDocumentAccessException.getMessage());
  498.             throw oDocumentAccessException;
  499.         } catch (Exception ex) {
  500.             LOG.error("Error during document processing in interceptor: {} ", ex);
  501.         }
  502.     }
  503.  
  504.     private void processDocumentSubmit(Map<String, String> mRequestParam, JSONObject omRequestBody)
  505.             throws Exception {
  506.         LOG.info("processDocumentSubmit start");
  507.         if (omRequestBody != null && omRequestBody.containsKey("taskId")) {
  508.             String sTaskId = String.valueOf(omRequestBody.get("taskId"));
  509.             //LOG.info("sTaskId is: {}", sTaskId);
  510.             HistoricTaskInstance oHistoricTaskInstance = historyService.createHistoricTaskInstanceQuery()
  511.                     .taskId(sTaskId)
  512.                     .singleResult();          
  513.             String processInstanceId = oHistoricTaskInstance.getProcessInstanceId();
  514.             String sAssignLogin = oHistoricTaskInstance.getAssignee();
  515.             LOG.info("sAssignLogin in interceptor is {}", sAssignLogin);
  516.             /*LOG.info("oHistoricTaskInstance.getProcessDefinitionId {}", oHistoricTaskInstance.getProcessDefinitionId());
  517.             LOG.info("oHistoricTaskInstance.processInstanceId {}", processInstanceId);*/
  518.  
  519.             Boolean bAuthorEdit = null;
  520.            
  521.             if (oHistoricTaskInstance.getProcessDefinitionId().startsWith("_doc_")) {
  522.                 //LOG.info("We catch document submit...");
  523.                 JSONArray properties = (JSONArray) omRequestBody.get("properties");
  524.                 //LOG.info("properties size {}", properties.size());
  525.                 Iterator<JSONObject> iterator = properties.iterator();
  526.                 String sKey_Step_Document = null;
  527.                 while (iterator.hasNext()) {
  528.                     JSONObject jsonObject = iterator.next();
  529.  
  530.                     String sId = null;
  531.                     String sValue = null;
  532.  
  533.                     try {
  534.                         sId = (String) jsonObject.get("id");
  535.                         if (jsonObject.get("value") instanceof Long) {
  536.                             sValue = ((Long) jsonObject.get("value")).toString();
  537.                         } else if (jsonObject.get("value") instanceof Double) {
  538.                             sValue = ((Double) jsonObject.get("value")).toString();
  539.                         } else {
  540.                             sValue = (String) jsonObject.get("value");
  541.                         }
  542.                     } catch (Exception ex) {
  543.                         LOG.info("sId field exception {}", sId, ex.getMessage());
  544.                         continue;
  545.                     }
  546.                     //LOG.info("sId field {}", sId);
  547.  
  548.                     if (sId.equals("sKey_Step_Document")) {
  549.                         sKey_Step_Document = sValue;
  550.                         //break;
  551.                     }
  552.                    
  553.                     if (sId.equals("bAuthorEdit")) {
  554.                         bAuthorEdit = Boolean.parseBoolean(sValue);
  555.                     }
  556.  
  557.                     if (sId.startsWith("sID_Order_Relation")) {
  558.  
  559.                         //LOG.info("sID_Order_Relation in {}", sId);
  560.                         String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(processInstanceId));
  561.                         String nID_Task_Linked = actionTaskService.getTaskIDbyProcess(null, sValue, Boolean.FALSE).toString();
  562.  
  563.                         /*LOG.info("sID_Order {}", sID_Order);
  564.                         LOG.info("nID_Task_Linked {}", nID_Task_Linked);*/
  565.  
  566.                         List<Task> aTask = taskService.createTaskQuery().processInstanceId(processInstanceId).active().list();
  567.                         boolean bProcessClosed = aTask == null || aTask.isEmpty();
  568.                         String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  569.  
  570.                         Map<String, String> mParam = new HashMap<>();
  571.                         mParam.put("new_BP_ID",
  572.                                 (taskService.createTaskQuery().taskId(nID_Task_Linked).list().get(0).getProcessDefinitionId()).split(":")[0]);
  573.                         mParam.put("sID_Order_Link", sValue);
  574.                         mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  575.                         LOG.info("mParam 1-st {}", mParam);
  576.                         oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 29L);
  577.  
  578.                         mParam.replace("new_BP_ID", aTask.get(0).getProcessDefinitionId().split(":")[0]);
  579.                         mParam.replace("sID_Order_Link", sID_Order);
  580.  
  581.                         LOG.info("mParam 2-nd {}", mParam);
  582.                         oActionEventHistoryService.addHistoryEvent(sValue, sUserTaskName, mParam, 30L);
  583.                     }
  584.                 }
  585.                 //LOG.info("sKey_Step_Document is {}", sKey_Step_Document);
  586.  
  587.                 if (sKey_Step_Document != null) {
  588.                     String sLogin = mRequestParam.get("sLogin");
  589.                    
  590.                     List<DocumentStep> aDocumentStep = documentStepDao.findAllBy("snID_Process_Activiti", processInstanceId);
  591.                     //LOG.info("aDocumentStep in interceptor is {}", aDocumentStep);
  592.  
  593.                     DocumentStep oCurrDocumentStep = null;
  594.                     DocumentStep oCommonDocumentStep = null;
  595.                    
  596.                     for (DocumentStep oDocumentStep : aDocumentStep) {
  597.                         if (oDocumentStep.getsKey_Step().equals(sKey_Step_Document)) {
  598.                             oCurrDocumentStep = oDocumentStep;
  599.                         }
  600.                         if (oDocumentStep.getsKey_Step().equals("_")) {
  601.                             oCommonDocumentStep = oDocumentStep;
  602.                             //break;
  603.                         }
  604.                     }
  605.                     LOG.info("oCurrDocumentStep in interceptor is {}", oCurrDocumentStep);
  606.  
  607.                     List<Group> aUserGroup = identityService.createGroupQuery().groupMember(sAssignLogin).list();
  608.                     LOG.info("aUserGroup is {}", aUserGroup);
  609.                     //runtimeService.setVariable(executionId, "sLogin_LastSubmited", sAssignLogin);
  610.                     if (oCurrDocumentStep != null && oCommonDocumentStep != null) {
  611.                         List<DocumentStepSubjectRight> aDocumentStepSubjectRight = oCurrDocumentStep.aDocumentStepSubjectRight();
  612.                         //aDocumentStepSubjectRight.addAll(oCommonDocumentStep.aDocumentStepSubjectRight());
  613.                         taskService.setVariable(sTaskId, "sLogin_LastSubmited", sLogin);
  614.                        
  615.                         for (DocumentStepSubjectRight oDocumentStepSubjectRight : aDocumentStepSubjectRight) {
  616.                             for (Group oGroup : aUserGroup) {
  617.                                 /*LOG.info("oGroup name: {}", oGroup.getName());
  618.                                 LOG.info("oGroup id: {}", oGroup.getId());*/
  619.                                 //oGroup.getId().equals(sLogin) - in case of refernt user on the step
  620.                                 if (oGroup.getId().equals(sLogin) && oGroup.getId().equals(oDocumentStepSubjectRight.getsKey_GroupPostfix())) {
  621.                                     List<User> aUser = identityService.createUserQuery().memberOfGroup(oDocumentStepSubjectRight.getsKey_GroupPostfix()).list();
  622.                                     //LOG.info("oDocumentStepSubjectRight.getsKey_GroupPostfix {}", oDocumentStepSubjectRight.getsKey_GroupPostfix());
  623.                                     for (User oUser : aUser) {
  624.                                             //LOG.info("oUser id is {}", oUser.getId());
  625.                                         if (oUser.getId().equals(sAssignLogin)) {
  626.                                            
  627.                                             String sLoginReferent;
  628.                                             if(mRequestParam.get("sLoginReferent") != null){
  629.                                                 sLoginReferent = mRequestParam.get("sLoginReferent");
  630.                                             } else{
  631.                                                 sLoginReferent = sAssignLogin;
  632.                                             }      
  633.                                             LOG.info("bAuthorEdit before setting date {}", bAuthorEdit);
  634.                                            
  635.                                             if(bAuthorEdit == null || bAuthorEdit == false){
  636.                                                 LOG.info("We set date for login: {}", sAssignLogin);
  637.                                                 oDocumentStepSubjectRight.setsDate(new DateTime());
  638.                                                 oDocumentStepSubjectRight.setsLogin(sLoginReferent);  
  639.                                                 runtimeService.setVariable(processInstanceId, "bUrgent", null);
  640.                                                 runtimeService.setVariable(processInstanceId, "sLogin_LastSubmited", sLogin);
  641.  
  642.                                                 String sID_SignType = mRequestParam.get("sName_DocumentStepSubjectSignType");
  643.                                                 //LOG.info("sID: {}", sID_SignType);
  644.                                                 if(sID_SignType == null){
  645.                                                     sID_SignType = "sign";
  646.                                                 }          
  647.  
  648.                                                 DocumentStepSubjectSignType oDocumentStepSubjectSignType = oDocumentStepSubjectSignTypeDao.findByExpected("sID", sID_SignType);                                                                                          
  649.                                                 oDocumentStepSubjectRight.setoDocumentStepSubjectSignType(oDocumentStepSubjectSignType);
  650.                                             }
  651.                                            
  652.                                             oDocumentStepSubjectRight.setbUrgent(null);
  653.                                             oDocumentStepSubjectRightDao.saveOrUpdate(oDocumentStepSubjectRight);
  654.                                            
  655.                                             break;
  656.                                         }
  657.                                     }
  658.                                     break;
  659.                                 }
  660.                             }
  661.                         }
  662.                         //LOG.info("oCurrDocumentStep.getRights() in interceptor is {}", oCurrDocumentStep.aDocumentStepSubjectRight());
  663.                         Map<String, String> mParam = new HashMap<>();
  664.                         //String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(processInstanceId)); нигде не используется закомментировал
  665.                         SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sAssignLogin);
  666.                         String sName = oSubjectGroup.getoSubject().getsLabel();
  667.                         mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  668.                         mParam.put("sLoginNew", sAssignLogin);
  669.                         mParam.put("sName", sName);
  670.                     }
  671.                     //oProcessLinkService.syncProcessLinks(processInstanceId, sLogin, false, null);
  672.                 }
  673.             }
  674.         }
  675.     }
  676.  
  677.     private void chatDocumentSubmit(HttpServletRequest oRequest) throws Exception {
  678.         Map<String, String> mRequestParam = getmRequestParam(oRequest);
  679.  
  680.         String sKeyGroup = mRequestParam.get("sKeyGroup");
  681.         String sLogin = mRequestParam.get("sLogin");
  682.  
  683.         if ((sKeyGroup != null && !sKeyGroup.isEmpty()) && (isSetMessage(oRequest) || isDeleteMessage(oRequest))) {
  684.             //это замечание
  685.  
  686.             String snID_Process_Activiti = mRequestParam.get("nID_Process_Activiti");
  687.             if (snID_Process_Activiti == null) {
  688.                 String snID_ProcessChatMessage = mRequestParam.get("nID_ProcessChatMessage");
  689.                 ProcessChatMessage oProcessChatMessage = oProcessChatMessageDao.findByIdExpected(Long.valueOf(snID_ProcessChatMessage));
  690.                 snID_Process_Activiti = String.valueOf(oProcessChatMessage.getoProcessChat().getnID_Process_Activiti());
  691.             }
  692.  
  693.             HistoricVariableInstance oHistoricVariable = oHistoryService.createHistoricVariableInstanceQuery()
  694.                     .processInstanceId(snID_Process_Activiti)
  695.                     .variableName("sKey_Step_Document")
  696.                     .singleResult();
  697.             String sKey_Step_Document = String.valueOf(oHistoricVariable.getValue());
  698.  
  699.  
  700.             String sName_DocumentStepSubjectSignType = mRequestParam.get("sName_DocumentStepSubjectSignType");
  701.             //DocumentStep oDocumentStep = oDocumentStepService.getDocumentStep(snID_Process_Activiti, sKey_Step_Document);
  702.  
  703.  
  704.             List<DocumentStep> aDocumentStep = oDocumentStepDao.getStepForProcess(snID_Process_Activiti);
  705.             for (DocumentStep documentStep : aDocumentStep) {
  706.                 LOG.debug("chat documentStep is {}", documentStep.toString());
  707.                 List<DocumentStepSubjectRight> aDocumentStepSubjectRight = documentStep.aDocumentStepSubjectRight();
  708.                 //LOG.info("aDocumentStepSubjectRight is {}", aDocumentStepSubjectRight);
  709.  
  710.                 if ("remark".equalsIgnoreCase(mRequestParam.get("sName_DocumentStepSubjectSignType"))) {
  711.                     //ветка, когда оставляем замечание
  712.                     for (int i = 0; i < aDocumentStepSubjectRight.size(); i++) {
  713.                         DocumentStepSubjectRight oDocumentStepSubjectRight = aDocumentStepSubjectRight.get(i);
  714.                         if (oDocumentStepSubjectRight.getsKey_GroupPostfix().equals(sKeyGroup)
  715.                                 && !documentStep.getsKey_Step().equalsIgnoreCase("_") && oDocumentStepSubjectRight.getsDate() == null) {
  716.                             oDocumentStepSubjectRight.setsDate(new DateTime());
  717.                             oDocumentStepSubjectRight.setsLogin(sKeyGroup);
  718.                             oDocumentStepSubjectRight.setsKey_GroupAuthor(mRequestParam.get("sLoginReferent"));
  719.                             DocumentStepSubjectSignType oDocumentStepSubjectSignType
  720.                                     = oDocumentStepSubjectSignTypeDao.findByExpected("sID", sName_DocumentStepSubjectSignType);
  721.                             oDocumentStepSubjectRight.setoDocumentStepSubjectSignType(oDocumentStepSubjectSignType);
  722.  
  723.                             oDocumentStepSubjectRightDao.saveOrUpdate(oDocumentStepSubjectRight);
  724.                             //break;
  725.                         }
  726.                     }
  727.                 } else if ((isSetMessage(oRequest) && !sKeyGroup.equalsIgnoreCase(sLogin)) //автор отвечает на замечание
  728.                         || (isDeleteMessage(oRequest) && sKeyGroup.equalsIgnoreCase(sLogin)) // я удаляю свое замечание
  729.                         ) {
  730.                     for (int i = 0; i < aDocumentStepSubjectRight.size(); i++) {
  731.                         LOG.debug("chat we are almost in");
  732.                         DocumentStepSubjectRight oDocumentStepSubjectRight = aDocumentStepSubjectRight.get(i);
  733.                         if (oDocumentStepSubjectRight.getsKey_GroupPostfix().equals(sKeyGroup)) {
  734.                             if (oDocumentStepSubjectRight.getsDate() != null &&
  735.                                     oDocumentStepSubjectRight.getoDocumentStepSubjectSignType().getsID().equals("remark")
  736.                                     && !documentStep.getsKey_Step().equalsIgnoreCase("_")) {
  737.                                 LOG.debug("chat we are finally in");
  738.                                 oDocumentStepService.cancelDocumentSubmit(snID_Process_Activiti, documentStep.getsKey_Step(), sKeyGroup);
  739.                             }
  740.                             //break;
  741.                         }
  742.                     }
  743.                 }
  744.             }
  745.  
  746.  
  747.  
  748.             /*String sID_Order = generalConfig.getOrderId_ByProcess(Long.valueOf(snID_Process_Activiti));
  749.             Long nTaskID = actionTaskService.getTaskIDbyProcess(Long.valueOf(snID_Process_Activiti), sID_Order, Boolean.FALSE);
  750.             boolean bSubmit = Boolean.parseBoolean(mRequestParam.get("bSubmit"));
  751.             if (bSubmit == true) {
  752.                 String sNeedAssign = mRequestParam.get("sNeedAssign");
  753.                 if (sNeedAssign != null) {
  754.                     taskService.setAssignee(String.valueOf(nTaskID), sNeedAssign);
  755.                 }
  756.                 taskService.complete(String.valueOf(nTaskID));
  757.             }*/
  758.             //oProcessLinkService.syncProcessLinks(snID_Process_Activiti, sKeyGroup);
  759.         }
  760.     }
  761.  
  762.     private Map<String, String> getmRequestParam(HttpServletRequest oRequest) throws Exception {
  763.         checksLoginRefernt(oRequest);
  764.         Map<String, String> mRequestParam = new HashMap<>();
  765.         Enumeration<String> paramsName = oRequest.getParameterNames();
  766.         while (paramsName.hasMoreElements()) {
  767.             String sKey = (String) paramsName.nextElement();
  768.             mRequestParam.put(sKey, oRequest.getParameter(sKey));
  769.         }
  770.         return mRequestParam;
  771.     }
  772.  
  773.     private Map<String, Object> getmRequestAttribute(HttpServletRequest oRequest) throws Exception {
  774.         checksLoginRefernt(oRequest);
  775.         Map<String, Object> mRequestAttribute = new HashMap<>();
  776.         Enumeration<String> aAttributeName = oRequest.getAttributeNames();
  777.  
  778.         while (aAttributeName.hasMoreElements()) {
  779.             String sKey = (String) aAttributeName.nextElement();
  780.             mRequestAttribute.put(sKey, oRequest.getAttribute(sKey));
  781.         }
  782.         return mRequestAttribute;
  783.     }
  784.  
  785.     private void protocolize(HttpServletRequest oRequest, HttpServletResponse oResponse, boolean bFinish)
  786.             throws IOException, TaskAlreadyUnboundException, Exception {
  787.        
  788.         LOG.info("Method 'protocolize' started");
  789.         int nLen = generalConfig.isSelfTest() ? 300 : 200;
  790.  
  791.         Map<String, String> mRequestParam = getmRequestParam(oRequest);
  792.                
  793.         StringBuilder osRequestBody = new StringBuilder();
  794.         BufferedReader oReader = oRequest.getReader();
  795.         String line;
  796.         if (oReader != null) {
  797.             while ((line = oReader.readLine()) != null) {
  798.                 osRequestBody.append(line);
  799.             }
  800.         }
  801.         String sURL = oRequest.getRequestURL().toString();
  802.         String snTaskId = null;
  803.         //getting task id from URL, if URL matches runtime/tasks/{taskId} (#1234)
  804.         String sRequestBody = osRequestBody.toString();
  805.         if (TAG_PATTERN_PREFIX.matcher(oRequest.getRequestURL()).find()) {
  806.             snTaskId = sURL.substring(sURL.lastIndexOf("/") + 1);
  807.             //LOG.info("snTaskId: " + snTaskId);
  808.             //LOG.info("Request.getMethod().trim(): " + oRequest.getMethod().trim());
  809.             if (PUT.equalsIgnoreCase(oRequest.getMethod().trim()) && SREQUESTBODY_PATTERN.matcher(sRequestBody).find()) {
  810.                 //LOG.info("URL is like runtime/tasks/{taskId}, getting task id from url, task id is " + snTaskId);
  811.                 Task task = taskService.createTaskQuery().taskId(snTaskId).singleResult();
  812.                 if (task != null && task.getAssignee() != null) {
  813.                     //LOG.info("task.getAssignee(): " + task.getAssignee());
  814.                     throw new TaskAlreadyUnboundException(HttpStatus.FORBIDDEN + " Вибачте, звернення вже взято в роботу");
  815.                 }
  816.             }
  817.         }
  818.         if (snTaskId != null && mRequestParam.get("taskId") == null) {
  819.             mRequestParam.put("taskId", snTaskId);
  820.         }
  821.  
  822.         String sResponseBody = !bFinish ? null : oResponse.toString();
  823.         if (bFinish) {
  824.             //LOG.info("(sResponseBody={})", sCut(nLen, sResponseBody));
  825.             if (sURL.endsWith(SERVICE_ACTION_ITEM_GET_SERVICE)
  826.                     || sURL.endsWith(SERVICE_ACTION_ITEM_GET_SERVICES_TREE)
  827.                     || (sURL.endsWith(SERVICE_FORM_FORM_DATA)
  828.                     && "GET".equalsIgnoreCase(oRequest.getMethod().trim()))
  829.                     || sURL.endsWith(SERVICE_REPOSITORY_PROCESS_DEFINITIONS)
  830.                     || sURL.endsWith(SERVICE_ACTION_TASK_GET_START_FORM_DATA)
  831.                     || sURL.endsWith(SERVICE_ACTION_TASK_GET_ORDER_MESSAGES_LOCAL)
  832.                     || sURL.endsWith(SERVICE_ACTION_FLOW_GET_FLOW_SLOTS_SERVICE_DATA)
  833.                     || sURL.contains(SERVICE_RUNTIME_TASKS)
  834.                     || sURL.endsWith(SERVICE_HISTORY_HISTORIC_TASK_INSTANCES)
  835.                     || sURL.endsWith(SERVICE_ACTION_TASK_GET_LOGIN_B_PS)
  836.                     || sURL.endsWith(SERVICE_SUBJECT_MESSAGE_GET_MESSAGES)
  837.                     || sURL.endsWith(SERVICE_SUBJECT_MESSAGE_GET_SERVICE_MESSAGES)
  838.                     || sURL.endsWith(SERVICE_OBJECT_PLACE_GET_PLACES_TREE)
  839.                     || sURL.endsWith(SERVICE_ACTION_EVENT_GET_LAST_TASK_HISTORY)
  840.                     || sURL.endsWith(SERVICE_ACTION_EVENT_GET_HISTORY_EVENTS_SERVICE)
  841.                     || sURL.endsWith(SERVICE_ACTION_EVENT_GET_HISTORY_EVENTS)
  842.                     || sURL.endsWith(SERVICE_DOCUMENT_GET_DOCUMENT_CONTENT)
  843.                     || sURL.endsWith(SERVICE_DOCUMENT_GET_DOCUMENT_FILE)
  844.                     || sURL.endsWith(SERVICE_DOCUMENT_GET_DOCUMENTS)
  845.                     || sURL.endsWith(SERVICE_DOCUMENT_SET_DOCUMENT_FILE)
  846.                     || sURL.contains(SERVICE_OBJECT_FILE)
  847.                     || sURL.contains(SERVICE_DOCUMENT_GET_DOCUMENT_ABSTRACT)) {
  848.             } else {
  849.                 //LOG.debug("(sResponseBody={})", sResponseBody);
  850.             }
  851.         }
  852.         String sType = "";
  853.  
  854.         try {
  855.             if (!bFinish || !(oResponse.getStatus() >= HttpStatus.OK.value()
  856.                     && oResponse.getStatus() < HttpStatus.BAD_REQUEST.value())) {
  857.                 LOG.info("returning from protocolize block: bSaveHistory:{} oResponse.getStatus():{}", bFinish, oResponse.getStatus());
  858.             }
  859.  
  860.             //LOG.info("isSaveTask(oRequest, sResponseBody): " + isSaveTask(oRequest, sResponseBody));
  861.             //LOG.info("oRequest.getRequestURL: " + oRequest.getRequestURL().toString());
  862.             //LOG.info("sResponseBody before SaveTask: " + sResponseBody);
  863.             if (isSaveTask(oRequest, sResponseBody, bFinish)) {
  864.                 sType = "Save";
  865.                 LOG.info("saveNewTaskInfo block started");
  866.                 //LOG.info("oRequest body {}", sRequestBody);
  867.                 //LOG.info("sResponseBody {}", sResponseBody);
  868.                 if (oResponse.getStatus() < 200 || oResponse.getStatus() >= 300
  869.                         || (sResponseBody != null && sResponseBody.contains(SYSTEM_ERR))) { //SYSTEM_ERR
  870.                     try {
  871.                         new Log(this.getClass(), LOG)//this.getClass()
  872.                                 ._Case("Activiti_FailStartTask")
  873.                                 ._Status(Log.LogStatus.ERROR)
  874.                                 ._Head("Error hapened while start process!")
  875.                                 ._Body(oResponse.toString())
  876.                                 //._Param("sRequestBody", sRequestBody)
  877.                                 //._Param("sResponseBody", sResponseBody)
  878.                                 ._Param("mRequestParam", mRequestParam)
  879.                                 .save();
  880.                     } catch (Exception ex) {
  881.                         LOG.error("Can't save error to MSG", ex.getMessage());
  882.                     }
  883.                     return;
  884.                 } else {
  885.                     //LOG.info("sRequestBody {}", sRequestBody);
  886.                     //LOG.info("sResponseBody {}", sRequestBody);
  887.                     //LOG.info("mRequestParam {}", sRequestBody);
  888.                     saveNewTaskInfo(sRequestBody, sResponseBody, mRequestParam);
  889.                 }
  890.                 //{nID_Service=25, nID_Subject=255289, nID_ServiceData=542, sID_BP=dms_0025_ID2 545_iGov:1:1, sID_UA=1210100000}
  891.                 LOG.info("saveNewTaskInfo block finished");
  892.             } else if (isCloseTask(oRequest, sResponseBody)) {
  893.                 LOG.info("saveClosedTaskInfo block started");
  894.                 List<String> aTaskId = new ArrayList<>();
  895.  
  896.                 if (oRequest.getRequestURL().toString().indexOf(SERVICE_CANCELTASK) > 0) {
  897.                     LOG.info("We catch cancel task...");
  898.                     //LOG.info("mRequestParam {}", mRequestParam);
  899.                     String nID_Order = mRequestParam.get("nID_Order");
  900.                     //LOG.info("nID_Order {}", nID_Order);
  901.  
  902.                     aTaskId = actionTaskService.getTaskIdsByProcessInstanceId(
  903.                             actionTaskService.getOriginalProcessInstanceId(Long.parseLong(nID_Order)));
  904.  
  905.                     List<Task> aTask = taskService.createTaskQuery().processInstanceId(
  906.                             actionTaskService.getOriginalProcessInstanceId(Long.parseLong(nID_Order))).active().list();
  907.                     boolean bProcessClosed = aTask == null || aTask.size() == 0;
  908.                     String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  909.                     LOG.info("sUserTaskName in close event is {}", sUserTaskName);
  910.                     //for(String taskId : aTaskId){
  911.                     //LOG.info("taskId {}", aTaskId.get(aTaskId.size() - 1));
  912.                     Map<String, String> mParam = new HashMap<>();
  913.                     String sID_Order = generalConfig.getOrderId_ByOrder(generalConfig.getSelfServerId(), Long.parseLong(nID_Order));
  914.                     LOG.info("sID_Order for cancel flowslot {}", sID_Order);
  915.                     mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  916.                     closeTaskEvent.doWorkOnCloseTaskEvent(bFinish, aTaskId.get(aTaskId.size() - 1), null, true);
  917.                     //oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 19L);
  918.                 }
  919.                 sType = "Close";
  920.                 if (aTaskId.isEmpty()) {
  921.                     saveClosedTaskInfo(sRequestBody, snTaskId, bFinish);
  922.                 }
  923.                 LOG.info("saveClosedTaskInfo block finished");
  924.             } else if (isUpdateTask(oRequest)) {
  925.                 sType = "Update";
  926.                 LOG.info("saveUpdatedTaskInfo block started");
  927.                 //LOG.info("oRequest URL: {}", oRequest.getRequestURL().toString());
  928.                 //LOG.info("oRequest mRequestParam: {}", mRequestParam);
  929.                 saveUpdatedTaskInfo(sResponseBody, mRequestParam);
  930.                 LOG.info("saveUpdatedTaskInfo block finished");
  931.             }
  932.         } catch (Exception oException) {
  933.             LOG.error("Can't save service-history record: {}", oException.getMessage());
  934.         }
  935.     }
  936.  
  937.     /**
  938.      * сохранение информации таска
  939.      *
  940.      * @param sRequestBody
  941.      * @param sResponseBody
  942.      * @param mParamRequest
  943.      * @throws Exception
  944.      */
  945.     private void saveNewTaskInfo(String sRequestBody, String sResponseBody, Map<String, String> mParamRequest)
  946.             throws Exception {
  947.  
  948.         LOG.info("saveNewTaskInfo started in " + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
  949.  
  950.         /*LOG.info("sRequestBody {}", sRequestBody);//
  951.         LOG.info("sResponseBody {}", sResponseBody);
  952.         LOG.info("mParamRequest {}", mParamRequest);*/
  953.         if (sResponseBody == null) {
  954.             //LOG.warn("sResponseBody=null!!! (sRequestBody={},mParamRequest={})", sRequestBody, mParamRequest);
  955.         }
  956.         Map<String, String> mParam = new HashMap<>();
  957.         //LOG.info("sRequestBody {}", sRequestBody);
  958.         JSONObject omRequestBody = (JSONObject) oJSONParser.parse(sRequestBody);
  959.  
  960.         // LOG.info("omRequestBody >>>>>>>>>>>>>> {}", omRequestBody );
  961.         JSONArray properties = (JSONArray) omRequestBody.get("properties");
  962.         //  LOG.info("properties >>>>>>>>>>>>>> {}", properties );
  963.  
  964.         if (properties == null) {
  965.             properties = (JSONArray) omRequestBody.get("aFormProperty");
  966.         }
  967.  
  968.         Iterator<JSONObject> iterator = properties.iterator();
  969.         String sID_Public_SubjectOrganJoin = null;
  970.  
  971.         while (iterator.hasNext()) {
  972.             JSONObject jsonObject = iterator.next();
  973.  
  974.             if (jsonObject.get("value") instanceof java.lang.String) {
  975.                 String sId = (String) jsonObject.get("id");
  976.                 String sValue = (String) jsonObject.get("value");
  977.  
  978.                 if (sId.equals("sID_Public_SubjectOrganJoin")) {
  979.                     sID_Public_SubjectOrganJoin = sValue;
  980.                     break;
  981.                 }
  982.             }
  983.         }
  984.         LOG.info("RequestProcessingInterceptor sID_Public_SubjectOrganJoin: " + sID_Public_SubjectOrganJoin);
  985.         mParam.put("sID_Public_SubjectOrganJoin", sID_Public_SubjectOrganJoin);
  986.  
  987.         JSONObject omResponseBody = (JSONObject) oJSONParser.parse(sResponseBody);
  988.         mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  989.  
  990.         //String osnID_Process = omResponseBody.containsKey("id"); //разобраться чего получаем нал в некоторых случаях
  991.         String snID_Process = String.valueOf(omResponseBody.containsKey("id") ? omResponseBody.get("id") : omResponseBody.get("snID_Process")); //разобраться чего получаем нал в некоторых случаях
  992.         //if(snID_Process) //{"snID_Process":"23285433","nID_Task":"23285483"}
  993.         if (sRequestBody != null && sRequestBody.contains("sCancelInfo")) {
  994.             runtimeService.setVariable(snID_Process, "sCancelInfo", String.format("Заявка актуальна"));
  995.         }
  996.  
  997.         if (snID_Process != null && !"null".equalsIgnoreCase(snID_Process)) {
  998.             Long nID_Process = Long.valueOf(snID_Process);
  999.             LOG.info("snID_Process please be here: " + snID_Process);
  1000.             String sID_Order = generalConfig.getOrderId_ByProcess(nID_Process);
  1001.             //String snID_Subject = String.valueOf(omRequestBody.get("nID_Subject"));
  1002.             String snID_Subject = String.valueOf(omRequestBody.containsKey("nID_Subject") ? omRequestBody.get("nID_Subject") : mParamRequest.get("nID_Subject"));
  1003.             mParam.put("nID_Subject", snID_Subject);
  1004.  
  1005.             LOG.info("(sID_Order={},nID_Subject={})", sID_Order, snID_Subject);
  1006.  
  1007.             String snID_Service = mParamRequest.get("nID_Service");
  1008.             LOG.info("nID_Service in RequestProcessingInterceptor: " + snID_Service);
  1009.             if (snID_Service != null) {
  1010.                 mParam.put("nID_Service", snID_Service);
  1011.             }
  1012.  
  1013.             String sID_UA = mParamRequest.get("sID_UA");
  1014.             if (sID_UA != null) {
  1015.                 mParam.put("sID_UA", sID_UA);
  1016.             }
  1017.  
  1018.             LOG.info("RequestProcessingInterceptor sID_UA: " + sID_UA);
  1019.  
  1020.             //TODO: need remove in future
  1021.             String snID_Region = mParamRequest.get("nID_Region");
  1022.             if (snID_Region != null) {
  1023.                 LOG.info("nID_Region in saveNewTaskInfo is {}", snID_Region);
  1024.                 mParam.put("nID_Region", snID_Region);
  1025.             }
  1026.  
  1027.             LOG.info("RequestProcessingInterceptor snID_Region: " + snID_Region);
  1028.  
  1029.             String snID_ServiceData = mParamRequest.get("nID_ServiceData");
  1030.             if (snID_ServiceData != null) {
  1031.                 mParam.put("nID_ServiceData", snID_ServiceData);
  1032.             }
  1033.  
  1034.             LOG.info("RequestProcessingInterceptor snID_ServiceData: " + snID_ServiceData);
  1035.  
  1036.             HistoricProcessInstance oHistoricProcessInstance
  1037.                     = historyService.createHistoricProcessInstanceQuery().processInstanceId(snID_Process).singleResult();
  1038.             ProcessDefinition oProcessDefinition = repositoryService.createProcessDefinitionQuery()
  1039.                     .processDefinitionId(oHistoricProcessInstance.getProcessDefinitionId()).singleResult();
  1040.             String sProcessName = oProcessDefinition.getName() != null ? oProcessDefinition.getName() : "";
  1041.             //mParam.put("sProcessInstanceName", sProcessInstanceName);
  1042.             mParam.put("sHead", sProcessName);
  1043.  
  1044.             List<Task> aTask = taskService.createTaskQuery().processInstanceId(snID_Process).active().list();
  1045.             boolean bProcessClosed = aTask == null || aTask.size() == 0;
  1046.             String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();//"(нет назви)"
  1047.  
  1048.             sendMailTo(omRequestBody, sID_Order, snID_Subject, snID_Service, oProcessDefinition);
  1049.  
  1050.             historyEventService.addHistoryEvent(sID_Order, sUserTaskName, mParam);
  1051.             //LOG.info("Before calling set action process count {}, {}", mParam, oProcessDefinition.getKey());
  1052.             if (oProcessDefinition.getKey().startsWith("_doc_") || DNEPR_MVK_291_COMMON_BP.contains(oProcessDefinition.getKey())) {
  1053.                 //Integer count = ActionProcessCountUtils.callSetActionProcessCount(httpRequester, generalConfig, oProcessDefinition.getKey(), Long.valueOf(snID_Service));
  1054.                 //LOG.info("RequestProcessInterceptor process count: " + count.intValue());
  1055.             }//2017-05-16_13:56:48.390
  1056.         }
  1057.     }
  1058.  
  1059.     /**
  1060.      * сохранение информации при закрытии таски
  1061.      *
  1062.      * @param sRequestBody
  1063.      * @param snClosedTaskId
  1064.      * @param bSaveHistory
  1065.      * @throws Exception
  1066.      */
  1067.     //(#1234) added additional parameter snClosedTaskId
  1068.     private void saveClosedTaskInfo(String sRequestBody, String snClosedTaskId, boolean bSaveHistory) throws Exception {
  1069.         LOG.info("Method saveClosedTaskInfo started");
  1070.  
  1071.         //LOG.info("sRequestBody is {}", sRequestBody);
  1072.         LOG.info("snClosedTaskId is {}", snClosedTaskId);
  1073.  
  1074.         JSONObject omRequestBody = null;
  1075.         String snID_Task = null;
  1076.         try {
  1077.             omRequestBody = (JSONObject) oJSONParser.parse(sRequestBody);
  1078.             snID_Task = String.valueOf(omRequestBody.get("taskId"));
  1079.         } catch (Exception ex) {
  1080.             LOG.info("sRequestBody in saveClosedTaskInfo is unparsable {}", ex);
  1081.         }
  1082.  
  1083.         if ((snID_Task == null) && (snClosedTaskId != null)) {
  1084.             snID_Task = snClosedTaskId.trim();
  1085.             LOG.info("Task id from requestbody is null, so using task id from url - " + snID_Task);
  1086.         }
  1087.  
  1088.         LOG.info("Task id is - " + snID_Task);
  1089.         if (snID_Task != null) {
  1090.             closeTaskEvent.doWorkOnCloseTaskEvent(bSaveHistory, snID_Task, omRequestBody, false);
  1091.         }
  1092.         LOG.info("Method saveClosedTaskInfo END");
  1093.     }
  1094.  
  1095.     /**
  1096.      * сохранение информации при обновлении таски
  1097.      *
  1098.      * @param sResponseBody
  1099.      * @param mRequestParam
  1100.      * @throws Exception
  1101.      */
  1102.     private void saveUpdatedTaskInfo(String sResponseBody, Map<String, String> mRequestParam) throws Exception {
  1103.         Map<String, String> mParam = new HashMap<>();
  1104.         JSONObject omResponseBody = (JSONObject) oJSONParser.parse(sResponseBody);
  1105.         String snID_Task = (String) omResponseBody.get("taskId");
  1106.         if (snID_Task == null && mRequestParam.containsKey("taskId")) {
  1107.             LOG.info("snID_Task is NULL, looking for it in mRequestParam");
  1108.             snID_Task = (String) mRequestParam.get("taskId");
  1109.             LOG.info("Found taskId in mRequestParam {}", snID_Task);
  1110.         }
  1111.  
  1112.         LOG.info("Looking for a task with ID {}", snID_Task);
  1113.  
  1114.         HistoricTaskInstance oHistoricTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(snID_Task)
  1115.                 .singleResult();
  1116.  
  1117.         mParam.put("sUserTaskName", oHistoricTaskInstance.getName());
  1118.         String snID_Process = oHistoricTaskInstance.getProcessInstanceId();
  1119.         closeEscalationProcessIfExists(snID_Process);
  1120.         Long nID_Process = Long.valueOf(snID_Process);
  1121.         String sSubjectInfo = mRequestParam.get("sSubjectInfo");
  1122.         if (sSubjectInfo != null) {
  1123.             mParam.put("sSubjectInfo", sSubjectInfo);
  1124.         }
  1125.         if (mRequestParam.get("nID_Subject") != null) {
  1126.             String nID_Subject = String.valueOf(mRequestParam.get("nID_Subject"));
  1127.             mParam.put("nID_Subject", nID_Subject);
  1128.         }
  1129.         LOG.info("mParams: {}", mParam.toString());
  1130.         String sID_Order = generalConfig.getOrderId_ByProcess(nID_Process);
  1131.         LOG.info("(sID_Order={})", sID_Order);
  1132.         historyEventService.updateHistoryEvent(sID_Order, HistoryEvent_Service_StatusType.OPENED_ASSIGNED, mParam);
  1133.         LOG.info("historyEventService.updateHistoryEvent finished");
  1134.         updateEscalationState(oHistoricTaskInstance, nID_Process);
  1135.     }
  1136.  
  1137.     /**
  1138.      *
  1139.      * @param omRequestBody
  1140.      * @param sID_Order
  1141.      * @param snID_Subject
  1142.      * @param snID_Service
  1143.      * @param oProcessDefinition
  1144.      * @throws ParseException
  1145.      * @throws EmailException
  1146.      */
  1147.     public void sendMailTo(JSONObject omRequestBody, String sID_Order, String snID_Subject, String snID_Service,
  1148.             ProcessDefinition oProcessDefinition) throws ParseException, EmailException {                
  1149.        
  1150.         String sMailTo = JsonRequestDataResolver.getEmail(omRequestBody);        
  1151.        
  1152.         String sPhone = String.valueOf(JsonRequestDataResolver.getPhone(omRequestBody));
  1153.         String bankIdFirstName = JsonRequestDataResolver.getBankIdFirstName(omRequestBody);
  1154.         String bankIdLastName = JsonRequestDataResolver.getBankIdLastName(omRequestBody);  
  1155.  
  1156.         int nID_Server = generalConfig.getSelfServerId();
  1157.         LOG.info("nID_Server in sendMailTo in interceptor is ", nID_Server);
  1158.  
  1159.         if (sMailTo != null) {            
  1160.             if (Arrays.asList(asID_BP_SendMail).contains(oProcessDefinition.getKey())) {
  1161.                 ActionProcessCountUtils.callSetActionProcessCount(httpRequester, generalConfig, oProcessDefinition.getKey(), Long.valueOf(snID_Service));
  1162.                 LOG.info("Before send notification mail... (sMailTo={}, oProcessDefinition.getKey()={})", sMailTo, oProcessDefinition.getKey());
  1163.                 oNotificationPatterns.sendTaskCreatedInfoEmail(sMailTo, sID_Order, bankIdFirstName, bankIdLastName);
  1164.                 LOG.info("Send notification mail... (sMailTo={}, oProcessDefinition.getKey()={})", sMailTo, oProcessDefinition.getKey());
  1165.             } else {
  1166.                 LOG.info("SKIP send notification mail... (sMailTo={}, oProcessDefinition.getKey()={})", sMailTo, oProcessDefinition.getKey());
  1167.             }
  1168.         }
  1169.  
  1170.         if (sMailTo != null || sPhone != null) {
  1171.             try {
  1172.                 Map<String, String> mParamSync = new HashMap<String, String>();
  1173.                 mParamSync.put("snID_Subject", snID_Subject);
  1174.                 mParamSync.put("sMailTo", sMailTo);
  1175.                 mParamSync.put("sPhone", sPhone);
  1176.                 LOG.info("Вносим параметры в коллекцию (sMailTo {}, snID_Subject {}, sPhone {})", sMailTo, snID_Subject, sPhone);
  1177.                 String sURL = generalConfig.getSelfHostCentral() + URI_SYNC_CONTACTS;
  1178.                 LOG.info("Подключаемся к центральному порталу by sURL: " + sURL);
  1179.                 String sResponse = httpRequester.getInside(sURL, mParamSync);
  1180.                 LOG.info("Подключение осуществлено.. sResponse is: " + sResponse);
  1181.             } catch (Exception ex) {
  1182.                 LOG.warn("(isSaveTask exception {})", ex.getMessage());
  1183.             }
  1184.  
  1185.         }
  1186.     }
  1187.  
  1188.     /**
  1189.      * Обновление статуса ескалации
  1190.      *
  1191.      * @param oHistoricTaskInstance
  1192.      * @param nID_Process
  1193.      */
  1194.     public void updateEscalationState(HistoricTaskInstance oHistoricTaskInstance, Long nID_Process) {
  1195.         String sProcessName = oHistoricTaskInstance.getProcessDefinitionId();
  1196.         try {
  1197.             LOG.info("Update escalation history... (sProcessName={})", sProcessName);
  1198.             if (sProcessName.indexOf(BpServiceHandler.PROCESS_ESCALATION) == 0) {//issue 981
  1199.                 escalationHistoryService
  1200.                         .updateStatus(nID_Process, EscalationHistoryService.STATUS_IN_WORK);//Long.valueOf(sID_Process)
  1201.             } else { //issue 1297
  1202.                 LOG.trace("BpServiceHandler.PROCESS_ESCALATION = {}", BpServiceHandler.PROCESS_ESCALATION);
  1203.             }
  1204.         } catch (Exception oException) {
  1205.             new Log(oException, LOG)//this.getClass()
  1206.                     ._Case("IC_UpdateEscalation")
  1207.                     ._Status(Log.LogStatus.ERROR)
  1208.                     ._Head("Can't update escalation history")
  1209.                     ._Param("nID_Process", nID_Process)
  1210.                     ._LogTrace()
  1211.                     .save();
  1212.         }
  1213.     }
  1214.  
  1215.     private boolean isUpdateTask(HttpServletRequest oRequest) {
  1216.         return (oRequest.getRequestURL().toString().indexOf(RUNTIME_TASKS) > 0
  1217.                 && PUT.equalsIgnoreCase(oRequest.getMethod().trim()))
  1218.                 || oRequest.getRequestURL().toString().indexOf("action/task/updateProcess") > 0
  1219.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim());
  1220.     }
  1221.  
  1222.     private boolean isCloseTask(HttpServletRequest oRequest, String sResponseBody) {
  1223.         return POST.equalsIgnoreCase(oRequest.getMethod().trim())
  1224.                 && (((sResponseBody == null || "".equals(sResponseBody))
  1225.                 && (oRequest.getRequestURL().toString().indexOf(FORM_FORM_DATA) > 0
  1226.                 || oRequest.getRequestURL().toString().indexOf(UPDATE_PROCESS) > 0))
  1227.                 || TAG_PATTERN_PREFIX.matcher(oRequest.getRequestURL()).find()
  1228.                 || (oRequest.getRequestURL().toString().indexOf(SERVICE_CANCELTASK) > 0));
  1229.     }
  1230.  
  1231.     private boolean isSaveTask(HttpServletRequest oRequest, String sResponseBody, boolean bFinish) {
  1232.         return (bFinish && sResponseBody != null && !"".equals(sResponseBody))
  1233.                 //&& oRequest.getRequestURL().toString().indexOf(FORM_FORM_DATA) > 0
  1234.                 && ((oRequest.getRequestURL().toString().indexOf(FORM_FORM_DATA) > 0
  1235.                 || oRequest.getRequestURL().toString().indexOf(UPDATE_PROCESS) > 0)
  1236.                 || oRequest.getRequestURL().toString().indexOf(START_PROCESS) > 0)
  1237.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim());
  1238.     }
  1239.  
  1240.     private boolean isDocumentSubmit(HttpServletRequest oRequest) {
  1241.         return (oRequest != null && (oRequest.getRequestURL().toString().indexOf(FORM_FORM_DATA) > 0
  1242.                 || oRequest.getRequestURL().toString().indexOf(UPDATE_PROCESS) > 0)
  1243.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim()));
  1244.     }
  1245.  
  1246.     private boolean isUpdateProcess(HttpServletRequest oRequest) {
  1247.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf("task/updateProcess") > 0
  1248.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim()));
  1249.     }
  1250.  
  1251.     private boolean isSetDocumentService(HttpServletRequest oRequest, String sResponseBody, boolean bFinish) {
  1252.         boolean isNewDocument = (bFinish && sResponseBody != null && !"".equals(sResponseBody))
  1253.                 && oRequest.getRequestURL().toString().indexOf(DOCUMENT_SERVICE) > 0
  1254.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim());
  1255.  
  1256.         if (isNewDocument) {
  1257.             LOG.info("We catch document in requestProcessingInterceptor! Yippie-Kai-Yay!");
  1258.         }
  1259.  
  1260.         return isNewDocument;
  1261.     }
  1262.  
  1263.     protected void closeEscalationProcessIfExists(String sID_Process) {
  1264.         closeTaskEvent.closeEscalationProcessIfExists(sID_Process);
  1265.     }
  1266.  
  1267.     private boolean isSetProcessSubjectStatus(HttpServletRequest oRequest) {
  1268.  
  1269.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(SERVICE_SUBJECT_PROCESS_SET_PROCESS_SUBJECT_STATUS) > 0
  1270.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim()));
  1271.     }
  1272.  
  1273.     private void processSubjectStatusHistoryWritingPreHandle(HttpServletRequest oRequest) throws Exception {
  1274.         try {
  1275.             if (isSetProcessSubjectStatus(oRequest)) {
  1276.                 Map<String, String> mRequestParam = getmRequestParam(oRequest);
  1277.  
  1278.                 JsonParser parser = new JsonParser();
  1279.  
  1280.                 String sBody = oRequest.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
  1281.                 //LOG.info("sBody={}", sBody);
  1282.                 JsonObject jsonBody = parser.parse(sBody).getAsJsonObject();  
  1283.                
  1284.                 JsonObject jsonQueryParams = jsonBody.get("queryParams").getAsJsonObject();
  1285.  
  1286.                 String sID_ProcessSubjectStatus = jsonQueryParams.get("sID_ProcessSubjectStatus").getAsString();
  1287.                 String snID_Task_Activiti = jsonQueryParams.get("snID_Task_Activiti").getAsString();
  1288.                 String sLoginController = jsonQueryParams.get("sLoginController") == null
  1289.                         ? null : jsonQueryParams.get("sLoginController").getAsString();
  1290.                 String sLoginExecutor = jsonQueryParams.get("sLoginExecutor") == null
  1291.                         ? null : jsonQueryParams.get("sLoginExecutor").getAsString();
  1292.                 LOG.debug("snID_Task_Activiti={}, sID_ProcessSubjectStatus={}, sLoginController={},"
  1293.                         + "sLoginExecutor={}", snID_Task_Activiti, sID_ProcessSubjectStatus, sLoginController,
  1294.                         sLoginExecutor);
  1295.                 String sText = jsonQueryParams.get("sText") == null
  1296.                         ? null : jsonQueryParams.get("sText").getAsString();;
  1297.                 String sDatePlaneNew = jsonQueryParams.get("sDatePlaneNew") == null
  1298.                         ? null : jsonQueryParams.get("sDatePlaneNew").getAsString();;
  1299.  
  1300.                 boolean isReferent = false;
  1301.                 String sReferentInitials = "";
  1302.                 String sLoginReferent = (String) mRequestParam.get("sLoginReferent");
  1303.                 if (sLoginReferent != null && !sLoginReferent.isEmpty()) {
  1304.                     isReferent = true;
  1305.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginReferent);
  1306.                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1307.                     sReferentInitials = usersService.getUserInitials(sFIO);
  1308.                 }
  1309.                 /**
  1310.                  * Определяем кто вызвал сервис (исполнитель или контролирующий). Пришел только логин sLoginExecutor -
  1311.                  * исполнитель, пришел только логин sLoginController - контролирующий, если пришло два логина -
  1312.                  * контролирующий.
  1313.                  */
  1314.                 String sLoginMain = sLoginController;
  1315.                 String sLoginRoleMain = "Controller";
  1316.                 if (sLoginExecutor != null && sLoginController == null) {
  1317.                     sLoginMain = sLoginExecutor;
  1318.                     sLoginRoleMain = "Executor";
  1319.                 }
  1320.  
  1321.                 if (sLoginRoleMain.equals("Executor") || sLoginRoleMain.equals("Controller")) {
  1322.                     HistoricTaskInstance oHistoricTaskInstance = historyService.createHistoricTaskInstanceQuery()
  1323.                             .taskId(snID_Task_Activiti)
  1324.                             .singleResult();
  1325.                     String sProcessInstanceId = oHistoricTaskInstance.getProcessInstanceId();
  1326.  
  1327.                     String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(sProcessInstanceId));
  1328.  
  1329.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginMain);
  1330.                     String sName = oSubjectGroup.getoSubject().getsLabel();
  1331.  
  1332.                     List<Task> aTask = taskService.createTaskQuery()
  1333.                             .processInstanceId(sProcessInstanceId)
  1334.                             .active()
  1335.                             .list();
  1336.                     boolean bProcessClosed = aTask == null || aTask.isEmpty();
  1337.                     //проверка, чтобы выбрать таску по ид, который пришел в запросе
  1338.                     String sUserTaskName = bProcessClosed
  1339.                             ? "закрита"
  1340.                             : aTask.stream().filter(oTask
  1341.                                     -> oTask.getId().equals(snID_Task_Activiti)).findFirst().toString();
  1342.  
  1343.                     JSONObject oTransportObject = new JSONObject();
  1344.  
  1345.                     oTransportObject.put("sLoginRole", sLoginRoleMain);
  1346.                     oTransportObject.put("sProcessInstanceId", sProcessInstanceId);
  1347.                     oTransportObject.put("sID_Order", sID_Order);
  1348.                     oTransportObject.put("sUserTaskName", sUserTaskName);
  1349.                     oTransportObject.put("sName", sName);
  1350.                     oTransportObject.put("sLogin", sLoginMain);
  1351.                     oTransportObject.put("sID_ProcessSubjectStatus", sID_ProcessSubjectStatus);
  1352.                     oTransportObject.put("sText", sText);
  1353.                     oTransportObject.put("sDatePlaneNew", sDatePlaneNew);
  1354.                     oTransportObject.put("snID_Task_Activiti", snID_Task_Activiti);
  1355.                     oTransportObject.put("sReferentInitials", sReferentInitials);
  1356.                     LOG.info("oTransportObject={}", oTransportObject);
  1357.  
  1358.                     oRequest.setAttribute("oTransportObject", oTransportObject);
  1359.                 }
  1360.             }
  1361.         } catch (Exception oException) {
  1362.             LOG.error("Error during writing processSubjectStatusHistory in interceptor: {}", oException);
  1363.         }
  1364.     }
  1365.  
  1366.     private void deleteMessagePreHandle(HttpServletRequest oRequest) throws Exception {
  1367.         try {
  1368.             if (isDeleteMessage(oRequest)){
  1369.                 Map<String, String> mRequestParam = getmRequestParam(oRequest);
  1370.                 //LOG.info("deleteMessagePreHandle mRequestParam: {}", mRequestParam);
  1371.                 JSONObject oTransportObject = new JSONObject();
  1372.  
  1373.                 String snID_ProcessChatMessage = mRequestParam.get("nID_ProcessChatMessage");
  1374.  
  1375.                 ProcessChatMessage oProcessChatMessage = oProcessChatMessageDao.findByIdExpected(Long.valueOf(snID_ProcessChatMessage));
  1376.                 String snID_Process_Activiti = String.valueOf(oProcessChatMessage.getoProcessChat().getnID_Process_Activiti());
  1377.  
  1378.                 String sKeyGroup = oProcessChatMessage.getoProcessChat().getsKeyGroup();
  1379.                 boolean isComment = false;
  1380.                 if(sKeyGroup == null || sKeyGroup.isEmpty()){
  1381.                     isComment = true;
  1382.                 }
  1383.  
  1384.                 String sLogin = mRequestParam.get("sLogin");
  1385.                 String sLoginReferent = mRequestParam.get("sLoginReferent");
  1386.  
  1387.                 oTransportObject.put("sBody", oProcessChatMessage.getsBody());
  1388.                 oTransportObject.put("isComment", isComment);
  1389.                 oTransportObject.put("snID_Process_Activiti", snID_Process_Activiti);
  1390.                 oTransportObject.put("sLogin", sLogin);
  1391.                 oTransportObject.put("sLoginReferent", sLoginReferent);
  1392.                 //LOG.info("oTransportObject={}", oTransportObject);
  1393.  
  1394.                 oRequest.setAttribute("oTransportObject", oTransportObject);
  1395.             }
  1396.         } catch (Exception oException){
  1397.             LOG.error("Error during writing deleteMessagePreHandle in interceptor: {}", oException);
  1398.         }
  1399.     }
  1400.  
  1401.     private void deleteMessagePostHandle(HttpServletRequest oRequest) throws Exception {
  1402.         try {
  1403.             if (isDeleteMessage(oRequest)) {
  1404.  
  1405.                 Map<String, Object> mRequestAttribute = getmRequestAttribute(oRequest);
  1406.                 JSONObject oTransportObject = (JSONObject) mRequestAttribute.get("oTransportObject");
  1407.  
  1408.  
  1409.                 String sBody = (String) oTransportObject.get("sBody");
  1410.                 String sLogin = (String) oTransportObject.get("sLogin");
  1411.                 String sLoginReferent = (String) oTransportObject.get("sLoginReferent");
  1412.                 String snID_Process_Activiti = (String) oTransportObject.get("snID_Process_Activiti");
  1413.                 boolean isComment = (boolean) oTransportObject.get("isComment");
  1414.  
  1415.  
  1416.                 String sAuthorInitials = "";
  1417.                 if (sLogin != null && !sLogin.isEmpty()) {
  1418.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1419.                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1420.                     sAuthorInitials = usersService.getUserInitials(sFIO);
  1421.                 }
  1422.                 String sReferentInitials = "";
  1423.                 if (sLoginReferent != null && !sLoginReferent.isEmpty()) {
  1424.                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginReferent);
  1425.                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1426.                     sReferentInitials = usersService.getUserInitials(sFIO);
  1427.                 }
  1428.  
  1429.                 Map<String, String> mParam = new HashMap<>();
  1430.  
  1431.  
  1432.                 mParam.put("sName", sAuthorInitials);
  1433.                 mParam.put("sLoginNew", sReferentInitials);
  1434.                 mParam.put("sBody", sBody);
  1435.  
  1436.  
  1437.                 List<Task> aTask = taskService.createTaskQuery().processInstanceId(snID_Process_Activiti).active().list();
  1438.                 boolean bProcessClosed = aTask == null || aTask.size() == 0;
  1439.                 String sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  1440.                 String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(snID_Process_Activiti));
  1441.  
  1442.                 mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  1443.                 mParam.put("sID_Process", snID_Process_Activiti);
  1444.  
  1445.  
  1446.                 if(isComment){
  1447.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 57L);
  1448.                 } else {
  1449.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 42L);
  1450.                 }
  1451.  
  1452.             }
  1453.         } catch (Exception oException) {
  1454.             LOG.error("Error during writing deleteMessagePostHandle in interceptor: {}", oException);
  1455.         }
  1456.     }
  1457.  
  1458.     private void processSubjectStatusHistoryWritingPostHandle(HttpServletRequest oRequest) throws Exception {
  1459.         try {
  1460.  
  1461.             if (isSetProcessSubjectStatus(oRequest)) {
  1462.                 Map<String, Object> mRequestAttribute = getmRequestAttribute(oRequest);
  1463.                
  1464.                 JSONObject oTransportObject = (JSONObject) mRequestAttribute.get("oTransportObject");
  1465.  
  1466.                 String sLoginRole = (String) oTransportObject.get("sLoginRole");
  1467.                 String sID_Order = (String) oTransportObject.get("sID_Order");
  1468.                 String sUserTaskName = (String) oTransportObject.get("sUserTaskName");
  1469.                 String sName = (String) oTransportObject.get("sName");
  1470.                 String sLogin = (String) oTransportObject.get("sLogin");
  1471.                 String sID_ProcessSubjectStatus = (String) oTransportObject.get("sID_ProcessSubjectStatus");
  1472.                 String sText = (String) oTransportObject.get("sText");
  1473.                 String sDatePlaneNew = (String) oTransportObject.get("sDatePlaneNew");                                  
  1474.                 String snID_Task_Activiti = (String) oTransportObject.get("snID_Task_Activiti");
  1475.                 String sProcessInstanceId = (String) oTransportObject.get("sProcessInstanceId");
  1476.                 String sReferentInitials = (String) oTransportObject.get("sReferentInitials");
  1477.                
  1478.                  
  1479.                 String sAuthorInitials = "";
  1480.                 if (!sName.isEmpty()) {
  1481.                     sAuthorInitials = usersService.getUserInitials(sName);
  1482.                 }
  1483.                
  1484.                 Map<String, String> mParam = new HashMap<>();
  1485.                
  1486.                 if (sReferentInitials.isEmpty()){
  1487.                     mParam.put("sLoginNew", sAuthorInitials);
  1488.                 }
  1489.                 else {
  1490.                     mParam.put("sLoginNew", sReferentInitials);
  1491.                 }
  1492.                                                
  1493.                
  1494.                 mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  1495.                
  1496.                 mParam.put("sName", sAuthorInitials);
  1497.                 mParam.put("sID_Process", sProcessInstanceId);
  1498.                
  1499.                 /*String sTemplateDoc = "/documents/sID_Order=";
  1500.                 String sTemplateFile = "/api/tasks/download/";
  1501.                 String sTemplateFileName = "/attachment/Mongo/";*/
  1502.                 String sAnswer = " ";
  1503.                
  1504.                /* Long nID = generalConfig.getSelfServerId().longValue();
  1505.                
  1506.                 Server oServer = oServerDao.findByIdExpected(nID);
  1507.                 String sURL = oServer.getsURL();*/
  1508.                  
  1509.                 ProcessSubject oProcessSubject = oProcessSubjectDao.findByExpected("snID_Task_Activiti", snID_Task_Activiti);
  1510.  
  1511.                 String sTextType = oProcessSubject.getsTextType();
  1512.                                
  1513.                 if (sID_ProcessSubjectStatus.equals("executed") && sLoginRole.equals("Executor")) {
  1514.                     sAnswer = oProcessSubjectService.getReport(oProcessSubject);
  1515.                     /*if (sText != null) {
  1516.                         if (sTextType.equals("string")) {
  1517.                             String sBody = sURL + sTemplateDoc + sText;
  1518.                             sAnswer = "<a href=\"" + sBody + "\">" + sBody + "</a>";
  1519.                         } else if (sTextType.equals("textArea")) {
  1520.                             sAnswer = sText;
  1521.                         } else if (sTextType.equals("file")) {
  1522.                             JsonParser parser = new JsonParser();
  1523.                             JsonObject jsonFile = parser.parse(sText).getAsJsonObject();
  1524.                             //LOG.info("jsonFile: {}", jsonFile);
  1525.                             String sKey = jsonFile.get("sKey").getAsString();
  1526.                             //LOG.info("sKey: {}", sKey);
  1527.                             String sFileNameAndExt = jsonFile.get("sFileNameAndExt").getAsString();
  1528.                             //LOG.info("sFileNameAndExt: {}", sFileNameAndExt);
  1529.                             String sBody = sURL + sTemplateFile + sKey + sTemplateFileName + sFileNameAndExt;
  1530.                             sAnswer = "<a href=\"" + sBody + "\" target=\"_blank\" download>" + sBody + "</a>";
  1531.                         } else {
  1532.                             sAnswer = sText;
  1533.                         }
  1534.                     }*/
  1535.                     mParam.put("sBody", sAnswer);
  1536.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 20L);
  1537.                 } else if (sID_ProcessSubjectStatus.equals("notExecuted") && sLoginRole.equals("Executor")) {
  1538.                     mParam.put("sBody", sText);
  1539.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 21L);
  1540.                 } else if (sID_ProcessSubjectStatus.equals("unactual") && sLoginRole.equals("Executor")) {
  1541.                     mParam.put("sBody", sText);
  1542.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 22L);
  1543.                 } else if (sID_ProcessSubjectStatus.equals("requestTransfered") && sLoginRole.equals("Executor")) {                    
  1544.                     mParam.put("newData", sDatePlaneNew);
  1545.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 23L);
  1546.                 } else if (sID_ProcessSubjectStatus.equals("transfered") && sLoginRole.equals("Controller")) {
  1547.                     mParam.put("newData", sDatePlaneNew);
  1548.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 24L);
  1549.                 } else if (sID_ProcessSubjectStatus.equals("rejected") && sLoginRole.equals("Controller")) {
  1550.                     mParam.put("sBody", sText);
  1551.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 25L);
  1552.                 } else if (sID_ProcessSubjectStatus.equals("executed") && sLoginRole.equals("Controller")) {
  1553.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 26L);
  1554.                 } else if (sID_ProcessSubjectStatus.equals("notExecuted") && sLoginRole.equals("Controller")) {
  1555.                     mParam.put("sBody", sText);
  1556.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 27L);
  1557.                 } else if (sID_ProcessSubjectStatus.equals("unactual") && sLoginRole.equals("Controller")) {
  1558.                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 28L);
  1559.                 }
  1560.             }
  1561.         } catch (Exception oException) {
  1562.             LOG.error("Error during writing processSubjectStatusHistory in interceptor: {}", oException);
  1563.         }
  1564.     }
  1565.    
  1566.     private void checksLoginRefernt(HttpServletRequest oRequest) throws Exception
  1567.     {
  1568.        
  1569.         Map<String, String> mRequestParam = new HashMap<>();
  1570.         Enumeration<String> paramsName = oRequest.getParameterNames();
  1571.         while (paramsName.hasMoreElements()) {
  1572.             String sKey = (String) paramsName.nextElement();
  1573.             mRequestParam.put(sKey, oRequest.getParameter(sKey));
  1574.         }
  1575.        
  1576.         if(mRequestParam.containsKey("sLogin") && mRequestParam.containsKey("sLoginReferent")){
  1577.            String sLogin = (String) mRequestParam.get("sLogin");
  1578.            String sLoginReferent = (String) mRequestParam.get("sLoginReferent");
  1579.            LOG.info("checksLoginRefernt sLogin: {} sLoginReferent: {}", sLogin, sLoginReferent);
  1580.            if(sLoginReferent != null && !sLoginReferent.equals(sLogin)){
  1581.                 Set<String> asGroup = usersService.getUserGroupMember(sLoginReferent);
  1582.                
  1583.                 if(!asGroup.contains(sLogin)){
  1584.                     throw new RuntimeException(ACCESS_DENIED);
  1585.                 }
  1586.            }
  1587.         }
  1588.     }      
  1589.  
  1590.     private void taskHistoryProcessing(HttpServletRequest oRequest, HttpServletResponse oResponse) {
  1591.         try {          
  1592.             Map<String, String> mRequestParam = getmRequestParam(oRequest);
  1593.  
  1594.             StringBuilder osRequestBody_test = new StringBuilder();
  1595.             BufferedReader oReader_test = oRequest.getReader();
  1596.             String sline;
  1597.  
  1598.             if (oReader_test != null) {
  1599.                 while ((sline = oReader_test.readLine()) != null) {
  1600.                     osRequestBody_test.append(sline);
  1601.                 }
  1602.             }
  1603.             LOG_BIG.debug("taskHistoryProcessing mRequestParam: {}", mRequestParam);
  1604.  
  1605.             if (isSetMessage(oRequest) || isEditMessage(oRequest) || isAddAcceptor(oRequest) || isAddViewer(oRequest)
  1606.                     || isAddVisor(oRequest) || isDelegate(oRequest) || isCancelSign(oRequest) || isUpdateProcess(oRequest)
  1607.                     || isRemoveDocumentStepSubject(oRequest) || isDeleteMessage(oRequest)) {
  1608.  
  1609.                 StringBuilder osRequestBody = new StringBuilder();
  1610.                 BufferedReader oReader = oRequest.getReader();
  1611.                 String line;
  1612.  
  1613.                 if (oReader != null) {
  1614.                     while ((line = oReader.readLine()) != null) {
  1615.                         osRequestBody.append(line);
  1616.                     }
  1617.                 }
  1618.  
  1619.                 String sRequestBody = osRequestBody.toString();
  1620.  
  1621.                 JSONObject omRequestBody = null;
  1622.  
  1623.                 try {
  1624.                     if (!sRequestBody.trim().equals("")) {
  1625.                         omRequestBody = (JSONObject) oJSONParser.parse(sRequestBody);
  1626.                     }
  1627.                 } catch (Exception ex) {
  1628.                     LOG.info("Error parsing sRequestBody: {}", ex);
  1629.                 }
  1630.  
  1631.                 String sID_Process = null;
  1632.  
  1633.                 Map<String, String> mParam = new HashMap<>();
  1634.                 List<Task> aTask;
  1635.                 String sUserTaskName;
  1636.  
  1637.                 mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());              
  1638.  
  1639.                 if (mRequestParam != null) {
  1640.  
  1641.                     if (mRequestParam.get("nID_Process_Activiti") != null) {
  1642.                         sID_Process = String.valueOf(mRequestParam.get("nID_Process_Activiti"));
  1643.                     } else if (mRequestParam.get("snID_Process_Activiti") != null) {
  1644.                         sID_Process = String.valueOf(mRequestParam.get("snID_Process_Activiti"));
  1645.                     } else if (omRequestBody.get("nID_Process") != null) {
  1646.                         sID_Process = String.valueOf(omRequestBody.get("nID_Process"));
  1647.                     }
  1648.  
  1649.                     if (sID_Process != null) {
  1650.                         mParam.put("sID_Process", sID_Process);
  1651.                         String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(sID_Process));
  1652.                         mParam.put("sID_Order", sID_Order);
  1653.  
  1654.                         aTask = taskService.createTaskQuery().processInstanceId(sID_Process).active().list();
  1655.                         boolean bProcessClosed = aTask == null || aTask.size() == 0;
  1656.                         sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  1657.  
  1658.                         LOG.info("task sID_Process in interceptor {}", sID_Process);
  1659.                         LOG.info("task sID_Order in interceptor {}", sID_Order);
  1660.                         LOG.info("task sUserTaskName in interceptor {}", sUserTaskName);
  1661.  
  1662.                         String sLoginReferent = (String) mRequestParam.get("sLoginReferent");
  1663.                         String sLogin = "";
  1664.                         String sBody = "";
  1665.  
  1666.  
  1667.                         if (isSetMessage(oRequest) || isEditMessage(oRequest)) {
  1668.                             if (omRequestBody.get("sBody") != null) {
  1669.                                 sBody = omRequestBody.get("sBody").toString();
  1670.                             }
  1671.                             if (mRequestParam.get("sLogin") != null) {
  1672.                                 sLogin = mRequestParam.get("sLogin");
  1673.                             }
  1674.                         }
  1675.  
  1676.                         if (isAddAcceptor(oRequest) || isAddViewer(oRequest) || isAddVisor(oRequest) || isDelegate(oRequest)) {
  1677.                             if (mRequestParam.get("sKey_Group_Delegate") != null) {
  1678.                                 sLogin = mRequestParam.get("sKey_Group_Delegate");
  1679.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginNew);
  1680.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1681.                                 String sInitials = usersService.getUserInitials(sFIO);
  1682.                                 mParam.put("sLogin", sInitials);
  1683.                                 mParam.put("sLoginNew", sInitials);
  1684.                             }
  1685.                             if (mRequestParam.get("sKey_Group") != null) {
  1686.                                 String sLogin = (String) mRequestParam.get("sKey_Group");
  1687.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1688.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1689.                                 String sInitials = usersService.getUserInitials(sFIO);                                
  1690.                                 mParam.put("sName", sInitials);
  1691.                                
  1692.                                 if(isReferent){
  1693.                                     mParam.put("sBody", sReferentInitials);
  1694.                                 }
  1695.                                 else {
  1696.                                     mParam.put("sBody", sInitials);
  1697.                                 }
  1698.                             }
  1699.                         }  
  1700.                        
  1701.                         if(isRemoveDocumentStepSubject(oRequest)){
  1702.                             if (mRequestParam.get("sLogin") != null) {
  1703.                                 String sLoginNew = (String) mRequestParam.get("sLogin");
  1704.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLoginNew);
  1705.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1706.                                 String sInitials = usersService.getUserInitials(sFIO);                              
  1707.                                 mParam.put("sName", sInitials);                                                                
  1708.                                
  1709.                                 if(isReferent){
  1710.                                     mParam.put("sBody", sReferentInitials);
  1711.                                 }
  1712.                                 else {
  1713.                                     mParam.put("sBody", sInitials);
  1714.                                 }
  1715.                             }
  1716.                             if (mRequestParam.get("sKey_Group") != null) {
  1717.                                 String sLogin = (String) mRequestParam.get("sKey_Group");
  1718.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1719.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1720.                                 String sInitials = usersService.getUserInitials(sFIO);                                
  1721.                                 mParam.put("sLogin", sInitials);
  1722.                             }
  1723.                         }
  1724.  
  1725.                         if (isUpdateProcess(oRequest)) {
  1726.                            
  1727.                             if (omRequestBody.get("properties") != null) {
  1728.                                 JSONArray aProperties = (JSONArray) omRequestBody.get("properties");
  1729.                                 Iterator<JSONObject> iterator = aProperties.iterator();
  1730.  
  1731.                                 String eRemoveSignes = "";
  1732.  
  1733.                                 while (iterator.hasNext()) {
  1734.                                     JSONObject jsonObject = iterator.next();
  1735.                                     String sId = (String) jsonObject.get("id");
  1736.  
  1737.                                     if (sId.equals("eRemoveSignes")) {
  1738.                                         eRemoveSignes = String.valueOf(jsonObject.get("value"));
  1739.                                         LOG.info("eRemoveSignes {}", eRemoveSignes);
  1740.                                         if (eRemoveSignes.equals("sEnumRemove")) {
  1741.                                             if (mRequestParam.get("sLogin") != null) {
  1742.                                                 String sLogin = (String) mRequestParam.get("sLogin");
  1743.                                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1744.                                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1745.                                                 String sInitials = usersService.getUserInitials(sFIO);
  1746.                                                 LOG.info("sLoginNew: {}", sLogin);
  1747.                                                 mParam.put("sName", sInitials);
  1748.  
  1749.                                                 if (isReferent) {
  1750.                                                     mParam.put("sLoginNew", sReferentInitials);
  1751.                                                 } else {
  1752.                                                     mParam.put("sLoginNew", sInitials);
  1753.                                                 }
  1754.                                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 54L);
  1755.                                             }
  1756.                                         }
  1757.                                     }
  1758.                                 }
  1759.                             }
  1760.  
  1761.                             if (mRequestParam.get("sName_DocumentStepSubjectSignType") != null && !mRequestParam.get("sName_DocumentStepSubjectSignType").equals("sign")) {
  1762.                                 if (mRequestParam.get("sLogin") != null) {
  1763.                                     String sLogin = (String) mRequestParam.get("sLogin");
  1764.                                     SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1765.                                     String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1766.                                     String sInitials = usersService.getUserInitials(sFIO);
  1767.                                     LOG.info("sLoginNew: {}", sLogin);
  1768.                                     mParam.put("sName", sInitials);
  1769.  
  1770.                                     if (isReferent) {
  1771.                                         mParam.put("sLoginNew", sReferentInitials);
  1772.                                     } else {
  1773.                                         mParam.put("sLoginNew", sInitials);
  1774.                                     }
  1775.                                 }
  1776.                                 String StepType = (String) mRequestParam.get("sName_DocumentStepSubjectSignType");
  1777.                                 LOG.info("StepType: {}", StepType);
  1778.                                 if (StepType.equals("refuse")) {
  1779.                                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 39L);
  1780.                                 } else if (StepType.equals("needlessly")) {
  1781.                                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 38L);
  1782.                                 } else if (StepType.equals("seen")) {
  1783.                                     mParam.put("sBody", "ознайомлено");
  1784.                                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 41L);
  1785.                                 }
  1786.                             } else if (omRequestBody.get("sKey_Step") != null && omRequestBody.get("properties") != null) {
  1787.  
  1788.                                 String sSignType = " ";
  1789.                                 String sKeyStep = omRequestBody.get("sKey_Step").toString();
  1790.                                 DocumentStepType oDocumentStepType = null;
  1791.                                 String sLogin = (String) mRequestParam.get("sLogin");
  1792.  
  1793.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1794.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1795.                                 String sInitials = usersService.getUserInitials(sFIO);                                
  1796.                                 mParam.put("sName", sInitials);
  1797.                                
  1798.                                 if(isReferent){
  1799.                                     mParam.put("sLoginNew", sReferentInitials);
  1800.                                 }
  1801.                                 else {
  1802.                                     mParam.put("sLoginNew", sInitials);
  1803.                                 }
  1804.  
  1805.                                 List<DocumentStep> aDocumentSteps = oDocumentStepDao.getStepForProcess(sID_Process);
  1806.  
  1807.                                 JSONArray aProperties = (JSONArray) omRequestBody.get("properties");
  1808.                                 Iterator<JSONObject> iterator = aProperties.iterator();
  1809.  
  1810.                                 boolean bAuthor = false;
  1811.  
  1812.                                 while (iterator.hasNext()) {
  1813.                                     JSONObject jsonObject = iterator.next();
  1814.                                     String sId = (String) jsonObject.get("id");
  1815.  
  1816.                                     if (sId.equals("bAuthorEdit")) {
  1817.                                         Map<String, Object> mProcessVariable = new HashMap<>();
  1818.                                         HistoricProcessInstance oProcessInstance = oHistoryService.createHistoricProcessInstanceQuery()
  1819.                                                 .processInstanceId(sID_Process.trim()).includeProcessVariables().singleResult();
  1820.  
  1821.                                         mProcessVariable = oProcessInstance.getProcessVariables();
  1822.  
  1823.                                         String sLoginAuthor = mProcessVariable.containsKey("sLoginAuthor")
  1824.                                                 ? (String) mProcessVariable.get("sLoginAuthor") : null;
  1825.                                         LOG.info("sLoginAuthor: {}", sLoginAuthor);
  1826.  
  1827.                                         if (sLogin.equalsIgnoreCase(sLoginAuthor)) {
  1828.                                             bAuthor = true;
  1829.                                         }
  1830.                                     }
  1831.                                 }
  1832.                                 for (DocumentStep oDocumentStep : aDocumentSteps) {
  1833.                                     if (oDocumentStep.getsKey_Step().equals(sKeyStep)) {
  1834.                                         oDocumentStepType = oDocumentStep.getoDocumentStepType();
  1835.  
  1836.                                         sSignType = oDocumentStepType.getsSing();
  1837.                                         LOG.info("sSignType: {}", sSignType);
  1838.  
  1839.                                         mParam.put("sBody", sSignType.toLowerCase());
  1840.  
  1841.                                         if (!bAuthor || (bAuthor && sSignType.equalsIgnoreCase("Відредаговано"))) {
  1842.                                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 41L);
  1843.                                         }
  1844.                                     }
  1845.                                 }
  1846.                             }
  1847.                            
  1848.                             if (omRequestBody.get("properties") != null) {
  1849.                                 org.json.simple.JSONObject jsonObj = (org.json.simple.JSONObject) new JSONParser().parse(omRequestBody.toString());
  1850.                                 String nID_Task = null;
  1851.                                 if (jsonObj.containsKey("taskId")) {
  1852.                                     nID_Task = jsonObj.get("taskId").toString();
  1853.                                 } else {
  1854.                                     LOG.info("Variable \"taskId\" not found");
  1855.                                 }
  1856.                                 LOG.info("taskId = " + nID_Task);
  1857.  
  1858.                                 Pattern patternDate = Pattern.compile("(.+?) :: (.+)");
  1859.                                 Matcher matcherDate = patternDate.matcher(sUserTaskName);
  1860.  
  1861.                                 String sStatus = "";
  1862.  
  1863.                                 while (matcherDate.find()) {
  1864.                                     sStatus = matcherDate.group(1);
  1865.                                 }
  1866.                                 LOG.info("sStatus = {}", sStatus);
  1867.                                
  1868.                                 if(sUserTaskName.equals("закрита")){
  1869.                                     sStatus = "документ закрито.";
  1870.                                 }
  1871.                                
  1872.                                 /*boolean isTask = false;
  1873.                                
  1874.                                 if (omRequestBody.get("aProcessSubjectTask") != null) {
  1875.                                     JSONArray aProcessSubjectTask = (JSONArray) omRequestBody.get("aProcessSubjectTask");
  1876.                                     LOG.info("aProcessSubjectTask: {}", aProcessSubjectTask);
  1877.                                     Iterator<JSONObject> i = aProcessSubjectTask.iterator();
  1878.  
  1879.                                     while (i.hasNext()) {
  1880.                                         JSONObject objectJSON = i.next();
  1881.                                         String sID_BP = (String) objectJSON.get("sID_BP");
  1882.                                         LOG.info("sID_BP: {}", sID_BP);
  1883.  
  1884.                                         if (sID_BP.startsWith("_task")) {
  1885.                                             isTask = true;
  1886.                                         }
  1887.                                     }
  1888.                                 }   */
  1889.  
  1890.                                 mParam.put("sName", sStatus.toLowerCase());
  1891.                                 if (!sStatus.isEmpty()) {
  1892.                                     oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 16L);
  1893.                                 }
  1894.                             }
  1895.                         }
  1896.  
  1897.                         if (isSetMessage(oRequest)) {
  1898.                             if (mRequestParam.get("sKeyGroup") != null && !mRequestParam.get("sKeyGroup").isEmpty()){
  1899.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 31L);
  1900.                             }
  1901.                             else{
  1902.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 55L);
  1903.                             }                            
  1904.                         } else if (isEditMessage(oRequest)) {
  1905.                             if (mRequestParam.get("sKeyGroup") != null && !mRequestParam.get("sKeyGroup").isEmpty()){
  1906.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 32L);
  1907.                             }
  1908.                             else{
  1909.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 56L);
  1910.                             }                                                    
  1911.                         } else if (isAddAcceptor(oRequest)) {
  1912.                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 33L);
  1913.                         } else if (isAddViewer(oRequest)) {
  1914.                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 34L);
  1915.                         } else if (isAddVisor(oRequest)) {
  1916.                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 35L);
  1917.                         } else if (isDelegate(oRequest)) {
  1918.                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 36L);
  1919.                         } else if (isRemoveDocumentStepSubject(oRequest)) {
  1920.                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 53L);
  1921.                          } else if (isCancelSign(oRequest)) {
  1922.                             LOG.info("isCancelSign started");
  1923.                             if (mRequestParam.get("sKey_Group") != null) {
  1924.                                 String snID_Process_Activiti = (String)mRequestParam.get("snID_Process_Activiti");
  1925.                                 String sKeyStep = (String)mRequestParam.get("sKey_Step");
  1926.                                 String sLogin = (String) mRequestParam.get("sKey_Group");
  1927.                                 SubjectGroup oSubjectGroup = oSubjectGroupDao.findByExpected("sID_Group_Activiti", sLogin);
  1928.                                 String sFIO = oSubjectGroup.getoSubject().getsLabel();
  1929.                                 String sInitials = usersService.getUserInitials(sFIO);                                
  1930.                                 mParam.put("sName", sInitials);
  1931.  
  1932.                                 if(isReferent){
  1933.                                     mParam.put("sLoginNew", sReferentInitials);
  1934.                                 }
  1935.                                 else {
  1936.                                     mParam.put("sLoginNew", sInitials);
  1937.                                 }
  1938.                                 oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 37L);
  1939.                                 /*for(DocumentStepSubjectRight oDocumentStepSubjectRight : oDocumentStep.aDocumentStepSubjectRight()){
  1940.                                     if(oDocumentStepSubjectRight.getsKey_GroupPostfix().equals(sLogin)
  1941.                                             && !oDocumentStepSubjectRight.getoDocumentStepSubjectSignType().getsID().equals("needlessly"))
  1942.                                     {
  1943.                                       LOG.info("addHistoryEvent was started");  
  1944.                                       oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 37L);  
  1945.                                     }
  1946.                                 }*/
  1947.                             }
  1948.                         }
  1949.                     } else if (omRequestBody.get("properties") != null && isUpdateProcess(oRequest)) {
  1950.                         JSONArray aProperties = (JSONArray) omRequestBody.get("properties");
  1951.                         LOG.info("properties: {}", aProperties);
  1952.                         Iterator<JSONObject> iterator = aProperties.iterator();
  1953.  
  1954.                         while (iterator.hasNext()) {
  1955.                             JSONObject jsonObject = iterator.next();
  1956.  
  1957.                             String sId = (String) jsonObject.get("id");
  1958.  
  1959.                             if (sId.equals("processInstanceId")) {
  1960.                                 sID_Process = String.valueOf(jsonObject.get("value"));
  1961.                                 mParam.put("sID_Process", sID_Process);
  1962.  
  1963.                                 String sID_Order = generalConfig.getOrderId_ByProcess(Long.parseLong(sID_Process));
  1964.                                 mParam.put("sID_Order", sID_Order);
  1965.                                 LOG.info("task sID_Order in interceptor {}", sID_Order);
  1966.  
  1967.                                 aTask = taskService.createTaskQuery().processInstanceId(sID_Process).active().list();
  1968.                                 boolean bProcessClosed = aTask == null || aTask.size() == 0;
  1969.                                 sUserTaskName = bProcessClosed ? "закрита" : aTask.get(0).getName();
  1970.                                 LOG.info("task sUserTaskName in interceptor {}", sUserTaskName);
  1971.  
  1972.                                 JSONArray aProcessSubjectTask = (JSONArray) omRequestBody.get("aProcessSubjectTask");
  1973.                                 LOG.info("aProcessSubjectTask: {}", aProcessSubjectTask);
  1974.                                 Iterator<JSONObject> i = aProcessSubjectTask.iterator();
  1975.  
  1976.                                 while (i.hasNext()) {
  1977.                                     JSONObject objectJSON = i.next();
  1978.                                     String sActionType = (String) objectJSON.get("sActionType");
  1979.                                     //LOG.info("sActionType: {}", sActionType);
  1980.  
  1981.                                     if (sActionType.equals("set")) {
  1982.                                         JSONArray aProcessSubject = (JSONArray) objectJSON.get("aProcessSubject");
  1983.                                         Iterator<JSONObject> j = aProcessSubject.iterator();
  1984.                                         if (j.hasNext()) {
  1985.                                             JSONObject ObjectJSON = j.next();
  1986.                                             String sDatePlan = (String) ObjectJSON.get("sDatePlan");
  1987.                                             //LOG.info("sDatePlan: {}", sDatePlan);
  1988.                                             mParam.put("newData", sDatePlan);
  1989.                                             oActionEventHistoryService.addHistoryEvent(sID_Order, sUserTaskName, mParam, 40L);
  1990.                                         }
  1991.                                     }
  1992.                                 }
  1993.                             }
  1994.                         }                        
  1995.                     }
  1996.                 }
  1997.             }
  1998.         } catch (Exception ex) {
  1999.             LOG.info("Error during task processing in interceptor: {}", ex.getMessage());
  2000.         }
  2001.     }
  2002.    
  2003.     private void processIpayHistory(HttpServletRequest oRequest){
  2004.         try{
  2005.             Map<String, String> mRequestParam = new HashMap<>();
  2006.             Enumeration<String> paramsName = oRequest.getParameterNames();
  2007.  
  2008.             while (paramsName.hasMoreElements()) {
  2009.                 String sKey = (String) paramsName.nextElement();
  2010.                 mRequestParam.put(sKey, oRequest.getParameter(sKey));
  2011.             }
  2012.             //LOG.info("mRequestParam in processIpayHistory {}", mRequestParam);
  2013.             String sProcessInstanceId = mRequestParam.get("processInstanceId");
  2014.             if(sProcessInstanceId != null){
  2015.                 List<HistoricVariableInstance> aHistoricVariableInstance = historyService.createHistoricVariableInstanceQuery()
  2016.                                             .processInstanceId(sProcessInstanceId).list();
  2017.                
  2018.                 HistoricVariableInstance oHistoricVariableInstance_asPayResult = null;
  2019.                 HistoricVariableInstance oHistoricVariableInstance_bHistoryIpayMessage = null;
  2020.                 HistoricVariableInstance oHistoricVariableInstance_bPayResult = null;
  2021.                 HistoricVariableInstance oHistoricVariableInstance_sID_Pay_MasterPass = null;
  2022.  
  2023.                 for(HistoricVariableInstance oHistoricVariableInstance : aHistoricVariableInstance){
  2024.                    
  2025.                     if(oHistoricVariableInstance.getVariableName().equals("asPayResult")){
  2026.                         oHistoricVariableInstance_asPayResult = oHistoricVariableInstance;
  2027.                     }
  2028.                    
  2029.                     if(oHistoricVariableInstance.getVariableName().equals("bHistoryIpayMessage")){
  2030.                         oHistoricVariableInstance_bHistoryIpayMessage = oHistoricVariableInstance;
  2031.                     }
  2032.                    
  2033.                     if(oHistoricVariableInstance.getVariableName().equals("bPayResult")){
  2034.                         oHistoricVariableInstance_bPayResult = oHistoricVariableInstance;
  2035.                     }
  2036.                    
  2037.                     if(oHistoricVariableInstance.getVariableName().equals("sID_Pay_MasterPass")){
  2038.                         oHistoricVariableInstance_sID_Pay_MasterPass = oHistoricVariableInstance;
  2039.                     }
  2040.                 }
  2041.                
  2042.                 if(oHistoricVariableInstance_asPayResult != null && oHistoricVariableInstance_bPayResult != null && oHistoricVariableInstance_sID_Pay_MasterPass != null
  2043.                         && oHistoricVariableInstance_bHistoryIpayMessage == null)
  2044.                 {
  2045.                      
  2046.                     if(oHistoricVariableInstance_asPayResult.getValue() != null){
  2047.                        
  2048.                         org.activiti.engine.impl.util.json.JSONObject oResponseParams =
  2049.                                 new org.activiti.engine.impl.util.json.JSONObject((String)oHistoricVariableInstance_asPayResult.getValue());
  2050.                        
  2051.                         org.activiti.engine.impl.util.json.JSONObject oRequestBody =
  2052.                                 new org.activiti.engine.impl.util.json.JSONObject((String)oHistoricVariableInstance_sID_Pay_MasterPass.getValue());
  2053.                        
  2054.                         String pmt_status = (String)((org.activiti.engine.impl.util.json.JSONObject)oResponseParams.get("response")).get("pmt_status");
  2055.                         String amount = ((String)((org.activiti.engine.impl.util.json.JSONObject)oResponseParams.get("response")).get("amount"));
  2056.                        
  2057.                         if(amount != null){
  2058.                             Map<String, String> mParam = new HashMap<>();
  2059.                            
  2060.                             Double amount_fix = (double)Integer.parseInt(amount)/100;
  2061.                             DecimalFormat decim = new DecimalFormat("0.00");
  2062.                             mParam.put("sIpay_Amount", decim.format(amount_fix));
  2063.                            
  2064.                             mParam.put("sID_Order", generalConfig.getOrderId_ByProcess(generalConfig.getSelfServerId(), Long.parseLong(sProcessInstanceId)));
  2065.                             mParam.put("nID_StatusType", HistoryEvent_Service_StatusType.CREATED.getnID().toString());
  2066.                            
  2067.                             String user_id = null;
  2068.                            
  2069.                             if(oRequestBody.get("user_id") instanceof Integer){
  2070.                                 user_id = ((Integer)oRequestBody.get("user_id")).toString();
  2071.                             }else if(oRequestBody.get("user_id") instanceof String){
  2072.                                 user_id = ((String)oRequestBody.get("user_id"));
  2073.                             }
  2074.                            
  2075.                             mParam.put("nID_Subject", user_id);
  2076.                            
  2077.                             mParam.put("sUserTaskName", "");
  2078.  
  2079.                             if(pmt_status.equals("5")){
  2080.                                 mParam.put("nID_HistoryEventType", "46");
  2081.                                 oActionEventHistoryService.doRemoteRequest("/wf/service/history/document/event/addHistoryEvent", mParam);
  2082.                                 runtimeService.setVariable(sProcessInstanceId, "bHistoryIpayMessage", "true");
  2083.                             }
  2084.                             if(pmt_status.equals("9") || pmt_status.equals("4")){
  2085.                                 mParam.put("nID_HistoryEventType", "47");
  2086.                                 oActionEventHistoryService.doRemoteRequest("/wf/service/history/document/event/addHistoryEvent", mParam);
  2087.                                 runtimeService.setVariable(sProcessInstanceId, "bHistoryIpayMessage", "true");
  2088.                             }
  2089.                         }
  2090.                     }
  2091.                 }
  2092.             }
  2093.         }catch (Exception ex){
  2094.             LOG.info("Error during processIpayHistory {}", ex);
  2095.         }
  2096.     }
  2097.  
  2098.     private boolean isSetMessage(HttpServletRequest oRequest) {
  2099.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(SET_CHAT_MESSAGE) > 0
  2100.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim()));
  2101.     }
  2102.    
  2103.     private boolean isEditMessage(HttpServletRequest oRequest) {
  2104.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(EDIT_CHAT_MESSAGE) > 0
  2105.                 && PUT.equalsIgnoreCase(oRequest.getMethod().trim()));
  2106.     }
  2107.    
  2108.     private boolean isDeleteMessage(HttpServletRequest oRequest) {
  2109.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(DELETE_CHAT_MESSAGE) > 0
  2110.                 && DELETE.equalsIgnoreCase(oRequest.getMethod().trim()));
  2111.     }      
  2112.    
  2113.     private boolean isAddAcceptor(HttpServletRequest oRequest) {
  2114.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(ADD_ACCEPTOR) > 0
  2115.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2116.     }
  2117.    
  2118.     private boolean isAddViewer(HttpServletRequest oRequest) {
  2119.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(ADD_VIEWER) > 0
  2120.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2121.     }
  2122.    
  2123.     private boolean isAddVisor(HttpServletRequest oRequest) {
  2124.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(ADD_VISOR) > 0
  2125.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2126.     }
  2127.    
  2128.     private boolean isDelegate(HttpServletRequest oRequest) {
  2129.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(DELEGATE) > 0
  2130.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2131.     }
  2132.     private boolean isCancelSign(HttpServletRequest oRequest) {
  2133.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(CANCEL_SIGN) > 0
  2134.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2135.     }            
  2136.    
  2137.     private boolean isAutentification(HttpServletRequest oRequest) {
  2138.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(URI_DASHBOARD_ENTER) > 0
  2139.                 && POST.equalsIgnoreCase(oRequest.getMethod().trim()));
  2140.     }
  2141.    
  2142.     private boolean isSetUrgent(HttpServletRequest oRequest) {
  2143.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(URI_URGENT_DOCUMENT) > 0
  2144.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2145.     }
  2146.  
  2147.     private boolean isRemoveDocumentStepSubject(HttpServletRequest oRequest) {
  2148.         return (oRequest != null && oRequest.getRequestURL().toString().indexOf(SERVICE_DOCUMENT_REMOVE_DOCUMENT_STEP_SUBJECT) > 0
  2149.                 && GET.equalsIgnoreCase(oRequest.getMethod().trim()));
  2150.     }
  2151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement