ConfigurazioneProxyPassRegolaList.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.List;

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

  25. import org.apache.commons.lang.StringUtils;
  26. import org.apache.struts.action.Action;
  27. import org.apache.struts.action.ActionForm;
  28. import org.apache.struts.action.ActionForward;
  29. import org.apache.struts.action.ActionMapping;
  30. import org.openspcoop2.core.commons.Liste;
  31. import org.openspcoop2.core.config.Configurazione;
  32. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazione;
  33. import org.openspcoop2.core.config.ConfigurazioneUrlInvocazioneRegola;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.MessageType;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * ConfigurazioneProxyPassRegolaList
  45.  *
  46.  * @author Giuliano Pintori (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazioneProxyPassRegolaList extends Action {

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

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

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         GeneralHelper generalHelper = new GeneralHelper(session);
  58.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  59.         // Inizializzo GeneralData
  60.         GeneralData gd = generalHelper.initGeneralData(request);

  61.         try {
  62.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  63.             String cambiaPosizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PROXY_PASS_REGOLA_POSIZIONE);
  64.             String idRegolaS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PROXY_PASS_ID_REGOLA);
  65.            
  66.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  67.             // Preparo il menu
  68.             confHelper.makeMenu();
  69.            
  70.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  71.                
  72.                 Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  73.                 ConfigurazioneUrlInvocazione urlInvocazione = configurazioneGenerale.getUrlInvocazione();
  74.                
  75.                 if(urlInvocazione != null) {
  76.                     long idRegola = Long.parseLong(idRegolaS);
  77.                     ConfigurazioneUrlInvocazioneRegola regolaToMove = null;
  78.                     for (ConfigurazioneUrlInvocazioneRegola reg : urlInvocazione.getRegolaList()) {
  79.                         if(reg.getId().longValue() == idRegola) {
  80.                             regolaToMove = reg;
  81.                             break;
  82.                         }
  83.                     }
  84.                     if(regolaToMove==null) {
  85.                         throw new Exception("Regola da muovere non trovata");
  86.                     }
  87.                    
  88.                     int posizioneAttuale = regolaToMove.getPosizione();
  89.                     int posizioneNuova = cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU) ? (posizioneAttuale - 1) : (posizioneAttuale + 1);
  90.                    
  91.                     ConfigurazioneUrlInvocazioneRegola regolaToSwitch = null;
  92.                     for (ConfigurazioneUrlInvocazioneRegola reg : urlInvocazione.getRegolaList()) {
  93.                         if(reg.getPosizione() == posizioneNuova) {
  94.                             regolaToSwitch = reg;
  95.                             break;
  96.                         }
  97.                     }
  98.                     if(regolaToSwitch==null) {
  99.                         throw new Exception("Regola con cui fare lo switch non trovata");
  100.                     }
  101.                    
  102.                     regolaToMove.setPosizione(posizioneNuova);
  103.                     regolaToSwitch.setPosizione(posizioneAttuale);
  104.                    
  105.                     confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);
  106.                     if(CostantiControlStation.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_REGOLA_PROXY_PASS)
  107.                         pd.setMessage(CostantiControlStation.MESSAGGIO_CONFERMA_REGOLA_PROXY_PASS_SPOSTATA_CORRETTAMENTE, MessageType.INFO);
  108.                 }
  109.             }

  110.             // Preparo la lista
  111.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  112.             int idLista = Liste.CONFIGURAZIONE_PROXY_PASS_REGOLA;

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

  114.             List<ConfigurazioneUrlInvocazioneRegola> lista = confCore.proxyPassConfigurazioneRegolaList(ricerca);
  115.            
  116.             confHelper.prepareProxyPassConfigurazioneRegolaList(ricerca, lista);
  117.            
  118.             // salvo l'oggetto ricerca nella sessione
  119.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  120.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  121.             // Forward control to the specified success URI
  122.             return ServletUtils.getStrutsForward (mapping,
  123.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PROXY_PASS_REGOLA,
  124.                     ForwardParams.LIST());
  125.         } catch (Exception e) {
  126.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  127.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PROXY_PASS_REGOLA, ForwardParams.LIST());
  128.         }
  129.     }
  130. }