PorteApplicativeCorrelazioneApplicativaResponseAdd.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.CorrelazioneApplicativaRisposta;
  31. import org.openspcoop2.core.config.CorrelazioneApplicativaRispostaElemento;
  32. import org.openspcoop2.core.config.PortaApplicativa;
  33. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRispostaIdentificazione;
  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.  * porteApplicativeCorrAppRispostaAdd
  53.  *
  54.  * @author Andrea Poli (apoli@link.it)
  55.  * @author $Author$
  56.  * @version $Rev$, $Date$
  57.  *
  58.  */
  59. public final class PorteApplicativeCorrelazioneApplicativaResponseAdd extends Action {

  60.     @Override
  61.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  62.         HttpSession session = request.getSession(true);

  63.         // Inizializzo PageData
  64.         PageData pd = new PageData();

  65.         GeneralHelper generalHelper = new GeneralHelper(session);

  66.         // Inizializzo GeneralData
  67.         GeneralData gd = generalHelper.initGeneralData(request);

  68.         try {
  69.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  70.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  71.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  72.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;

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

  86.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  87.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  88.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  89.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  90.            
  91.             // Preparo il menu
  92.             porteApplicativeHelper.makeMenu();

  93.             // Prendo il nome della porta applicativa
  94.             PortaApplicativa pde = porteApplicativeCore.getPortaApplicativa(idInt);
  95.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());
  96.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  97.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  98.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  99.             String nome = pde.getNome();
  100.            
  101.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  102.            
  103.             String labelPerPorta = null;
  104.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  105.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  106.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  107.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRACCIAMENTO,
  108.                         pde);
  109.             }
  110.             else {
  111.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nome;
  112.             }
  113.             lstParam.add(new Parameter(labelPerPorta,
  114.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA,
  115.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  116.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  117.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nome),
  118.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  119.                     ));
  120.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_RISPOSTA_DI, // + nome,
  121.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE_LIST,
  122.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  123.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  124.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nome),
  125.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  126.             lstParam.add(ServletUtils.getParameterAggiungi());

  127.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  128.             // dati
  129.             if (porteApplicativeHelper.isEditModeInProgress()) {
  130.                 // setto la barra del titolo
  131.                 ServletUtils.setPageDataTitle(pd, lstParam);

  132.                 // preparo i campi
  133.                 List<DataElement> dati = new ArrayList<>();
  134.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  135.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRispostaToDati(TipoOperazione.ADD,
  136.                         elemxml, mode, pattern, gif, dati, apc.getServiceBinding(),
  137.                         protocollo);
  138.                
  139.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);
  140.                
  141.                 pd.setDati(dati);

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

  143.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  144.                         ForwardParams.ADD());
  145.             }

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

  152.                 // preparo i campi
  153.                 List<DataElement> dati = new ArrayList<>();
  154.                
  155.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  156.                
  157.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRispostaToDati(TipoOperazione.ADD,
  158.                         elemxml, mode, pattern, gif, dati, apc.getServiceBinding(),
  159.                         protocollo);

  160.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);
  161.                
  162.                 pd.setDati(dati);

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

  164.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  165.                         ForwardParams.ADD());
  166.             }

  167.             // Inserisco la correlazione applicativa nel db
  168.             CorrelazioneApplicativaRispostaElemento cae = new CorrelazioneApplicativaRispostaElemento();
  169.             cae.setNome(elemxml);
  170.             cae.setIdentificazione(CorrelazioneApplicativaRispostaIdentificazione.toEnumConstant(mode));
  171.             if (mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  172.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  173.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  174.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  175.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  176.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE)) {
  177.                 cae.setPattern(pattern);
  178.             }
  179.            
  180.             if(!PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  181.                 cae.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  182.             }
  183.            
  184.             CorrelazioneApplicativaRisposta ca = pde.getCorrelazioneApplicativaRisposta();
  185.             if (ca == null) {
  186.                 ca = new CorrelazioneApplicativaRisposta();
  187.             }
  188.             ca.addElemento(cae);
  189.             pde.setCorrelazioneApplicativaRisposta(ca);

  190.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  191.            
  192.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pde);

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

  195.             List<CorrelazioneApplicativaRispostaElemento> lista = porteApplicativeCore.porteApplicativeCorrelazioneApplicativaRispostaList(idInt, ricerca);

  196.             porteApplicativeHelper.preparePorteApplicativeCorrAppRispostaList(nome, ricerca, lista);

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