PorteDelegateCorrelazioneApplicativaResponseAdd.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.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.PortaDelegata;
  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.  * porteDelegateCorrAppRispostaAdd
  53.  *
  54.  * @author Andrea Poli (apoli@link.it)
  55.  * @author $Author$
  56.  * @version $Rev$, $Date$
  57.  *
  58.  */
  59. public final class PorteDelegateCorrelazioneApplicativaResponseAdd 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  70.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  71.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  72.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;

  73.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  74.             int idInt = Integer.parseInt(id);
  75.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  76.             String elemxml = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ELEMENTO_XML);
  77.             String mode = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE);
  78.             if (mode == null) {
  79.                 mode = PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED;
  80.             }
  81.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  82.             String gif = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_IDENTIFICAZIONE_FALLITA);

  83.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  84.             if(idAsps == null)
  85.                 idAsps = "";
  86.            
  87.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  88.             if(idFruizione == null)
  89.                 idFruizione = "";
  90.            
  91.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore( );
  92.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  93.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  94.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

  95.             // Preparo il menu
  96.             porteDelegateHelper.makeMenu();

  97.             // Prendo il nome della porta delegata
  98.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  99.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  100.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  101.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  102.             String nome = pde.getNome();

  103.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pde.getTipoSoggettoProprietario());
  104.            
  105.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  106.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  107.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  108.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  109.             Parameter pNome = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME, nome);
  110.            
  111.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  112.            
  113.             String labelPerPorta = null;
  114.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  115.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  116.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI,
  117.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_TRACCIAMENTO,
  118.                         pde);
  119.             }
  120.             else {
  121.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_CONFIG_DI+nome;
  122.             }
  123.             lstParam.add(new Parameter(labelPerPorta,
  124.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA, pId,pIdSoggetto,pIdAsps,pIdFrizione, pNome));
  125.            
  126.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CORRELAZIONI_APPLICATIVE_RISPOSTA_DI, // + nome,
  127.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE_LIST,pId,pIdSoggetto,pIdAsps,pIdFrizione, pNome));
  128.            
  129.             lstParam.add(ServletUtils.getParameterAggiungi());
  130.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  131.             // dati
  132.             if (porteDelegateHelper.isEditModeInProgress()) {
  133.                 // setto la barra del titolo
  134.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  138.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  139.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  140.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaResponseToDati(TipoOperazione.ADD,
  141.                         pd,   elemxml, mode, pattern, gif,  dati, null, apc.getServiceBinding(),
  142.                         protocollo);

  143.                 pd.setDati(dati);

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

  145.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  146.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE, ForwardParams.ADD());

  147.             }

  148.             // Controlli sui campi immessi
  149.             boolean isOk = porteDelegateHelper.correlazioneApplicativaRispostaCheckData(TipoOperazione.ADD,true,
  150.                     serviceBinding);
  151.             if (!isOk) {
  152.                 // setto la barra del titolo
  153.                 ServletUtils.setPageDataTitle(pd, lstParam);
  154.                
  155.                 // preparo i campi
  156.                 List<DataElement> dati = new ArrayList<>();

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

  158.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  159.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  160.                 dati = porteDelegateHelper.addPorteDelegateCorrelazioneApplicativaResponseToDati(TipoOperazione.ADD,
  161.                         pd,  elemxml, mode, pattern, gif,  dati, null, apc.getServiceBinding(),
  162.                         protocollo);

  163.                 pd.setDati(dati);

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

  165.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  166.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_RESPONSE,
  167.                         ForwardParams.ADD());
  168.             }

  169.             // Inserisco la correlazione applicativa nel db
  170.             CorrelazioneApplicativaRispostaElemento cae = new CorrelazioneApplicativaRispostaElemento();
  171.             cae.setNome(elemxml);
  172.             cae.setIdentificazione(CorrelazioneApplicativaRispostaIdentificazione.toEnumConstant(mode));
  173.             if (mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_URL_BASED) ||
  174.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_HEADER_BASED) ||
  175.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED) ||
  176.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_TEMPLATE) ||
  177.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_FREEMARKER_TEMPLATE) ||
  178.                     mode.equals(PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_VELOCITY_TEMPLATE)) {
  179.                 cae.setPattern(pattern);
  180.             }

  181.             if(!PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  182.                 cae.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  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.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

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

  195.             porteDelegateHelper.preparePorteDelegateCorrAppRispostaList(nome, ricerca, lista);

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