PorteApplicativeCorrelazioneApplicativaRequestChange.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.CorrelazioneApplicativa;
  32. import org.openspcoop2.core.config.CorrelazioneApplicativaElemento;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  35. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRichiestaIdentificazione;
  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.  * porteApplicativeCorrAppChange
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author Stefano Corallo (corallo@link.it)
  58.  * @author Sandra Giangrandi (sandra@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  *
  62.  */
  63. public final class PorteApplicativeCorrelazioneApplicativaRequestChange extends Action {

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

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

  67.         // Inizializzo PageData
  68.         PageData pd = new PageData();

  69.         GeneralHelper generalHelper = new GeneralHelper(session);

  70.         // Inizializzo GeneralData
  71.         GeneralData gd = generalHelper.initGeneralData(request);

  72.         try {
  73.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  75.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  76.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  77.            
  78.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  79.             int idInt = Integer.parseInt(idPorta);
  80.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  81.            
  82.             String elemxml = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ELEMENTO_XML);
  83.             if(elemxml!=null)
  84.                 elemxml = StringEscapeUtils.escapeHtml(elemxml);

  85.             String mode = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE);

  86.             String pattern = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_PATTERN);
  87.             if(pattern!=null)
  88.                 pattern = StringEscapeUtils.escapeHtml(pattern);

  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 riusoIdMessaggio = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RIUSO_ID_MESSAGGIO);
  93.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  94.             if(idAsps == null)
  95.                 idAsps = "";
  96.            
  97.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  98.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  99.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  100.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);

  101.             // Preparo il menu
  102.             porteApplicativeHelper.makeMenu();

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

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

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

  156.                 if (elemxml == null) {
  157.                     elemxml = StringEscapeUtils.escapeHtml(cae.getNome());
  158.                 }
  159.                 if (mode == null &&
  160.                     cae.getIdentificazione()!=null) {
  161.                     mode = cae.getIdentificazione().toString();
  162.                 }
  163.                 if (pattern == null) {
  164.                     pattern = StringEscapeUtils.escapeHtml(cae.getPattern());
  165.                 }
  166.                 if (gif == null &&
  167.                     cae.getIdentificazioneFallita()!=null) {
  168.                     gif = cae.getIdentificazioneFallita().toString();
  169.                 }
  170.                 if (riusoIdMessaggio == null &&
  171.                     cae.getRiusoIdentificativo()!=null) {
  172.                     riusoIdMessaggio = cae.getRiusoIdentificativo().toString();
  173.                 }


  174.                 // preparo i campi
  175.                 List<DataElement> dati = new ArrayList<>();
  176.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  177.                 dati = porteApplicativeHelper.addHiddenFieldCorrelazioneApplicativaToDati(TipoOperazione.CHANGE, idcorrString, dati);

  178.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRichiestaToDati(TipoOperazione.CHANGE, elemxml, mode,
  179.                         pattern, gif, riusoIdMessaggio, dati, apc.getServiceBinding(),
  180.                         protocollo);

  181.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  182.                 pd.setDati(dati);

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

  184.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  185.                         ForwardParams.CHANGE());
  186.             }

  187.             // Controlli sui campi immessi
  188.             boolean isOk = porteApplicativeHelper.correlazioneApplicativaRichiestaCheckData(TipoOperazione.CHANGE,false,
  189.                     serviceBinding);
  190.             if (!isOk) {
  191.                 // setto la barra del titolo
  192.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  195.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  196.                 dati = porteApplicativeHelper.addHiddenFieldCorrelazioneApplicativaToDati(TipoOperazione.CHANGE, idcorrString, dati);

  197.                 dati = porteApplicativeHelper.addPorteApplicativeCorrelazioneApplicativeRichiestaToDati(TipoOperazione.CHANGE, elemxml, mode,
  198.                         pattern, gif, riusoIdMessaggio, dati, apc.getServiceBinding(),
  199.                         protocollo);

  200.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  201.                 pd.setDati(dati);

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

  203.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CORRELAZIONE_APPLICATIVA_REQUEST,
  204.                         ForwardParams.CHANGE());
  205.             }

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

  241.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  242.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pde);

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

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

  246.             porteApplicativeHelper.preparePorteApplicativeCorrAppList(nomePorta, ricerca, lista);

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


  257. }