PorteApplicativeTrasformazioniRichiestaHeaderDel.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.pa;

  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.PortaApplicativa;
  32. import org.openspcoop2.core.config.TrasformazioneRegola;
  33. import org.openspcoop2.core.config.TrasformazioneRegolaParametro;
  34. import org.openspcoop2.core.config.Trasformazioni;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.core.Utilities;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.Costanti;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;

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

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  62.         try {
  63.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  64.            
  65.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  66.             // String idsogg = porteApplicativeHelper.getParameter("idsogg");
  67.             // int soggInt = Integer.parseInt(idsogg);
  68.             String nomePorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  69.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  70.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  71.            
  72.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  73.             // Preparo il menu
  74.             porteApplicativeHelper.makeMenu();

  75.             String objToRemove = porteApplicativeHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  76.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  77.             Long idParametro = null;

  78.             PortaApplicativa portaApplicativa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta));
  79.             Trasformazioni trasformazioni = portaApplicativa.getTrasformazioni();
  80.             TrasformazioneRegola regola = null;
  81.             for (int i = 0; i < idsToRemove.size(); i++) {

  82.                 idParametro = Long.parseLong(idsToRemove.get(i));

  83.                
  84.                 for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  85.                     TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  86.                     if (regolaTmp.getId().longValue() == idTrasformazione) {
  87.                         regola = regolaTmp;
  88.                         break;
  89.                     }
  90.                 }
  91.                
  92.                 for (int j = 0; j < regola.getRichiesta().sizeHeaderList(); j++) {
  93.                     TrasformazioneRegolaParametro paramteroTmp = regola.getRichiesta().getHeader(j);
  94.                     if (paramteroTmp.getId().longValue() == idParametro) {
  95.                         regola.getRichiesta().removeHeader(j);
  96.                         break;
  97.                     }
  98.                 }
  99.             }

  100.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), portaApplicativa);
  101.            
  102.             // ricaricare id trasformazione
  103.             portaApplicativa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta));

  104.             TrasformazioneRegola trasformazioneAggiornata = porteApplicativeCore.getTrasformazione(Long.parseLong(idPorta), regola.getNome());

  105.             // Preparo il menu
  106.             porteApplicativeHelper.makeMenu();
  107.            
  108.             // Preparo la lista
  109.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  110.            
  111.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER;
  112.            
  113.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  114.            
  115.             List<TrasformazioneRegolaParametro> lista = porteApplicativeCore.porteAppTrasformazioniRichiestaHeaderList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  116.            
  117.             porteApplicativeHelper.preparePorteAppTrasformazioniRichiestaHeaderList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  118.            
  119.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  120.             // Forward control to the specified success URI
  121.             return ServletUtils.getStrutsForward (mapping,
  122.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER,
  123.                     ForwardParams.DEL());
  124.         } catch (Exception e) {
  125.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  126.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.DEL());
  127.         }
  128.     }

  129. }