PorteApplicativeCorrelazioneApplicativaResponseChange.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.List;
  22. import java.util.ArrayList;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringEscapeUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.config.CorrelazioneApplicativaRisposta;
  32. import org.openspcoop2.core.config.CorrelazioneApplicativaRispostaElemento;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  35. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRispostaIdentificazione;
  36. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  37. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  38. import org.openspcoop2.message.constants.ServiceBinding;
  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.  * porteApplicativeCorrAppRispostaChange
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public final class PorteApplicativeCorrelazioneApplicativaResponseChange 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.         try {
  71.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  72.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  73.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  74.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;

  75.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  76.             int idInt = Integer.parseInt(idPorta);
  77.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  78.            
  79.             String elemxml = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ELEMENTO_XML);
  80.             if(elemxml!=null)
  81.                 elemxml = StringEscapeUtils.escapeHtml(elemxml);
  82.            
  83.             String mode = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE);
  84.            
  85.             String pattern = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_PATTERN);
  86.             if(pattern!=null)
  87.                 pattern = StringEscapeUtils.escapeHtml(pattern);
  88.            
  89.             String idcorrString = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_CORRELAZIONE_APPLICATIVA);
  90.             int idcorr = Integer.parseInt(idcorrString);
  91.             String gif = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_GESTIONE_IDENTIFICAZIONE_FALLITA);
  92.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  93.             if(idAsps == null)
  94.                 idAsps = "";
  95.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  96.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  97.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  98.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);

  99.             // Preparo il menu
  100.             porteApplicativeHelper.makeMenu();

  101.             // Prendo il nome della porta applicativa
  102.             PortaApplicativa pde = porteApplicativeCore.getPortaApplicativa(idInt);
  103.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());
  104.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  105.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  106.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  107.             String nomePorta = pde.getNome();

  108.             // Prendo il nome originario della correlazione applicativa
  109.             String elemxmlOrig = "";
  110.             CorrelazioneApplicativaRisposta ca = pde.getCorrelazioneApplicativaRisposta();
  111.             CorrelazioneApplicativaRispostaElemento cae = null;
  112.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  113.                 cae = ca.getElemento(i);
  114.                 if (idcorr == cae.getId().intValue()) {
  115.                     elemxmlOrig = cae.getNome();
  116.                     break;
  117.                 }
  118.             }
  119.             if (elemxmlOrig == null || "".equals(elemxmlOrig))
  120.                 elemxmlOrig = CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI;
  121.             // Quando esco dal ciclo, cae รจ il mio elemento
  122.            
  123.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  124.            
  125.             String labelPerPorta = null;
  126.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  127.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  128.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  129.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRACCIAMENTO,
  130.                         pde);
  131.             }
  132.             else {
  133.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nomePorta;
  134.             }
  135.             lstParam.add(new Parameter(labelPerPorta,
  136.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA,
  137.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  138.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  139.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nomePorta),
  140.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  141.                     ));
  142.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CORRELAZIONI_APPLICATIVE_RISPOSTA_DI, // + nomePorta,
  143.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE_LIST,
  144.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  145.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  146.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nomePorta),
  147.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  148.             lstParam.add(new Parameter(elemxmlOrig, null));

  149.             // Se idhid = null, devo visualizzare la pagina per la
  150.             // modifica dati
  151.             if (porteApplicativeHelper.isEditModeInProgress()) {
  152.                 // setto la barra del titolo
  153.                 ServletUtils.setPageDataTitle(pd, lstParam);

  154.                 if (elemxml == null) {
  155.                     elemxml = StringEscapeUtils.escapeHtml(cae.getNome());
  156.                 }
  157.                 if (mode == null &&
  158.                     cae.getIdentificazione()!=null) {
  159.                     mode = cae.getIdentificazione().toString();
  160.                 }
  161.                 if (pattern == null) {
  162.                     pattern = StringEscapeUtils.escapeHtml(cae.getPattern());
  163.                 }
  164.                 if (gif == null &&
  165.                     cae.getIdentificazioneFallita()!=null) {
  166.                     gif = cae.getIdentificazioneFallita().toString();
  167.                 }


  168.                 // preparo i campi
  169.                 List<DataElement> dati = new ArrayList<>();
  170.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  171.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRispostaToDati(TipoOperazione.CHANGE, elemxml, mode, pattern, gif, dati, apc.getServiceBinding(), protocollo);

  172.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);
  173.                
  174.                 dati = porteApplicativeHelper.addHiddenFieldCorrelazioneApplicativaToDati(TipoOperazione.CHANGE, idcorrString, dati);

  175.                 pd.setDati(dati);

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

  177.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  178.                         ForwardParams.CHANGE());
  179.             }

  180.             // Controlli sui campi immessi
  181.             boolean isOk = porteApplicativeHelper.correlazioneApplicativaRispostaCheckData(TipoOperazione.CHANGE,false,
  182.                     serviceBinding);
  183.             if (!isOk) {
  184.                 // setto la barra del titolo
  185.                 ServletUtils.setPageDataTitle(pd, lstParam);

  186.                 // preparo i campi
  187.                 List<DataElement> dati = new ArrayList<>();
  188.                
  189.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  190.                
  191.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRispostaToDati(TipoOperazione.CHANGE, elemxml, mode, pattern, gif, dati, apc.getServiceBinding(), protocollo);

  192.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);
  193.                
  194.                 dati = porteApplicativeHelper.addHiddenFieldCorrelazioneApplicativaToDati(TipoOperazione.CHANGE, idcorrString, dati);
  195.                
  196.                 pd.setDati(dati);

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

  198.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  199.                         ForwardParams.CHANGE());
  200.             }

  201.             // Modifico i dati della correlazione applicativa della porta
  202.             // applicativa
  203.             // nel db
  204.             CorrelazioneApplicativaRispostaElemento caeNew=null;
  205.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  206.                 cae = ca.getElemento(i);
  207.                 if (idcorr == cae.getId().intValue()) {
  208.                     caeNew = cae;
  209.                     break;
  210.                 }
  211.             }
  212.             if(caeNew==null) {
  213.                 throw new Exception("CorrelazioneApplicativaElemento con id '"+idcorr+"' non trovato");
  214.             }
  215.                        
  216.             if(CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI.equals(elemxml)) {
  217.                 caeNew.setNome(null);
  218.             }
  219.             else {
  220.                 caeNew.setNome(StringEscapeUtils.unescapeHtml(elemxml));
  221.             }
  222.             caeNew.setIdentificazione(CorrelazioneApplicativaRispostaIdentificazione.toEnumConstant(mode));
  223.             if (mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  224.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  225.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  226.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  227.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  228.                     mode.equals(PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE)) {
  229.                 caeNew.setPattern(StringEscapeUtils.unescapeHtml(pattern));
  230.             }
  231.             if(!PorteApplicativeCostanti.VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  232.                 caeNew.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  233.             }
  234.             //ca.addElemento(caeNew); l'elemento e' stato modificato per riferimento
  235.             pde.setCorrelazioneApplicativaRisposta(ca);

  236.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  237.            
  238.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pde);

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

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

  242.             porteApplicativeHelper.preparePorteApplicativeCorrAppRispostaList(nomePorta, ricerca, lista);

  243.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  244.             // Forward control to the specified success URI
  245.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  246.                     ForwardParams.CHANGE());
  247.         } catch (Exception e) {
  248.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  249.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  250.                     ForwardParams.CHANGE());
  251.         }  
  252.     }
  253. }