PorteDelegateTrasformazioniRichiestaHeaderChange.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.  * PorteDelegateTrasformazioniRichiestaHeaderChange
  55.  *
  56.  * @author Giuliano Pintori (pintori@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public class PorteDelegateTrasformazioniRichiestaHeaderChange 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 idTrasformazioneRichiestaHeaderS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE_RICHIESTA_HEADER);
  95.             long idTrasformazioneRichiestaHeader = Long.parseLong(idTrasformazioneRichiestaHeaderS);
  96.            
  97.             String tipo = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_TIPO);
  98.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_NOME);
  99.             String valore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_VALORE);
  100.             String identificazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_IDENTIFICAZIONE);
  101.            
  102.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  103.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  104.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  105.             Parameter pIdFruizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);

  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().sizeHeaderList(); j++) {
  131.                 TrasformazioneRegolaParametro parametro = oldRegola.getRichiesta().getHeader(j);
  132.                 if (parametro.getId().longValue() == idTrasformazioneRichiestaHeader) {
  133.                     oldParametro = parametro;
  134.                     break;
  135.                 }
  136.             }
  137.             if(oldParametro==null) {
  138.                 throw new Exception("TrasformazioneRegolaParametro con id '"+idTrasformazioneRichiestaHeader+"' 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> parametriInvocazioneServletTrasformazioniRichiestaHeaders = new ArrayList<>();
  176.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pId);
  177.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pIdSoggetto);
  178.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pIdAsps);
  179.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pIdFruizione);
  180.             parametriInvocazioneServletTrasformazioniRichiestaHeaders.add(pIdTrasformazione);
  181.            
  182.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADERS,
  183.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_LIST,parametriInvocazioneServletTrasformazioniRichiestaHeaders ));
  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.addTrasformazioneRichiestaHeaderToDati(TipoOperazione.CHANGE, protocollo, true, dati, idTrasformazioneS, idTrasformazioneRichiestaHeaderS, 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_HEADER,   ForwardParams.CHANGE());
  210.             }
  211.            
  212.             boolean isOk = porteDelegateHelper.trasformazioniRichiestaHeaderCheckData(TipoOperazione.CHANGE);
  213.             if (isOk && (oldParametro!=null && !oldParametro.getNome().equals(nome))) {
  214.                 boolean giaRegistrato = porteDelegateCore.existsTrasformazioneRichiestaHeader(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_HEADER);
  217.                     isOk = false;
  218.                 }
  219.             }
  220.            
  221.            
  222.             if (!isOk) {

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

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

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

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

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