PorteDelegateCorrelazioneApplicativaRequestChange.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.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.PortaDelegata;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  35. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRichiestaIdentificazione;
  36. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  37. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  39. import org.openspcoop2.message.constants.ServiceBinding;
  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.  * porteDelegateCorrAppChange
  56.  *
  57.  * @author Andrea Poli (apoli@link.it)
  58.  * @author Stefano Corallo (corallo@link.it)
  59.  * @author Sandra Giangrandi (sandra@link.it)
  60.  * @author $Author$
  61.  * @version $Rev$, $Date$
  62.  *
  63.  */
  64. public final class PorteDelegateCorrelazioneApplicativaRequestChange extends Action {

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

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

  68.         // Inizializzo PageData
  69.         PageData pd = new PageData();
  70.        
  71.         GeneralHelper generalHelper = new GeneralHelper(session);

  72.         // Inizializzo GeneralData
  73.         GeneralData gd = generalHelper.initGeneralData(request);
  74.        
  75.         try {
  76.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  77.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  78.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  79.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;

  80.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  81.             int idInt = Integer.parseInt(id);
  82.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  83.            
  84.             String elemxml = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ELEMENTO_XML);
  85.             if(elemxml!=null)
  86.                 elemxml = StringEscapeUtils.escapeHtml(elemxml);
  87.            
  88.             String mode = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE);
  89.            
  90.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  91.             if(pattern!=null)
  92.                 pattern = StringEscapeUtils.escapeHtml(pattern);
  93.            
  94.             String idcorrString = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_CORRELAZIONE);
  95.             int idcorr = Integer.parseInt(idcorrString);
  96.             String gif = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_IDENTIFICAZIONE_FALLITA);
  97.             String riusoIdMessaggio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RIUSO_ID_MESSAGGIO);
  98.            
  99.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  100.             if(idAsps == null)
  101.                 idAsps = "";
  102.            
  103.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  104.             if(idFruizione == null)
  105.                 idFruizione = "";
  106.            
  107.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore( );
  108.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  109.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  110.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

  111.             // Preparo il menu
  112.             porteDelegateHelper.makeMenu();

  113.             // Prendo il nome della porta delegata
  114.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  115.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  116.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  117.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  118.             String nomePorta = pde.getNome();
  119.            
  120.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());

  121.             // Prendo il nome originario della correlazione applicativa
  122.             String elemxmlOrig = "";
  123.             CorrelazioneApplicativa ca = pde.getCorrelazioneApplicativa();
  124.             CorrelazioneApplicativaElemento cae = null;
  125.             // Quando esco dal ciclo, cae รจ il mio elemento
  126.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  127.                 cae = ca.getElemento(i);
  128.                 if (idcorr == cae.getId().intValue()) {
  129.                     elemxmlOrig = cae.getNome();
  130.                     break;
  131.                 }
  132.             }
  133.             if (elemxmlOrig == null || "".equals(elemxmlOrig))
  134.                 elemxmlOrig = CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI;

  135.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  136.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  137.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  138.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  139.             Parameter pNomePorta = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME, nomePorta);
  140.            
  141.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  142.            
  143.             String labelPerPorta = null;
  144.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  145.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  146.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  147.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRACCIAMENTO,
  148.                         pde);
  149.             }
  150.             else {
  151.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nomePorta;
  152.             }
  153.             lstParam.add(new Parameter(labelPerPorta,
  154.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA, pId,pIdSoggetto,pIdAsps,pIdFrizione, pNomePorta));
  155.            
  156.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_RICHIESTA_DI, // + nome,
  157.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST_LIST,pId,pIdSoggetto,pIdAsps,pIdFrizione, pNomePorta));
  158.            
  159.             lstParam.add(new Parameter(elemxmlOrig , null));
  160.             // Se idhid = null, devo visualizzare la pagina per la
  161.             // modifica dati
  162.             if (porteDelegateHelper.isEditModeInProgress()) {
  163.                 // setto la barra del titolo
  164.                 ServletUtils.setPageDataTitle(pd, lstParam);
  165.                
  166.                 if (elemxml == null) {
  167.                     elemxml = StringEscapeUtils.escapeHtml(cae.getNome());
  168.                 }
  169.                 if (mode == null &&
  170.                     cae.getIdentificazione()!=null) {
  171.                     mode = cae.getIdentificazione().toString();
  172.                 }
  173.                 if (pattern == null) {
  174.                     pattern = StringEscapeUtils.escapeHtml(cae.getPattern());
  175.                 }
  176.                 if (gif == null &&
  177.                     cae.getIdentificazioneFallita()!=null) {
  178.                     gif = cae.getIdentificazioneFallita().toString();
  179.                 }
  180.                 if (riusoIdMessaggio == null &&
  181.                     cae.getRiusoIdentificativo()!=null) {
  182.                     riusoIdMessaggio = cae.getRiusoIdentificativo().toString();
  183.                 }


  184.                 // preparo i campi
  185.                 List<DataElement> dati = new ArrayList<>();
  186.                
  187.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  188.                
  189.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  190.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  191.                
  192.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaRequestToDati(TipoOperazione.CHANGE, pd,  
  193.                         elemxmlOrig, mode, pattern, gif, riusoIdMessaggio, dati, idcorrString, protocollo, apc.getServiceBinding());

  194.                 pd.setDati(dati);

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

  196.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST,
  197.                         ForwardParams.CHANGE());

  198.             }

  199.             // Controlli sui campi immessi
  200.             boolean isOk = porteDelegateHelper.correlazioneApplicativaRichiestaCheckData(TipoOperazione.CHANGE,true,
  201.                     serviceBinding);
  202.             if (!isOk) {
  203.                 // setto la barra del titolo
  204.                 ServletUtils.setPageDataTitle(pd, lstParam);

  205.                 // preparo i campi
  206.                 List<DataElement> dati = new ArrayList<>();
  207.                
  208.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  209.                
  210.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  211.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  212.                
  213.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaRequestToDati(TipoOperazione.CHANGE, pd,
  214.                         elemxmlOrig, mode, pattern, gif, riusoIdMessaggio, dati, idcorrString, protocollo, apc.getServiceBinding());

  215.                 pd.setDati(dati);

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

  217.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST,
  218.                         ForwardParams.CHANGE());
  219.             }

  220.             // Modifico i dati della correlazione applicativa della porta
  221.             // delegata
  222.             // nel db
  223.             CorrelazioneApplicativaElemento caeNew=null;
  224.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  225.                 cae = ca.getElemento(i);
  226.                 if (idcorr == cae.getId().intValue()) {
  227.                     //ca.removeElemento(i);
  228.                     caeNew = cae;
  229.                     break;
  230.                 }
  231.             }
  232.             if(caeNew==null) {
  233.                 throw new Exception("CorrelazioneApplicativaElemento con id '"+idcorr+"' non trovata");
  234.             }
  235.                        
  236.             if(CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI.equals(elemxml)) {
  237.                 caeNew.setNome(null);
  238.             }
  239.             else {
  240.                 caeNew.setNome(StringEscapeUtils.unescapeHtml(elemxml));
  241.             }
  242.             caeNew.setIdentificazione(CorrelazioneApplicativaRichiestaIdentificazione.toEnumConstant(mode));
  243.             if (mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  244.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  245.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  246.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  247.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  248.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE)) {
  249.                 caeNew.setPattern(StringEscapeUtils.unescapeHtml(pattern));
  250.             }
  251.             if(!PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  252.                 caeNew.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  253.                 caeNew.setRiusoIdentificativo(StatoFunzionalita.toEnumConstant(riusoIdMessaggio));
  254.             }
  255.             //ca.addElemento(caeNew); l'elemento e' stato modificato per riferimento
  256.             pde.setCorrelazioneApplicativa(ca);

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

  258.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

  261.             List<CorrelazioneApplicativaElemento> lista = porteDelegateCore.porteDelegateCorrelazioneApplicativaList(idInt, ricerca);

  262.             porteDelegateHelper.preparePorteDelegateCorrAppList(nomePorta, ricerca, lista);

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

  264.             // Forward control to the specified success URI
  265.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST,
  266.                     ForwardParams.CHANGE());
  267.         } catch (Exception e) {
  268.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  269.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST,
  270.                     ForwardParams.CHANGE());
  271.         }  
  272.     }
  273. }