PorteDelegateTrasformazioniRichiestaUrlParameterChange.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.pd;

  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.PortaDelegata;
  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.  * PorteDelegateTrasformazioniRichiestaUrlParameterChange
  55.  *
  56.  * @author Giuliano Pintori (pintori@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public class PorteDelegateTrasformazioniRichiestaUrlParameterChange 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  76.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  77.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  78.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  79.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  80.             int idInt = Integer.parseInt(id);
  81.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  82.            
  83.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  84.             if(idAsps == null)
  85.                 idAsps = "";
  86.            
  87.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  88.             if(idFruizione == null)
  89.                 idFruizione = "";
  90.            
  91.             String idTrasformazioneS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE);
  92.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  93.            
  94.             String idTrasformazioneRichiestaUrlParameterS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE_RICHIESTA_PARAMETRO);
  95.             long idTrasformazioneRichiestaUrlParameter = Long.parseLong(idTrasformazioneRichiestaUrlParameterS);
  96.            
  97.             String tipo = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_TIPO);
  98.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_NOME);
  99.             String valore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_VALORE);
  100.             String identificazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_IDENTIFICAZIONE);

  101.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  102.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  103.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  104.             Parameter pIdFruizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  105.            
  106.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  107.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  108.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  109.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  110.            
  111.             // Preparo il menu
  112.             porteDelegateHelper.makeMenu();

  113.             // Prendo nome della porta applicativa
  114.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  115.             String nomePorta = portaDelegata.getNome();
  116.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(portaDelegata.getTipoSoggettoProprietario());
  117.            
  118.             Trasformazioni trasformazioni = portaDelegata.getTrasformazioni();
  119.             TrasformazioneRegola oldRegola = null;
  120.             TrasformazioneRegolaParametro oldParametro = null;
  121.             for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  122.                 if(reg.getId().longValue() == idTrasformazione) {
  123.                     oldRegola = reg;
  124.                     break;
  125.                 }
  126.             }
  127.             if(oldRegola==null) {
  128.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  129.             }

  130.             for (int j = 0; j < oldRegola.getRichiesta().sizeParametroUrlList(); j++) {
  131.                 TrasformazioneRegolaParametro parametro = oldRegola.getRichiesta().getParametroUrl(j);
  132.                 if (parametro.getId().longValue() == idTrasformazioneRichiestaUrlParameter) {
  133.                     oldParametro = parametro;
  134.                     break;
  135.                 }
  136.             }
  137.             if(oldParametro==null) {
  138.                 throw new Exception("TrasformazioneRegolaParametro con id '"+idTrasformazioneRichiestaUrlParameter+"' non trovata");
  139.             }
  140.            
  141.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  142.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  143.            
  144.             String nomeTrasformazione = oldRegola.getNome();
  145.             String nomeParametro = oldParametro.getNome();
  146.             Parameter pIdTrasformazione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE, idTrasformazione+"");
  147.            
  148.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  149.            
  150.             String labelPerPorta = null;
  151.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  152.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  153.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_DI,
  154.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI,
  155.                         portaDelegata);
  156.             }
  157.             else {
  158.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_DI+nomePorta;
  159.             }

  160.             lstParam.add(new Parameter(labelPerPorta, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_LIST, pId, pIdSoggetto, pIdAsps, pIdFruizione));
  161.            
  162.             lstParam.add(new Parameter(nomeTrasformazione, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_CHANGE,
  163.                     pId, pIdSoggetto, pIdAsps, pIdFruizione, pIdTrasformazione));
  164.            
  165.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiesta = new ArrayList<>();
  166.             parametriInvocazioneServletTrasformazioniRichiesta.add(pId);
  167.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdSoggetto);
  168.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdAsps);
  169.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdFruizione);
  170.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdTrasformazione);
  171.            
  172.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA,
  173.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA,parametriInvocazioneServletTrasformazioniRichiesta));
  174.                        
  175.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiestaUrlParameters = new ArrayList<>();
  176.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pId);
  177.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdSoggetto);
  178.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdAsps);
  179.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdFruizione);
  180.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdTrasformazione);
  181.            
  182.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRI,
  183.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_LIST,parametriInvocazioneServletTrasformazioniRichiestaUrlParameters ));
  184.            
  185.             lstParam.add(new Parameter(nomeParametro, null));

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

  202.                 dati = porteDelegateHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.CHANGE, protocollo, true, dati, idTrasformazioneS, idTrasformazioneRichiestaUrlParameterS, nome, tipo, valore, identificazione, apc.getServiceBinding());
  203.                
  204.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  205.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);
  206.                
  207.                 pd.setDati(dati);

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

  209.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,    ForwardParams.CHANGE());
  210.             }
  211.            
  212.             boolean isOk = porteDelegateHelper.trasformazioniRichiestaUrlParameterCheckData(TipoOperazione.CHANGE);
  213.             if (isOk && (oldParametro!=null && !oldParametro.getNome().equals(nome))) {
  214.                 boolean giaRegistrato = porteDelegateCore.existsTrasformazioneRichiestaUrlParameter(Long.parseLong(id), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  215.                 if (giaRegistrato) {
  216.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_URL);
  217.                     isOk = false;
  218.                 }
  219.             }
  220.             if (!isOk) {

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

  223.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  224.                
  225.                 dati = porteDelegateHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.CHANGE, protocollo, true, dati, idTrasformazioneS, idTrasformazioneRichiestaUrlParameterS, nome, tipo, valore, identificazione, apc.getServiceBinding());
  226.                
  227.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  228.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);
  229.                
  230.                 pd.setDati(dati);

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

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

  273.             TrasformazioneRegola trasformazioneAggiornata = porteDelegateCore.getTrasformazione(portaDelegata.getId(), regola.getNome());
  274.            
  275.             // Preparo la lista
  276.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  277.            
  278.             int idLista = Liste.PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRI;
  279.            
  280.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  281.            
  282.             List<TrasformazioneRegolaParametro> lista = porteDelegateCore.porteDelegateTrasformazioniRichiestaUrlParameterList(Long.parseLong(id), trasformazioneAggiornata.getId(), ricerca);
  283.            
  284.             porteDelegateHelper.preparePorteDelegateTrasformazioniRichiestaUrlParameterList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  285.                        
  286.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  287.            
  288.             // Forward control to the specified success URI
  289.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.CHANGE());
  290.         } catch (Exception e) {
  291.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  292.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,
  293.                     ForwardParams.CHANGE());
  294.         }
  295.     }
  296. }