PorteApplicativeCorrelazioneApplicativaRequestAdd.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.config.CorrelazioneApplicativa;
  31. import org.openspcoop2.core.config.CorrelazioneApplicativaElemento;
  32. import org.openspcoop2.core.config.PortaApplicativa;
  33. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRichiestaIdentificazione;
  35. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  36. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  37. import org.openspcoop2.message.constants.ServiceBinding;
  38. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  39. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  42. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  43. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  44. import org.openspcoop2.web.lib.mvc.DataElement;
  45. import org.openspcoop2.web.lib.mvc.ForwardParams;
  46. import org.openspcoop2.web.lib.mvc.GeneralData;
  47. import org.openspcoop2.web.lib.mvc.PageData;
  48. import org.openspcoop2.web.lib.mvc.Parameter;
  49. import org.openspcoop2.web.lib.mvc.ServletUtils;
  50. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  51. /**
  52.  * porteApplicativeCorrAppAdd
  53.  *
  54.  * @author Andrea Poli (apoli@link.it)
  55.  * @author Stefano Corallo (corallo@link.it)
  56.  * @author Sandra Giangrandi (sandra@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public final class PorteApplicativeCorrelazioneApplicativaRequestAdd 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.         // Inizializzo GeneralData
  69.         GeneralData gd = generalHelper.initGeneralData(request);
  70.        
  71.         try {
  72.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  73.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  74.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  75.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;

  76.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  77.             int idInt = Integer.parseInt(idPorta);
  78.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  79.             String elemxml = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ELEMENTO_XML);
  80.             String mode = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE);
  81.             if (mode == null) {
  82.                 mode = PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED;
  83.             }
  84.             String pattern = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_PATTERN);
  85.             String gif = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_GESTIONE_IDENTIFICAZIONE_FALLITA);
  86.             String riusoIdMessaggio = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RIUSO_ID_MESSAGGIO);
  87.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  88.             if(idAsps == null)
  89.                 idAsps = "";

  90.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  91.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  92.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  93.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);

  94.             // Preparo il menu
  95.             porteApplicativeHelper.makeMenu();

  96.             // Prendo il nome della porta applicativa
  97.             PortaApplicativa pde = porteApplicativeCore.getPortaApplicativa(idInt);
  98.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());
  99.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  100.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  101.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  102.             String nome = pde.getNome();
  103.            
  104.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  105.             String labelPerPorta = null;
  106.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  107.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  108.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  109.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRACCIAMENTO,
  110.                         pde);
  111.             }
  112.             else {
  113.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nome;
  114.             }
  115.             lstParam.add(new Parameter(labelPerPorta,
  116.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA,
  117.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  118.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  119.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nome),
  120.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  121.                     ));
  122.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_RICHIESTA_DI, // + nome,
  123.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST_LIST,
  124.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  125.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  126.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nome),
  127.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  128.             lstParam.add(ServletUtils.getParameterAggiungi());

  129.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  130.             // dati
  131.             if (porteApplicativeHelper.isEditModeInProgress()) {
  132.                
  133.                 // setto la barra del titolo
  134.                 ServletUtils.setPageDataTitle(pd, lstParam);
  135.                
  136.                 // preparo i campi
  137.                 List<DataElement> dati = new ArrayList<>();
  138.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  139.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRichiestaToDati(TipoOperazione.ADD, elemxml, mode,
  140.                         pattern, gif, riusoIdMessaggio, dati, apc.getServiceBinding(),
  141.                         protocollo);
  142.                
  143.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  144.                 pd.setDati(dati);

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

  146.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  147.                         ForwardParams.ADD());
  148.             }

  149.             // Controlli sui campi immessi
  150.             boolean isOk = porteApplicativeHelper.correlazioneApplicativaRichiestaCheckData(TipoOperazione.ADD,false,
  151.                     serviceBinding);
  152.             if (!isOk) {
  153.                 // setto la barra del titolo
  154.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  157.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  158.                
  159.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRichiestaToDati(TipoOperazione.ADD, elemxml, mode, pattern, gif, riusoIdMessaggio,
  160.                         dati, apc.getServiceBinding(),
  161.                         protocollo);
  162.                
  163.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);
  164.                
  165.                 pd.setDati(dati);

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

  167.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  168.                         ForwardParams.ADD());
  169.             }

  170.             // Inserisco la correlazione applicativa nel db
  171.             CorrelazioneApplicativaElemento cae = new CorrelazioneApplicativaElemento();
  172.             cae.setNome(elemxml);
  173.             cae.setIdentificazione(CorrelazioneApplicativaRichiestaIdentificazione.toEnumConstant(mode));
  174.             if (mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  175.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  176.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  177.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  178.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  179.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE) ) {
  180.                 cae.setPattern(pattern);
  181.             }
  182.            
  183.             if(!PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  184.                 cae.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  185.             }
  186.            
  187.             CorrelazioneApplicativa ca = pde.getCorrelazioneApplicativa();
  188.             if (ca == null) {
  189.                 ca = new CorrelazioneApplicativa();
  190.             }
  191.             ca.addElemento(cae);
  192.             pde.setCorrelazioneApplicativa(ca);

  193.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  194.            
  195.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pde);

  196.             // Preparo la lista
  197.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  198.             List<CorrelazioneApplicativaElemento> lista = porteApplicativeCore.porteApplicativeCorrelazioneApplicativaList(idInt, ricerca);

  199.             porteApplicativeHelper.preparePorteApplicativeCorrAppList(nome, ricerca, lista);

  200.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  201.             // Forward control to the specified success URI
  202.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  203.                     ForwardParams.ADD());
  204.         } catch (Exception e) {
  205.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  206.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  207.                     ForwardParams.ADD());
  208.         }
  209.     }


  210. }