PorteApplicativeTrasformazioniRichiestaHeaderAdd.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.  * PorteApplicativeTrasformazioniRichiestaHeaderAdd
  56.  *
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public class PorteApplicativeTrasformazioniRichiestaHeaderAdd 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.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  78.             int idInt = Integer.parseInt(idPorta);
  79.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  80.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";
  83.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  84.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  85.            
  86.             String tipo = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_TIPO);
  87.             if(tipo == null)
  88.                 tipo = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_ADD;
  89.            
  90.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_NOME);
  91.             if(nome == null)
  92.                 nome = "";
  93.            
  94.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_VALORE);
  95.             if(valore == null)
  96.                 valore = "";
  97.            
  98.             String identificazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER_IDENTIFICAZIONE);
  99.             if(identificazione == null)
  100.                 identificazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_IDENTIFICAZIONE_FALLITA;
  101.            
  102.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  103.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  104.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  105.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  106.            
  107.             // Preparo il menu
  108.             porteApplicativeHelper.makeMenu();

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

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

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

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

  174.             ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  188.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.ADD());
  189.             }
  190.            
  191.             boolean isOk = porteApplicativeHelper.trasformazioniRichiestaHeaderCheckData(TipoOperazione.ADD);
  192.            
  193.             if (isOk) {
  194.                 boolean giaRegistrato = porteApplicativeCore.existsTrasformazioneRichiestaHeader(Long.parseLong(idPorta), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  195.                 if (giaRegistrato) {
  196.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER);
  197.                     isOk = false;
  198.                 }
  199.             }
  200.            
  201.             if (!isOk) {

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

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

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

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

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

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

  257.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.ADD());


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