PorteApplicativeTrasformazioniRichiestaHeaderChange.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.core.config.constants.TrasformazioneIdentificazioneRisorsaFallita;
  36. import org.openspcoop2.core.config.constants.TrasformazioneRegolaParametroTipoAzione;
  37. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  39. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  40. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  41. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  42. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  43. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  44. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  45. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  46. import org.openspcoop2.web.lib.mvc.DataElement;
  47. import org.openspcoop2.web.lib.mvc.ForwardParams;
  48. import org.openspcoop2.web.lib.mvc.GeneralData;
  49. import org.openspcoop2.web.lib.mvc.PageData;
  50. import org.openspcoop2.web.lib.mvc.Parameter;
  51. import org.openspcoop2.web.lib.mvc.ServletUtils;
  52. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

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

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

  65.         // Inizializzo PageData
  66.         PageData pd = new PageData();

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

  70.         // Inizializzo GeneralData
  71.         GeneralData gd = generalHelper.initGeneralData(request);
  72.        
  73.         try {
  74.            
  75.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  76.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  77.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  78.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  79.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  80.             int idInt = Integer.parseInt(idPorta);
  81.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  82.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  83.             if(idAsps == null)
  84.                 idAsps = "";
  85.            
  86.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  87.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  88.            
  89.             String idTrasformazioneRichiestaHeaderS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE_RICHIESTA_HEADER);
  90.             long idTrasformazioneRichiestaHeader = Long.parseLong(idTrasformazioneRichiestaHeaderS);
  91.            
  92.             String tipo = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_TIPO);
  93.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_NOME);
  94.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_VALORE);
  95.             String identificazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_IDENTIFICAZIONE);

  96.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  97.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  98.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  99.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  100.                        
  101.             // Preparo il menu
  102.             porteApplicativeHelper.makeMenu();

  103.             // Prendo nome della porta applicativa
  104.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  105.             String nomePorta = pa.getNome();
  106.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pa.getTipoSoggettoProprietario());
  107.            
  108.             Trasformazioni trasformazioni = pa.getTrasformazioni();
  109.             TrasformazioneRegola oldRegola = null;
  110.             TrasformazioneRegolaParametro oldParametro = null;
  111.             for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  112.                 if(reg.getId().longValue() == idTrasformazione) {
  113.                     oldRegola = reg;
  114.                     break;
  115.                 }
  116.             }
  117.             if(oldRegola==null) {
  118.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  119.             }

  120.             for (int j = 0; j < oldRegola.getRichiesta().sizeHeaderList(); j++) {
  121.                 TrasformazioneRegolaParametro parametro = oldRegola.getRichiesta().getHeader(j);
  122.                 if (parametro.getId().longValue() == idTrasformazioneRichiestaHeader) {
  123.                     oldParametro = parametro;
  124.                     break;
  125.                 }
  126.             }
  127.             if(oldParametro==null) {
  128.                 throw new Exception("TrasformazioneRegolaParametro con id '"+idTrasformazioneRichiestaHeader+"' non trovata");
  129.             }
  130.            
  131.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  132.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  133.            
  134.             String nomeTrasformazione = oldRegola.getNome();
  135.             String nomeParametro = oldParametro.getNome();
  136.             Parameter pIdTrasformazione = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE, idTrasformazione+"");
  137.            
  138.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  139.             String labelPerPorta = null;
  140.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  141.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  142.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI,
  143.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI,
  144.                         pa);
  145.             }
  146.             else {
  147.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI+nomePorta;
  148.             }

  149.             lstParam.add(new Parameter(labelPerPorta,
  150.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_LIST,
  151.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  152.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  153.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  154.                     ));
  155.            
  156.             lstParam.add(new Parameter(nomeTrasformazione, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_CHANGE,
  157.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  158.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  159.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps), pIdTrasformazione));
  160.            
  161.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiesta = new ArrayList<>();
  162.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  163.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  164.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  165.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdTrasformazione);
  166.            
  167.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA,
  168.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA,parametriInvocazioneServletTrasformazioniRichiesta));
  169.                        
  170.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiestaHeaders = new ArrayList<>();
  171.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  172.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  173.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  174.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pIdTrasformazione);
  175.            
  176.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADERS,
  177.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_LIST,parametriInvocazioneServletTrasformazioniRichiestaHeaders ));
  178.            
  179.             lstParam.add(new Parameter(nomeParametro, null));

  180.             ServletUtils.setPageDataTitle(pd, lstParam);
  181.            
  182.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  183.             // dati
  184.             if (porteApplicativeHelper.isEditModeInProgress()) {
  185.                 // preparo i campi
  186.                 List<DataElement> dati = new ArrayList<>();
  187.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  188.                
  189.                 // primo accesso
  190.                 if(nome == null) {
  191.                     nome = oldParametro.getNome();
  192.                     tipo = oldParametro.getConversioneTipo().getValue();
  193.                     valore = oldParametro.getValore();
  194.                     identificazione = oldParametro.getIdentificazioneFallita()!=null ? oldParametro.getIdentificazioneFallita().getValue() : CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_IDENTIFICAZIONE_FALLITA;
  195.                 }

  196.                 dati = porteApplicativeHelper.addTrasformazioneRichiestaHeaderToDati(TipoOperazione.CHANGE, protocollo, false, dati, idTrasformazioneS, idTrasformazioneRichiestaHeaderS, nome, tipo, valore, identificazione, apc.getServiceBinding());
  197.                
  198.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);
  199.                
  200.                 pd.setDati(dati);

  201.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  202.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.CHANGE());
  203.             }
  204.            
  205.             boolean isOk = porteApplicativeHelper.trasformazioniRichiestaHeaderCheckData(TipoOperazione.CHANGE);
  206.             if (!isOk) {

  207.                 // preparo i campi
  208.                 List<DataElement> dati = new ArrayList<>();

  209.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  210.                
  211.                 dati = porteApplicativeHelper.addTrasformazioneRichiestaHeaderToDati(TipoOperazione.CHANGE, protocollo, false, dati, idTrasformazioneS, idTrasformazioneRichiestaHeaderS, nome, tipo, valore, identificazione, apc.getServiceBinding());
  212.                
  213.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);
  214.                
  215.                 pd.setDati(dati);

  216.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  217.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.CHANGE());
  218.             }
  219.            
  220.             // aggiorno la regola
  221.             TrasformazioneRegola regola = null;
  222.             for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  223.                 if(reg.getId().longValue() == idTrasformazione) {
  224.                     regola = reg;
  225.                     break;
  226.                 }
  227.             }
  228.             if(regola==null) {
  229.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  230.             }
  231.            
  232.             TrasformazioneRegolaParametro parametroDaAggiornare = null;
  233.             for (int j = 0; j < regola.getRichiesta().sizeHeaderList(); j++) {
  234.                 TrasformazioneRegolaParametro parametro = regola.getRichiesta().getHeader(j);
  235.                 if (parametro.getId().longValue() == idTrasformazioneRichiestaHeader) {
  236.                     parametroDaAggiornare = parametro;
  237.                     break;
  238.                 }
  239.             }
  240.             if(parametroDaAggiornare==null) {
  241.                 throw new Exception("TrasformazioneRegolaParametro con id '"+idTrasformazioneRichiestaHeader+"' non trovata");
  242.             }
  243.            
  244.             parametroDaAggiornare.setNome(nome);
  245.             parametroDaAggiornare.setValore(valore);
  246.             parametroDaAggiornare.setConversioneTipo(TrasformazioneRegolaParametroTipoAzione.toEnumConstant(tipo));
  247.             if(!TrasformazioneRegolaParametroTipoAzione.DELETE.equals(parametroDaAggiornare.getConversioneTipo())) {
  248.                 parametroDaAggiornare.setIdentificazioneFallita(TrasformazioneIdentificazioneRisorsaFallita.toEnumConstant(identificazione));
  249.             }
  250.             else {
  251.                 parametroDaAggiornare.setIdentificazioneFallita(null);
  252.             }
  253.            
  254.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  255.            
  256.             // ricaricare id trasformazione
  257.             pa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta));

  258.             TrasformazioneRegola trasformazioneAggiornata = porteApplicativeCore.getTrasformazione(pa.getId(), regola.getNome());
  259.            
  260.             // Preparo la lista
  261.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  262.            
  263.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER;
  264.            
  265.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  266.            
  267.             List<TrasformazioneRegolaParametro> lista = porteApplicativeCore.porteAppTrasformazioniRichiestaHeaderList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  268.            
  269.             porteApplicativeHelper.preparePorteAppTrasformazioniRichiestaHeaderList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  270.                        
  271.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  272.            
  273.             // Forward control to the specified success URI
  274.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER,   ForwardParams.CHANGE());
  275.         } catch (Exception e) {
  276.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  277.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER,
  278.                     ForwardParams.CHANGE());
  279.         }
  280.     }
  281. }