PorteDelegateCorrelazioneApplicativaRequestAdd.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.CorrelazioneApplicativa;
  31. import org.openspcoop2.core.config.CorrelazioneApplicativaElemento;
  32. import org.openspcoop2.core.config.PortaDelegata;
  33. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaGestioneIdentificazioneFallita;
  34. import org.openspcoop2.core.config.constants.CorrelazioneApplicativaRichiestaIdentificazione;
  35. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  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.ConsoleSearch;
  40. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  41. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  42. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  43. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  44. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  45. import org.openspcoop2.web.lib.mvc.DataElement;
  46. import org.openspcoop2.web.lib.mvc.ForwardParams;
  47. import org.openspcoop2.web.lib.mvc.GeneralData;
  48. import org.openspcoop2.web.lib.mvc.PageData;
  49. import org.openspcoop2.web.lib.mvc.Parameter;
  50. import org.openspcoop2.web.lib.mvc.ServletUtils;
  51. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  52. /**
  53.  * porteDelegateCorrAppAdd
  54.  *
  55.  * @author Andrea Poli (apoli@link.it)
  56.  * @author Stefano Corallo (corallo@link.it)
  57.  * @author Sandra Giangrandi (sandra@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public final class PorteDelegateCorrelazioneApplicativaRequestAdd extends Action {

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

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


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

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  76.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  77.             int idInt = Integer.parseInt(id);
  78.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  79.             String elemxml = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ELEMENTO_XML);
  80.             String mode = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE);
  81.             if (mode == null) {
  82.                 mode = PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_CONTENT_BASED;
  83.             }
  84.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  85.             String gif = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_IDENTIFICAZIONE_FALLITA);
  86.             String riusoIdentificativoMessaggio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RIUSO_ID_MESSAGGIO);
  87.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  88.             if(idAsps == null)
  89.                 idAsps = "";
  90.            
  91.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  92.             if(idFruizione == null)
  93.                 idFruizione = "";
  94.            
  95.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore( );
  96.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  97.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  98.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

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

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

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

  140.                 // preparo i campi
  141.                 List<DataElement> dati = new ArrayList<>();
  142.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

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

  145.                 dati = porteDelegateHelper. addPorteDelegateCorrelazioneApplicativaRequestToDati(TipoOperazione.ADD , pd,  
  146.                         elemxml, mode, pattern, gif, riusoIdentificativoMessaggio, dati, null, protocollo,
  147.                         apc.getServiceBinding());

  148.                 pd.setDati(dati);

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

  150.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST, ForwardParams.ADD());

  151.             }

  152.             // Controlli sui campi immessi
  153.             boolean isOk = porteDelegateHelper.correlazioneApplicativaRichiestaCheckData(TipoOperazione.ADD,true,
  154.                     serviceBinding);
  155.             if (!isOk) {
  156.                 // setto la barra del titolo
  157.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

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

  163.                 dati = porteDelegateHelper. addPorteDelegateCorrelazioneApplicativaRequestToDati(TipoOperazione.ADD, pd,
  164.                         elemxml, mode, pattern, gif, riusoIdentificativoMessaggio, dati, null, protocollo,
  165.                         apc.getServiceBinding());

  166.                 pd.setDati(dati);

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

  168.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CORRELAZIONE_APPLICATIVA_REQUEST,
  169.                         ForwardParams.ADD());
  170.             }

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

  183.             if(!PorteDelegateCostanti.VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_MODE_CORRELAZIONE_DISABILITATO.equals(mode)){
  184.                 cae.setIdentificazioneFallita(CorrelazioneApplicativaGestioneIdentificazioneFallita.toEnumConstant(gif));
  185.                 cae.setRiusoIdentificativo(StatoFunzionalita.toEnumConstant(riusoIdentificativoMessaggio));
  186.             }

  187.             CorrelazioneApplicativa ca = pde.getCorrelazioneApplicativa();
  188.             if (ca == null) {
  189.                 ca = new CorrelazioneApplicativa();
  190.             }
  191.             ca.addElemento(cae);
  192.             pde.setCorrelazioneApplicativa(ca);

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

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

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

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

  198.             porteDelegateHelper.preparePorteDelegateCorrAppList(nome, ricerca, lista);

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

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


  209. }