PorteApplicativeTrasformazioniRichiestaUrlParameterChange.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.  * PorteApplicativeTrasformazioniRichiestaUrlParameterChange
  55.  *
  56.  * @author Giuliano Pintori (pintori@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public class PorteApplicativeTrasformazioniRichiestaUrlParameterChange 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.            
  80.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  81.             int idInt = Integer.parseInt(idPorta);
  82.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  83.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  84.             if(idAsps == null)
  85.                 idAsps = "";
  86.            
  87.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  88.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  89.            
  90.             String idTrasformazioneRichiestaUrlParameterS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE_RICHIESTA_PARAMETRO);
  91.             long idTrasformazioneRichiestaUrlParameter = Long.parseLong(idTrasformazioneRichiestaUrlParameterS);
  92.            
  93.             String tipo = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_TIPO);
  94.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_NOME);
  95.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_VALORE);
  96.             String identificazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_IDENTIFICAZIONE);

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

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

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

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

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

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

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

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

  203.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,  ForwardParams.CHANGE());
  204.             }
  205.            
  206.             boolean isOk = porteApplicativeHelper.trasformazioniRichiestaUrlParameterCheckData(TipoOperazione.CHANGE);
  207.             if (isOk && (oldParametro!=null && !oldParametro.getNome().equals(nome))) {
  208.                 boolean giaRegistrato = porteApplicativeCore.existsTrasformazioneRichiestaUrlParameter(Long.parseLong(idPorta), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  209.                 if (giaRegistrato) {
  210.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_URL);
  211.                     isOk = false;
  212.                 }
  213.             }
  214.             if (!isOk) {

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

  217.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  218.                
  219.                 dati = porteApplicativeHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.CHANGE, protocollo, false, dati, idTrasformazioneS, idTrasformazioneRichiestaUrlParameterS, nome, tipo, valore, identificazione, apc.getServiceBinding());
  220.                
  221.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);
  222.                
  223.                 pd.setDati(dati);

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

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

  266.             TrasformazioneRegola trasformazioneAggiornata = porteApplicativeCore.getTrasformazione(pa.getId(), regola.getNome());
  267.            
  268.             // Preparo la lista
  269.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  270.            
  271.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRI;
  272.            
  273.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  274.            
  275.             List<TrasformazioneRegolaParametro> lista = porteApplicativeCore.porteAppTrasformazioniRichiestaUrlParameterList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  276.            
  277.             porteApplicativeHelper.preparePorteAppTrasformazioniRichiestaUrlParameterList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  278.                        
  279.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  280.            
  281.             // Forward control to the specified success URI
  282.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.CHANGE());
  283.         } catch (Exception e) {
  284.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  285.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,
  286.                     ForwardParams.CHANGE());
  287.         }
  288.     }
  289. }