ConfigurazioneHandlersRispostaList.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.web.ctrlstat.servlet.config;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.Configurazione;
  33. import org.openspcoop2.core.config.ConfigurazioneGeneraleHandler;
  34. import org.openspcoop2.core.config.ConfigurazioneHandler;
  35. import org.openspcoop2.core.config.ConfigurazioneMessageHandlers;
  36. import org.openspcoop2.core.config.ConfigurazionePortaHandler;
  37. import org.openspcoop2.core.config.PortaApplicativa;
  38. import org.openspcoop2.core.config.PortaDelegata;
  39. import org.openspcoop2.core.config.constants.FaseMessageHandler;
  40. import org.openspcoop2.core.constants.TipoPdD;
  41. import org.openspcoop2.core.plugins.utils.handlers.ConfigurazioneHandlerBean;
  42. import org.openspcoop2.message.constants.ServiceBinding;
  43. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  44. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  45. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  46. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  47. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCore;
  48. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCore;
  49. import org.openspcoop2.web.lib.mvc.Costanti;
  50. import org.openspcoop2.web.lib.mvc.ForwardParams;
  51. import org.openspcoop2.web.lib.mvc.GeneralData;
  52. import org.openspcoop2.web.lib.mvc.MessageType;
  53. import org.openspcoop2.web.lib.mvc.PageData;
  54. import org.openspcoop2.web.lib.mvc.ServletUtils;

  55. /**
  56.  * ConfigurazioneHandlersRispostaList
  57.  *
  58.  * @author Giuliano Pintori (pintori@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  *
  62.  */
  63. public final class ConfigurazioneHandlersRispostaList extends Action {

  64.     @Override
  65.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  66.         HttpSession session = request.getSession(true);

  67.         // Inizializzo PageData
  68.         PageData pd = new PageData();

  69.         GeneralHelper generalHelper = new GeneralHelper(session);
  70.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  71.         // Inizializzo GeneralData
  72.         GeneralData gd = generalHelper.initGeneralData(request);

  73.         try {
  74.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
  75.            
  76.             String ruoloPortaParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_RUOLO_PORTA);
  77.             TipoPdD ruoloPorta = null;
  78.             if(ruoloPortaParam!=null) {
  79.                 ruoloPorta = TipoPdD.toTipoPdD(ruoloPortaParam);
  80.             }
  81.             String idPortaS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_ID_PORTA);
  82.             Long idPorta = null;
  83.             if(StringUtils.isNotBlank(idPortaS)) {
  84.                 idPorta = Long.parseLong(idPortaS);
  85.             }
  86.             ServiceBinding serviceBinding = null;
  87.             String serviceBindingParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_SERVICE_BINDING);
  88.             if(serviceBindingParam!=null && !"".equals(serviceBindingParam)) {
  89.                 serviceBinding = ServiceBinding.valueOf(serviceBindingParam);
  90.             }
  91.            
  92.             String idTab = confHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  93.             if(!confHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  94.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  95.             }
  96.             String fase = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_FASE);
  97.             String cambiaPosizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_POSIZIONE);
  98.             String idHandlerS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_ID_HANDLER);

  99.             FaseMessageHandler faseMH = FaseMessageHandler.toEnumConstant(fase);
  100.            
  101.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  102.            
  103.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  104.                
  105.                 Long idHandler = Long.parseLong(idHandlerS);
  106.                
  107.                 List<Object> oggettiDaAggiornare = new ArrayList<>();
  108.                 List<ConfigurazioneHandler> listaDaAggiornare = null;
  109.                 if(ruoloPorta !=null) {
  110.                     if(ruoloPorta.equals(TipoPdD.DELEGATA)) {
  111.                         PorteDelegateCore porteDelegateCore = new PorteDelegateCore(confCore);
  112.                         PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idPorta);
  113.                        
  114.                         if(portaDelegata.getConfigurazioneHandler() == null)
  115.                             portaDelegata.setConfigurazioneHandler(new ConfigurazionePortaHandler());
  116.                        
  117.                         if(portaDelegata.getConfigurazioneHandler().getResponse() == null)
  118.                             portaDelegata.getConfigurazioneHandler().setResponse(new ConfigurazioneMessageHandlers());
  119.                        
  120.                        
  121.                         switch (faseMH) {
  122.                         case IN:
  123.                             listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getResponse().getInList();
  124.                             break;
  125.                         case IN_PROTOCOL_INFO:
  126.                             listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getResponse().getInProtocolInfoList();
  127.                             break;
  128.                         case OUT:
  129.                             listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getResponse().getOutList();
  130.                             break;
  131.                         case POST_OUT:
  132.                             listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getResponse().getPostOutList();
  133.                             break;
  134.                         case PRE_IN:
  135.                             listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getResponse().getPreInList();
  136.                             break;
  137.                         }
  138.                         oggettiDaAggiornare.add(portaDelegata);
  139.                     }
  140.                     else if(ruoloPorta.equals(TipoPdD.APPLICATIVA)) {
  141.                         PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore(confCore);
  142.                         PortaApplicativa portaApplicativa = porteApplicativeCore.getPortaApplicativa(idPorta);
  143.                        
  144.                         if(portaApplicativa.getConfigurazioneHandler() == null)
  145.                             portaApplicativa.setConfigurazioneHandler(new ConfigurazionePortaHandler());
  146.                        
  147.                         if(portaApplicativa.getConfigurazioneHandler().getResponse() == null)
  148.                             portaApplicativa.getConfigurazioneHandler().setResponse(new ConfigurazioneMessageHandlers());
  149.                        
  150.                         switch (faseMH) {
  151.                         case IN:
  152.                             listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getResponse().getInList();
  153.                             break;
  154.                         case IN_PROTOCOL_INFO:
  155.                             listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getResponse().getInProtocolInfoList();
  156.                             break;
  157.                         case OUT:
  158.                             listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getResponse().getOutList();
  159.                             break;
  160.                         case POST_OUT:
  161.                             listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getResponse().getPostOutList();
  162.                             break;
  163.                         case PRE_IN:
  164.                             listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getResponse().getPreInList();
  165.                             break;
  166.                         }  
  167.                         oggettiDaAggiornare.add(portaApplicativa);
  168.                     }
  169.                 } else {
  170.                     Configurazione configurazione = confCore.getConfigurazioneGenerale();
  171.                    
  172.                     if(configurazione.getConfigurazioneHandler() == null)
  173.                         configurazione.setConfigurazioneHandler(new ConfigurazioneGeneraleHandler());
  174.                    
  175.                     if(configurazione.getConfigurazioneHandler().getResponse() == null)
  176.                         configurazione.getConfigurazioneHandler().setResponse(new ConfigurazioneMessageHandlers());
  177.                    
  178.                     switch (faseMH) {
  179.                     case IN:
  180.                         listaDaAggiornare = configurazione.getConfigurazioneHandler().getResponse().getInList();
  181.                         break;
  182.                     case IN_PROTOCOL_INFO:
  183.                         listaDaAggiornare = configurazione.getConfigurazioneHandler().getResponse().getInProtocolInfoList();
  184.                         break;
  185.                     case OUT:
  186.                         listaDaAggiornare = configurazione.getConfigurazioneHandler().getResponse().getOutList();
  187.                         break;
  188.                     case POST_OUT:
  189.                         listaDaAggiornare = configurazione.getConfigurazioneHandler().getResponse().getPostOutList();
  190.                         break;
  191.                     case PRE_IN:
  192.                         listaDaAggiornare = configurazione.getConfigurazioneHandler().getResponse().getPreInList();
  193.                         break;
  194.                     }
  195.                     oggettiDaAggiornare.add(configurazione);
  196.                 }
  197.                
  198.                 if(listaDaAggiornare!=null) {
  199.                     for(int j = 0; j < listaDaAggiornare.size() ; j++) {
  200.                         ConfigurazioneHandler handlerToMove = null;
  201.                         ConfigurazioneHandler handlerToCheck = listaDaAggiornare.get(j);
  202.                         if(handlerToCheck.getId().equals(idHandler)) {
  203.                             handlerToMove = handlerToCheck;
  204.                            
  205.                             int posizioneAttuale = handlerToMove.getPosizione();
  206.                            
  207.                             ConfigurazioneHandler handlerToSwitch = null;
  208.                             if(cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU)) {
  209.                                 handlerToSwitch = listaDaAggiornare.get(j-1);
  210.                             } else {
  211.                                 handlerToSwitch = listaDaAggiornare.get(j+1);
  212.                             }
  213.                             int posizioneNuova = handlerToSwitch.getPosizione();
  214.                            
  215.                             handlerToMove.setPosizione(posizioneNuova);
  216.                             handlerToSwitch.setPosizione(posizioneAttuale);
  217.                             break;
  218.                         }
  219.                     }
  220.                 }

  221.                 confCore.performUpdateOperation(userLogin, confHelper.smista(), oggettiDaAggiornare.toArray(new Object[oggettiDaAggiornare.size()]));
  222.                 if(ConfigurazioneCostanti.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_HANDLER) {
  223.                     pd.setMessage(ConfigurazioneCostanti.MESSAGGIO_CONFERMA_HANDLER_SPOSTATO_CORRETTAMENTE, MessageType.INFO);
  224.                 }
  225.                 else {
  226.                     if(ruoloPorta == null) {
  227.                         pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_MESSAGE_HANDLERS_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  228.                     }
  229.                 }
  230.             }


  231.             // Preparo il menu
  232.             confHelper.makeMenu();
  233.            
  234.             // Preparo la lista
  235.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  236.             int idLista = Liste.CONFIGURAZIONE_HANDLERS_RISPOSTA;

  237.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);

  238.             List<ConfigurazioneHandlerBean> lista = confCore.handlersRispostaList(ricerca, fase, ruoloPorta, idPorta);
  239.            
  240.             confHelper.prepareHandlersRispostaList(ricerca, lista, ruoloPorta, idPortaS, serviceBinding, fase);
  241.            
  242.             // salvo l'oggetto ricerca nella sessione
  243.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  244.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  245.             // Forward control to the specified success URI
  246.             return ServletUtils.getStrutsForward (mapping,
  247.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_RISPOSTA,
  248.                     ForwardParams.LIST());
  249.         } catch (Exception e) {
  250.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  251.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_RISPOSTA, ForwardParams.LIST());
  252.         }
  253.     }
  254. }