PorteDelegateTrasformazioniRichiestaHeaderAdd.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.  * PorteDelegateTrasformazioniRichiestaHeaderAdd
  56.  *
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public class PorteDelegateTrasformazioniRichiestaHeaderAdd 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.             String idTrasformazioneS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE);
  89.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  90.            
  91.             String tipo = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_TIPO);
  92.             if(tipo == null)
  93.                 tipo = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_ADD;
  94.            
  95.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_NOME);
  96.             if(nome == null)
  97.                 nome = "";
  98.            
  99.             String valore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_VALORE);
  100.             if(valore == null)
  101.                 valore = "";
  102.            
  103.             String identificazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER_IDENTIFICAZIONE);
  104.             if(identificazione == null)
  105.                 identificazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_PARAMETRO_IDENTIFICAZIONE_FALLITA;
  106.            
  107.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  108.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  109.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  110.             Parameter pIdFruizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  111.            
  112.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  113.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  114.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  115.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  116.            
  117.             // Preparo il menu
  118.             porteDelegateHelper.makeMenu();

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

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

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

  180.             ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  195.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER,   ForwardParams.ADD());
  196.             }
  197.            
  198.             boolean isOk = porteDelegateHelper.trasformazioniRichiestaHeaderCheckData(TipoOperazione.ADD);
  199.            
  200.             if (isOk) {
  201.                 boolean giaRegistrato = porteDelegateCore.existsTrasformazioneRichiestaHeader(Long.parseLong(id), idTrasformazione, nome, tipo, CostantiControlStation.VALUE_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER_URL);

  202.                 if (giaRegistrato) {
  203.                     pd.setMessage(CostantiControlStation.MESSAGGIO_TRASFORMAZIONI_CHECK_UNIQUE_NOME_TIPO_HEADER);
  204.                     isOk = false;
  205.                 }
  206.             }
  207.            
  208.             if (!isOk) {

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

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

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

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

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

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

  265.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RICHIESTA_HEADER, ForwardParams.ADD());


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