ConfigurazioneProxyPassRegolaDel.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.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.core.Utilities;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * ConfigurazioneProxyPassRegolaDel
  45.  *
  46.  * @author Giuliano Pintori (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazioneProxyPassRegolaDel 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.         // Inizializzo GeneralData
  59.         GeneralData gd = generalHelper.initGeneralData(request);

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

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

  63.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  64.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  65.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  66.             Long id = null;

  67.             // Prendo l'accesso registro
  68.             Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  69.             ConfigurazioneUrlInvocazione urlInvocazione = configurazioneGenerale.getUrlInvocazione();
  70.             List<ConfigurazioneUrlInvocazioneRegola> regoleDaEliminare = new ArrayList<ConfigurazioneUrlInvocazioneRegola>();
  71.            
  72.             for (int i = 0; i < idsToRemove.size(); i++) {

  73.                 id = Long.parseLong(idsToRemove.get(i));

  74.                 for (int j = 0; j < urlInvocazione.sizeRegolaList(); j++) {
  75.                     ConfigurazioneUrlInvocazioneRegola regola = urlInvocazione.getRegola(j);
  76.                     if (regola.getId().longValue() == id.longValue()) {
  77.                         regoleDaEliminare.add(urlInvocazione.removeRegola(j));
  78.                     }
  79.                 }
  80.             }

  81.             //confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);
  82.             if(!regoleDaEliminare.isEmpty()) {
  83.                 confCore.performDeleteOperation(userLogin, confHelper.smista(), regoleDaEliminare.toArray(new Object[1]) );
  84.             }

  85.             // Preparo il menu
  86.             confHelper.makeMenu();

  87.            
  88.             // Preparo la lista
  89.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  90.             int idLista = Liste.CONFIGURAZIONE_PROXY_PASS_REGOLA;

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

  92.             List<ConfigurazioneUrlInvocazioneRegola> lista = confCore.proxyPassConfigurazioneRegolaList(ricerca);
  93.            
  94.             confHelper.prepareProxyPassConfigurazioneRegolaList(ricerca, lista);
  95.                        
  96.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  97.            
  98.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  99.             // Forward control to the specified success URI
  100.             return ServletUtils.getStrutsForward (mapping,
  101.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PROXY_PASS_REGOLA,
  102.                     ForwardParams.DEL());
  103.         } catch (Exception e) {
  104.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  105.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PROXY_PASS_REGOLA, ForwardParams.DEL());
  106.         }
  107.     }
  108. }