PorteDelegateCorrelazioneApplicativaResponseChange.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.CorrelazioneApplicativaRisposta;
  32. import org.openspcoop2.core.config.CorrelazioneApplicativaRispostaElemento;
  33. import org.openspcoop2.core.config.PortaDelegata;
  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.  * porteDelegateCorrAppRispostaChange
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  *
  60.  */
  61. public final class PorteDelegateCorrelazioneApplicativaResponseChange 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  72.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  73.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  74.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;

  75.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  76.             int idInt = Integer.parseInt(id);
  77.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);

  78.             String elemxml = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ELEMENTO_XML);
  79.             if(elemxml!=null)
  80.                 elemxml = StringEscapeUtils.escapeHtml(elemxml);

  81.             String mode = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE);

  82.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  83.             if(pattern!=null)
  84.                 pattern = StringEscapeUtils.escapeHtml(pattern);

  85.             String idcorrString = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_CORRELAZIONE);
  86.             int idcorr = Integer.parseInt(idcorrString);
  87.             String gif = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_IDENTIFICAZIONE_FALLITA);
  88.            
  89.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  90.             if(idAsps == null)
  91.                 idAsps = "";
  92.            
  93.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  94.             if(idFruizione == null)
  95.                 idFruizione = "";
  96.            
  97.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  98.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  99.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

  100.             // Preparo il menu
  101.             porteDelegateHelper.makeMenu();

  102.             // Prendo il nome della porta delegata
  103.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  104.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  105.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  106.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  107.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  108.             String nomePorta = pde.getNome();

  109.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());
  110.            
  111.             // Prendo il nome originario della correlazione applicativa
  112.             String elemxmlOrig = "";
  113.             CorrelazioneApplicativaRisposta ca = pde.getCorrelazioneApplicativaRisposta();
  114.             CorrelazioneApplicativaRispostaElemento cae = null;
  115.             // Quando esco dal ciclo, cae รจ il mio elemento
  116.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  117.                 cae = ca.getElemento(i);
  118.                 if (idcorr == cae.getId().intValue()) {
  119.                     elemxmlOrig = cae.getNome();
  120.                     break;
  121.                 }
  122.             }
  123.             if (elemxmlOrig == null || "".equals(elemxmlOrig))
  124.                 elemxmlOrig = CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI;

  125.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  126.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  127.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  128.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  129.             Parameter pNomePorta = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME, nomePorta);
  130.            
  131.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  132.            
  133.             String labelPerPorta = null;
  134.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  135.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  136.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  137.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRACCIAMENTO,
  138.                         pde);
  139.             }
  140.             else {
  141.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nomePorta;
  142.             }
  143.             lstParam.add(new Parameter(labelPerPorta,
  144.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA, pId,pIdSoggetto,pIdAsps,pIdFrizione, pNomePorta));
  145.            
  146.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_RISPOSTA_DI, // + nome,
  147.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE_LIST,pId,pIdSoggetto,pIdAsps,pIdFrizione, pNomePorta));
  148.            
  149.             lstParam.add(new Parameter(elemxmlOrig , null));
  150.            
  151.             // Se idhid = null, devo visualizzare la pagina per la
  152.             // modifica dati
  153.             if( porteDelegateHelper.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.                 // preparo i campi
  171.                 List<DataElement> dati = new ArrayList<>();

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

  173.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  174.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  175.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaResponseToDati(TipoOperazione.CHANGE,
  176.                         pd,  elemxml, mode, pattern, gif, dati, idcorrString, apc.getServiceBinding(),
  177.                         protocollo);

  178.                 pd.setDati(dati);

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

  180.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  181.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE, ForwardParams.CHANGE());

  182.             }

  183.             // Controlli sui campi immessi
  184.             boolean isOk = porteDelegateHelper.correlazioneApplicativaRispostaCheckData(TipoOperazione.CHANGE,true,
  185.                     serviceBinding);
  186.             if (!isOk) {
  187.                 // setto la barra del titolo
  188.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  192.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  193.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  194.                
  195.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaResponseToDati(TipoOperazione.CHANGE,
  196.                         pd,   elemxml, mode, pattern, gif, dati, idcorrString, apc.getServiceBinding(),
  197.                         protocollo);

  198.                 pd.setDati(dati);

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

  200.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  201.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  202.                         ForwardParams.CHANGE());
  203.             }

  204.             // Modifico i dati della correlazione applicativa della porta
  205.             // delegata
  206.             // nel db
  207.             CorrelazioneApplicativaRispostaElemento caeNew=null;
  208.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  209.                 cae = ca.getElemento(i);
  210.                 if (idcorr == cae.getId().intValue()) {
  211.                     caeNew = cae;
  212.                     break;
  213.                 }
  214.             }
  215.             if(caeNew==null) {
  216.                 throw new Exception("CorrelazioneApplicativaRispostaElemento con id '"+idcorr+"' non trovata");
  217.             }

  218.             if(CostantiControlStation.LABEL_PORTE_CORRELAZIONE_APPLICATIVA_QUALSIASI.equals(elemxml)) {
  219.                 caeNew.setNome(null);
  220.             }
  221.             else {
  222.                 caeNew.setNome(StringEscapeUtils.unescapeHtml(elemxml));
  223.             }
  224.             caeNew.setIdentificazione(CorrelazioneApplicativaRispostaIdentificazione.toEnumConstant(mode));
  225.             if (mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  226.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  227.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  228.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  229.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  230.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE)) {
  231.                 caeNew.setPattern(StringEscapeUtils.unescapeHtml(pattern));
  232.             }
  233.             if(!PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  234.                 caeNew.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  235.             }
  236.             //ca.addElemento(caeNew); l'elemento e' stato modificato per riferimento
  237.             pde.setCorrelazioneApplicativaRisposta(ca);

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

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

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

  242.             List<CorrelazioneApplicativaRispostaElemento> lista = porteDelegateCore.porteDelegateCorrelazioneApplicativaRispostaList(idInt, ricerca);

  243.             porteDelegateHelper.preparePorteDelegateCorrAppRispostaList(nomePorta, ricerca, lista);

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

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