ConfigurazioneHandlersRichiestaDel.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.core.Utilities;
  46. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  47. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  48. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCore;
  49. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCore;
  50. import org.openspcoop2.web.lib.mvc.Costanti;
  51. import org.openspcoop2.web.lib.mvc.ForwardParams;
  52. import org.openspcoop2.web.lib.mvc.GeneralData;
  53. import org.openspcoop2.web.lib.mvc.PageData;
  54. import org.openspcoop2.web.lib.mvc.ServletUtils;

  55. /**
  56.  * ConfigurazioneHandlersRichiestaDel
  57.  *
  58.  * @author Giuliano Pintori (pintori@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  *
  62.  */
  63. public final class ConfigurazioneHandlersRichiestaDel 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.         // Inizializzo GeneralData
  71.         GeneralData gd = generalHelper.initGeneralData(request);

  72.         String userLogin = ServletUtils.getUserLoginFromSession(session);  

  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.             FaseMessageHandler faseMH = FaseMessageHandler.toEnumConstant(fase);

  98.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  99.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  100.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  101.             List<Object> oggettiDaAggiornare = new ArrayList<>();
  102.             List<ConfigurazioneHandler> listaDaAggiornare = null;
  103.             if(ruoloPorta !=null) {
  104.                 if(ruoloPorta.equals(TipoPdD.DELEGATA)) {
  105.                     PorteDelegateCore porteDelegateCore = new PorteDelegateCore(confCore);
  106.                     PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idPorta);
  107.                    
  108.                     if(portaDelegata.getConfigurazioneHandler() == null)
  109.                         portaDelegata.setConfigurazioneHandler(new ConfigurazionePortaHandler());
  110.                    
  111.                     if(portaDelegata.getConfigurazioneHandler().getRequest() == null)
  112.                         portaDelegata.getConfigurazioneHandler().setRequest(new ConfigurazioneMessageHandlers());
  113.                    
  114.                     switch (faseMH) {
  115.                     case IN:
  116.                         listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getRequest().getInList();
  117.                         break;
  118.                     case IN_PROTOCOL_INFO:
  119.                         listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getRequest().getInProtocolInfoList();
  120.                         break;
  121.                     case OUT:
  122.                         listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getRequest().getOutList();
  123.                         break;
  124.                     case POST_OUT:
  125.                         listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getRequest().getPostOutList();
  126.                         break;
  127.                     case PRE_IN:
  128.                         listaDaAggiornare = portaDelegata.getConfigurazioneHandler().getRequest().getPreInList();
  129.                         break;
  130.                     }
  131.                     oggettiDaAggiornare.add(portaDelegata);
  132.                 }
  133.                 else if(ruoloPorta.equals(TipoPdD.APPLICATIVA)) {
  134.                     PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore(confCore);
  135.                     PortaApplicativa portaApplicativa = porteApplicativeCore.getPortaApplicativa(idPorta);
  136.                    
  137.                     if(portaApplicativa.getConfigurazioneHandler() == null)
  138.                         portaApplicativa.setConfigurazioneHandler(new ConfigurazionePortaHandler());
  139.                    
  140.                     if(portaApplicativa.getConfigurazioneHandler().getRequest() == null)
  141.                         portaApplicativa.getConfigurazioneHandler().setRequest(new ConfigurazioneMessageHandlers());
  142.                    
  143.                     switch (faseMH) {
  144.                     case IN:
  145.                         listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getRequest().getInList();
  146.                         break;
  147.                     case IN_PROTOCOL_INFO:
  148.                         listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getRequest().getInProtocolInfoList();
  149.                         break;
  150.                     case OUT:
  151.                         listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getRequest().getOutList();
  152.                         break;
  153.                     case POST_OUT:
  154.                         listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getRequest().getPostOutList();
  155.                         break;
  156.                     case PRE_IN:
  157.                         listaDaAggiornare = portaApplicativa.getConfigurazioneHandler().getRequest().getPreInList();
  158.                         break;
  159.                     }  
  160.                     oggettiDaAggiornare.add(portaApplicativa);
  161.                 }
  162.             } else {
  163.                 Configurazione configurazione = confCore.getConfigurazioneGenerale();
  164.                
  165.                 if(configurazione.getConfigurazioneHandler() == null)
  166.                     configurazione.setConfigurazioneHandler(new ConfigurazioneGeneraleHandler());
  167.                
  168.                 if(configurazione.getConfigurazioneHandler().getRequest() == null)
  169.                     configurazione.getConfigurazioneHandler().setRequest(new ConfigurazioneMessageHandlers());
  170.                
  171.                 switch (faseMH) {
  172.                 case IN:
  173.                     listaDaAggiornare = configurazione.getConfigurazioneHandler().getRequest().getInList();
  174.                     break;
  175.                 case IN_PROTOCOL_INFO:
  176.                     listaDaAggiornare = configurazione.getConfigurazioneHandler().getRequest().getInProtocolInfoList();
  177.                     break;
  178.                 case OUT:
  179.                     listaDaAggiornare = configurazione.getConfigurazioneHandler().getRequest().getOutList();
  180.                     break;
  181.                 case POST_OUT:
  182.                     listaDaAggiornare = configurazione.getConfigurazioneHandler().getRequest().getPostOutList();
  183.                     break;
  184.                 case PRE_IN:
  185.                     listaDaAggiornare = configurazione.getConfigurazioneHandler().getRequest().getPreInList();
  186.                     break;
  187.                 }
  188.                 oggettiDaAggiornare.add(configurazione);
  189.             }
  190.            
  191.             List<String> idRemove = new ArrayList<>();
  192.             if(listaDaAggiornare!=null) {
  193.                 for(int j = listaDaAggiornare.size() -1; j >= 0 ; j--) {
  194.                     for (int i = 0; i < idsToRemove.size(); i++) {
  195.                         if(idsToRemove.get(i).equals(listaDaAggiornare.get(j).getTipo())) {
  196.                             idRemove.add(idsToRemove.get(i));
  197.                         }
  198.                     }
  199.                 }
  200.             }
  201.             if(!idRemove.isEmpty()) {
  202.                
  203.                 if(listaDaAggiornare==null) {
  204.                     throw new Exception("Lista da aggiornare non trovata");
  205.                 }
  206.                
  207.                 for (String id : idRemove) {
  208.                     for (int i = 0; i < listaDaAggiornare.size(); i++) {
  209.                         if(id.equals(listaDaAggiornare.get(i).getTipo())) {
  210.                             listaDaAggiornare.remove(i);
  211.                             break;
  212.                         }
  213.                     }
  214.                 }
  215.             }
  216.            
  217.             // update sul db
  218.             confCore.performUpdateOperation(userLogin, confHelper.smista(), oggettiDaAggiornare.toArray(new Object[oggettiDaAggiornare.size()]));
  219.             // Preparo il menu
  220.             confHelper.makeMenu();
  221.            
  222.             // Preparo la lista
  223.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  224.             int idLista = Liste.CONFIGURAZIONE_HANDLERS_RICHIESTA;

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

  226.             List<ConfigurazioneHandlerBean> lista = confCore.handlersRichiestaList(ricerca, fase, ruoloPorta, idPorta);
  227.            
  228.             confHelper.prepareHandlersRichiestaList(ricerca, lista, ruoloPorta, idPortaS, serviceBinding, fase);
  229.                        
  230.             if(ruoloPorta == null) {
  231.                 pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_MESSAGE_HANDLERS_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  232.             }
  233.            
  234.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  235.             // Forward control to the specified success URI
  236.             return ServletUtils.getStrutsForward (mapping,
  237.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_RICHIESTA,
  238.                     ForwardParams.DEL());
  239.         } catch (Exception e) {
  240.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  241.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_RICHIESTA, ForwardParams.DEL());
  242.         }
  243.     }
  244. }