PorteDelegateTrasformazioniRichiestaUrlParameterAdd.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.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.  * PorteDelegateTrasformazioniRichiestaUrlParameterAdd
  56.  *
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public class PorteDelegateTrasformazioniRichiestaUrlParameterAdd 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  75.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  76.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  77.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  78.             int idInt = Integer.parseInt(id);
  79.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  80.            
  81.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  82.             if(idAsps == null)
  83.                 idAsps = "";
  84.            
  85.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  86.             if(idFruizione == null)
  87.                 idFruizione = "";
  88.            
  89.             String idTrasformazioneS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE);
  90.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  91.            
  92.             String tipo = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_TIPO);
  93.             if(tipo == null)
  94.                 tipo = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_ADD;
  95.            
  96.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_NOME);
  97.             if(nome == null)
  98.                 nome = "";
  99.            
  100.             String valore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_VALORE);
  101.             if(valore == null)
  102.                 valore = "";
  103.            
  104.             String identificazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_IDENTIFICAZIONE);
  105.             if(identificazione == null)
  106.                 identificazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_IDENTIFICAZIONE_FALLITA;
  107.            
  108.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  109.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  110.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  111.             Parameter pIdFruizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  112.            
  113.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  114.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  115.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  116.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  117.            
  118.             // Preparo il menu
  119.             porteDelegateHelper.makeMenu();

  120.             // Prendo nome della porta applicativa
  121.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  122.             String nomePorta = portaDelegata.getNome();
  123.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(portaDelegata.getTipoSoggettoProprietario());
  124.            
  125.             Trasformazioni trasformazioni = portaDelegata.getTrasformazioni();
  126.             TrasformazioneRegola regola = null;
  127.             for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  128.                 TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  129.                 if (regolaTmp.getId().longValue() == idTrasformazione) {
  130.                     regola = regolaTmp;
  131.                     break;
  132.                 }
  133.             }
  134.             if(regola==null) {
  135.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  136.             }
  137.            
  138.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  139.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  140.            
  141.             String nomeTrasformazione = regola.getNome();
  142.             Parameter pIdTrasformazione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE, idTrasformazione+"");

  143.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  144.            
  145.             String labelPerPorta = null;
  146.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  147.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  148.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_DI,
  149.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI,
  150.                         portaDelegata);
  151.             }
  152.             else {
  153.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_DI+nomePorta;
  154.             }

  155.             lstParam.add(new Parameter(labelPerPorta, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_LIST, pId, pIdSoggetto, pIdAsps, pIdFruizione));
  156.            
  157.             lstParam.add(new Parameter(nomeTrasformazione, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_CHANGE,
  158.                     pId, pIdSoggetto, pIdAsps, pIdFruizione, pIdTrasformazione));
  159.            
  160.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiesta = new ArrayList<>();
  161.             parametriInvocazioneServletTrasformazioniRichiesta.add(pId);
  162.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdSoggetto);
  163.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdAsps);
  164.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdFruizione);
  165.             parametriInvocazioneServletTrasformazioniRichiesta.add(pIdTrasformazione);
  166.            
  167.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA,
  168.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA,parametriInvocazioneServletTrasformazioniRichiesta));
  169.                        
  170.             List<Parameter> parametriInvocazioneServletTrasformazioniRichiestaUrlParameters = new ArrayList<>();
  171.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pId);
  172.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdSoggetto);
  173.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdAsps);
  174.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdFruizione);
  175.             parametriInvocazioneServletTrasformazioniRichiestaUrlParameters.add(pIdTrasformazione);
  176.            
  177.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRI,
  178.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO_LIST,parametriInvocazioneServletTrasformazioniRichiestaUrlParameters ));
  179.            
  180.             lstParam.add(ServletUtils.getParameterAggiungi());

  181.             ServletUtils.setPageDataTitle(pd, lstParam);

  182.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  183.             // dati
  184.             if (porteDelegateHelper.isEditModeInProgress()) {
  185.                 // preparo i campi
  186.                 List<DataElement> dati = new ArrayList<>();
  187.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  188.                
  189.                 dati = porteDelegateHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.ADD, protocollo, true, dati, idTrasformazioneS, null, nome, tipo, valore, identificazione, apc.getServiceBinding());
  190.                
  191.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  192.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);
  193.                
  194.                 pd.setDati(dati);

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

  196.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,    ForwardParams.ADD());
  197.             }
  198.            
  199.             boolean isOk = porteDelegateHelper.trasformazioniRichiestaUrlParameterCheckData(TipoOperazione.ADD);
  200.            
  201.             // Se tipoOp = add, controllo che la trasformazione risposta non sia gia' stato registrata
  202.             if (isOk) {
  203.                 boolean giaRegistrato = porteDelegateCore.existsTrasformazioneRichiestaUrlParameter(Long.parseLong(id), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  204.                 if (giaRegistrato) {
  205.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_URL);
  206.                     isOk = false;
  207.                 }
  208.             }
  209.            
  210.             if (!isOk) {

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

  213.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  214.                
  215.                 dati = porteDelegateHelper.addTrasformazioneRichiestaUrlParameterToDati(TipoOperazione.ADD, protocollo, true, dati, idTrasformazioneS, null, nome, tipo, valore, identificazione, apc.getServiceBinding());
  216.                
  217.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  218.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);
  219.                
  220.                 pd.setDati(dati);

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

  222.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO,    ForwardParams.ADD());
  223.             }
  224.            
  225.             // salvataggio nuova regola
  226.             for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  227.                 TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  228.                 if (regolaTmp.getId().longValue() == idTrasformazione) {
  229.                     regola = regolaTmp;
  230.                     break;
  231.                 }
  232.             }
  233.            
  234.             if(regola.getRichiesta() == null)
  235.                 regola.setRichiesta(new TrasformazioneRegolaRichiesta());
  236.            
  237.             TrasformazioneRegolaParametro parametro = new TrasformazioneRegolaParametro();
  238.             parametro.setNome(nome);
  239.             parametro.setValore(valore);
  240.             parametro.setConversioneTipo(TrasformazioneRegolaParametroTipoAzione.toEnumConstant(tipo));
  241.             if(!TrasformazioneRegolaParametroTipoAzione.DELETE.equals(parametro.getConversioneTipo())) {
  242.                 parametro.setIdentificazioneFallita(TrasformazioneIdentificazioneRisorsaFallita.toEnumConstant(identificazione));
  243.             }
  244.             else {
  245.                 parametro.setIdentificazioneFallita(null);
  246.             }
  247.                    
  248.             regola.getRichiesta().addParametroUrl(parametro);
  249.            
  250.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  251.            
  252.             /** ricaricare id trasformazione
  253.             portaDelegata = porteDelegateCore.getPortaDelegata(Long.parseLong(id)); */

  254.             TrasformazioneRegola trasformazioneAggiornata = porteDelegateCore.getTrasformazione(Long.parseLong(id), regola.getNome());

  255.             // Preparo la lista
  256.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  257.            
  258.             int idLista = Liste.PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRI;
  259.            
  260.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  261.            
  262.             List<TrasformazioneRegolaParametro> lista = porteDelegateCore.porteDelegateTrasformazioniRichiestaUrlParameterList(Long.parseLong(id), trasformazioneAggiornata.getId(), ricerca);
  263.            
  264.             porteDelegateHelper.preparePorteDelegateTrasformazioniRichiestaUrlParameterList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  265.                        
  266.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  267.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.ADD());


  268.         } catch (Exception e) {
  269.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_PARAMETRO, ForwardParams.ADD());
  270.         }
  271.     }
  272. }