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

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

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

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

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

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         String userLogin = ServletUtils.getUserLoginFromSession(session);  
  70.         // Inizializzo GeneralData
  71.         GeneralData gd = generalHelper.initGeneralData(request);

  72.         try {
  73.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  75.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  76.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  77.            
  78.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  79.             int idInt = Integer.parseInt(idPorta);
  80.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  81.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  82.             if(idAsps == null)
  83.                 idAsps = "";
  84.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  85.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  86.            
  87.             String tipo = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_TIPO);
  88.             if(tipo == null)
  89.                 tipo = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_ADD;
  90.            
  91.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_NOME);
  92.             if(nome == null)
  93.                 nome = "";
  94.            
  95.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_VALORE);
  96.             if(valore == null)
  97.                 valore = "";
  98.            
  99.             String identificazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_IDENTIFICAZIONE);
  100.             if(identificazione == null)
  101.                 identificazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_IDENTIFICAZIONE_FALLITA;
  102.            
  103.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  104.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  105.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  106.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  107.            
  108.             // Preparo il menu
  109.             porteApplicativeHelper.makeMenu();

  110.             // Prendo nome della porta applicativa
  111.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  112.             String nomePorta = pa.getNome();
  113.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pa.getTipoSoggettoProprietario());
  114.            
  115.             Trasformazioni trasformazioni = pa.getTrasformazioni();
  116.             TrasformazioneRegola regola = null;
  117.             for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  118.                 TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  119.                 if (regolaTmp.getId().longValue() == idTrasformazione) {
  120.                     regola = regolaTmp;
  121.                     break;
  122.                 }
  123.             }
  124.             if(regola==null) {
  125.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  126.             }
  127.            
  128.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  129.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  130.            
  131.             String nomeTrasformazione = regola.getNome();
  132.             Parameter pIdTrasformazione = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE, idTrasformazione+"");

  133.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  134.             String labelPerPorta = null;
  135.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  136.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  137.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI,
  138.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI,
  139.                         pa);
  140.             }
  141.             else {
  142.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI+nomePorta;
  143.             }

  144.             lstParam.add(new Parameter(labelPerPorta,
  145.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_LIST,
  146.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  147.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  148.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  149.                     ));
  150.            
  151.             lstParam.add(new Parameter(nomeTrasformazione, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_CHANGE,
  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), pIdTrasformazione));
  155.            
  156.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiesta = new ArrayList<>();
  157.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  158.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  159.             parametriInvocazioneServletTrasformazioniRichiesta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  160.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdTrasformazione);
  161.            
  162.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA,
  163.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA,parametriInvocazioneServletTrasformazioniRichiesta));
  164.                        
  165.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiestaUrlParameters = new ArrayList<>();
  166.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  167.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  168.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  169.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdTrasformazione);
  170.            
  171.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRI,
  172.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_LIST,parametriInvocazioneServletTrasformazioniRichiestaUrlParameters ));
  173.            
  174.             lstParam.add(ServletUtils.getParameterAggiungi());

  175.             ServletUtils.setPageDataTitle(pd, lstParam);

  176.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  177.             // dati
  178.             if (porteApplicativeHelper.isEditModeInProgress()) {
  179.                 // preparo i campi
  180.                 List<DataElement> dati = new ArrayList<>();
  181.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  182.                
  183.                 dati = porteApplicativeHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.ADD, protocollo, false, dati, idTrasformazioneS, null, nome, tipo, valore, identificazione, apc.getServiceBinding());
  184.                
  185.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);
  186.                
  187.                 pd.setDati(dati);

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

  189.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,  ForwardParams.ADD());
  190.             }
  191.            
  192.             boolean isOk = porteApplicativeHelper.trasformazioniRichiestaUrlParameterCheckData(TipoOperazione.ADD);
  193.            
  194.             // Se tipoOp = add, controllo che la trasformazione risposta non sia gia' stato registrata
  195.             if (isOk) {
  196.                 boolean giaRegistrato = porteApplicativeCore.existsTrasformazioneRichiestaUrlParameter(Long.parseLong(idPorta), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  197.                 if (giaRegistrato) {
  198.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_URL);
  199.                     isOk = false;
  200.                 }
  201.             }
  202.            
  203.             if (!isOk) {

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

  206.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  207.                
  208.                 dati = porteApplicativeHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.ADD, protocollo, false, dati, idTrasformazioneS, null, nome, tipo, valore, identificazione, apc.getServiceBinding());
  209.                
  210.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);
  211.                
  212.                 pd.setDati(dati);

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

  214.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,  ForwardParams.ADD());
  215.             }
  216.            
  217.             // salvataggio nuova regola
  218.             for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  219.                 TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  220.                 if (regolaTmp.getId().longValue() == idTrasformazione) {
  221.                     regola = regolaTmp;
  222.                     break;
  223.                 }
  224.             }
  225.            
  226.             if(regola.getRichiesta() == null)
  227.                 regola.setRichiesta(new TrasformazioneRegolaRichiesta());
  228.            
  229.             TrasformazioneRegolaParametro parametro = new TrasformazioneRegolaParametro();
  230.             parametro.setNome(nome);
  231.             parametro.setValore(valore);
  232.             parametro.setConversioneTipo(TrasformazioneRegolaParametroTipoAzione.toEnumConstant(tipo));
  233.             if(!TrasformazioneRegolaParametroTipoAzione.DELETE.equals(parametro.getConversioneTipo())) {
  234.                 parametro.setIdentificazioneFallita(TrasformazioneIdentificazioneRisorsaFallita.toEnumConstant(identificazione));
  235.             }
  236.             else {
  237.                 parametro.setIdentificazioneFallita(null);
  238.             }
  239.                    
  240.             regola.getRichiesta().addParametroUrl(parametro);
  241.            
  242.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  243.            
  244.             /** ricaricare id trasformazione
  245.             pa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta)); */

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

  247.             // Preparo la lista
  248.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  249.            
  250.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRI;
  251.            
  252.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  253.            
  254.             List<TrasformazioneRegolaParametro> lista = porteApplicativeCore.porteAppTrasformazioniRichiestaUrlParameterList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  255.            
  256.             porteApplicativeHelper.preparePorteAppTrasformazioniRichiestaUrlParameterList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  257.                        
  258.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  259.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.ADD());


  260.         } catch (Exception e) {
  261.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.ADD());
  262.         }
  263.     }
  264. }