PorteApplicativeConnettoriMultipliProprietaAdd.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.ArrayList;
  22. import java.util.List;

  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.commons.Liste;
  31. import org.openspcoop2.core.config.PortaApplicativa;
  32. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativo;
  33. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativoConnettore;
  34. import org.openspcoop2.core.config.Proprieta;
  35. import org.openspcoop2.core.config.ProprietaOggetto;
  36. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  37. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.utils.date.DateManager;
  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.aps.AccordiServizioParteSpecificaCore;
  44. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniCostanti;
  45. import org.openspcoop2.web.lib.mvc.Costanti;
  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.  * PorteApplicativeConnettoriMultipliConfigProprietaAdd
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public final class PorteApplicativeConnettoriMultipliProprietaAdd 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.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  73.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  74.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  75.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  76.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  77.             int idInt = Integer.parseInt(idPorta);
  78.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  79.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_PROP);
  80.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE);
  81.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  82.             String nomeSAConnettore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_NOME_SA);
  83.             if(idAsps == null)
  84.                 idAsps = "";
  85.            
  86.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  87.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  88.             // Preparo il menu
  89.             porteApplicativeHelper.makeMenu();

  90.             // Prendo nome della porta applicativa
  91.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  92.             String nomePorta = pa.getNome();
  93.             long idAspsLong = Long.parseLong(idAsps);
  94.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idAspsLong);
  95.            
  96.             PortaApplicativaServizioApplicativo oldPaSA = null;
  97.             for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  98.                 if(paSATmp.getNome().equals(nomeSAConnettore)) {
  99.                     oldPaSA = paSATmp;
  100.                     break;
  101.                 }
  102.             }
  103.             if(oldPaSA==null) {
  104.                 throw new Exception("PortaApplicativaServizioApplicativo con nome '"+nomeSAConnettore+"' non trovato");
  105.             }
  106.            
  107.             long idPaSa = oldPaSA.getId();

  108.             Parameter pIdPorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta);
  109.             Parameter pNomePorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nomePorta);
  110.             Parameter pIdSogg = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg);
  111.             Parameter pIdAsps = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps);
  112.             String accessoDaAPSParametro = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS);
  113.             Parameter pAccessoDaAPS = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS, accessoDaAPSParametro != null ? accessoDaAPSParametro : "");
  114.             String connettoreAccessoGruppi = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI);
  115.             Parameter pConnettoreAccessoDaGruppi = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI, connettoreAccessoGruppi);
  116.             String connettoreRegistro = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO);
  117.             Parameter pConnettoreRegistro = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO, connettoreRegistro);
  118.             String connettoreAccessoCM = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_LISTA_CONNETTORI_MULTIPLI);
  119.             Parameter pConnettoreAccessoCM = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_LISTA_CONNETTORI_MULTIPLI, connettoreAccessoCM);
  120.            
  121.             boolean accessoDaListaAPS = false;
  122.             if(Costanti.CHECK_BOX_ENABLED_TRUE.equals(accessoDaAPSParametro)) {
  123.                 accessoDaListaAPS = true;
  124.             }
  125.            
  126.             boolean isModalitaCompleta = porteApplicativeHelper.isModalitaCompleta();
  127.             Boolean vistaErogazioni = ServletUtils.getBooleanAttributeFromSession(ErogazioniCostanti.ASPS_EROGAZIONI_ATTRIBUTO_VISTA_EROGAZIONI, session, request).getValue();
  128.             // setto la barra del titolo
  129.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  130.            
  131.             String labelPerPorta = null;
  132.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  133.                 if(accessoDaListaAPS) {
  134.                     if(!isModalitaCompleta) {
  135.                         if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  136.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG;
  137.                         } else {
  138.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI+
  139.                                     porteApplicativeHelper.getLabelIdServizio(asps);
  140.                         }
  141.                     }
  142.                     else {
  143.                         labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG;
  144.                     }
  145.                 }
  146.                 else {
  147.                     labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  148.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI,
  149.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG,
  150.                             pa);
  151.                 }
  152.             }
  153.             else {
  154.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_DI+nomePorta;
  155.             }
  156.            
  157.             if(accessoDaListaAPS) {
  158.                 lstParam.remove(lstParam.size()-1);
  159.             }
  160.             List<Parameter> listaParametriServletConnettoriMultipliList = new ArrayList<>();
  161.             listaParametriServletConnettoriMultipliList.add(pIdSogg);
  162.             listaParametriServletConnettoriMultipliList.add(pIdPorta);
  163.             listaParametriServletConnettoriMultipliList.add(pNomePorta);
  164.             listaParametriServletConnettoriMultipliList.add(pIdAsps);
  165.             listaParametriServletConnettoriMultipliList.add(pAccessoDaAPS);
  166.             listaParametriServletConnettoriMultipliList.add(pConnettoreAccessoDaGruppi);
  167.             listaParametriServletConnettoriMultipliList.add(pConnettoreRegistro);
  168.             listaParametriServletConnettoriMultipliList.add(pConnettoreAccessoCM);
  169.            
  170.             lstParam.add(new Parameter(labelPerPorta,  PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_LIST, listaParametriServletConnettoriMultipliList.toArray(new Parameter[1])));

  171.             String labelPagLista =  porteApplicativeHelper.getLabelNomePortaApplicativaServizioApplicativo(
  172.                     PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPRIETA_DI,
  173.                     PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPRIETA,
  174.                     oldPaSA);
  175.            
  176.             List<Parameter> listaParametriServletConnettoriMultipliProprietaList = new ArrayList<>();
  177.             listaParametriServletConnettoriMultipliProprietaList.addAll(listaParametriServletConnettoriMultipliList);
  178.             listaParametriServletConnettoriMultipliProprietaList.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_NOME_SA, nomeSAConnettore));
  179.            
  180.             lstParam.add(new Parameter(labelPagLista, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPERTIES_LIST,  listaParametriServletConnettoriMultipliProprietaList.toArray(new Parameter[listaParametriServletConnettoriMultipliProprietaList.size()])));
  181.            
  182.            
  183.             lstParam.add(ServletUtils.getParameterAggiungi());

  184.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  185.             // l'inserimento dati
  186.             if (porteApplicativeHelper.isEditModeInProgress()) {
  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 = porteApplicativeHelper.addProprietaConnettoriMultipliConfigToDati(dati, TipoOperazione.ADD, nome, valore,PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPRIETA,nomeSAConnettore);
  193.                
  194.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  195.                 pd.setDati(dati);

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

  197.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPERTIES,
  198.                         ForwardParams.ADD());
  199.             }

  200.             // Controlli sui campi immessi
  201.             boolean isOk = porteApplicativeHelper.proprietaConnettoriMultipliCheckData(TipoOperazione.ADD, idPorta, nomeSAConnettore, nome, valore);
  202.             if (!isOk) {
  203.                
  204.                 // setto la barra del titolo
  205.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  208.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  209.                
  210.                 dati = porteApplicativeHelper.addProprietaConnettoriMultipliConfigToDati(dati, TipoOperazione.ADD, nome, valore,PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPRIETA,nomeSAConnettore);
  211.                
  212.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  213.                 pd.setDati(dati);

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

  215.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPERTIES,
  216.                         ForwardParams.ADD());
  217.             }

  218.             // Inserisco il ruolo nel db
  219.             PortaApplicativaServizioApplicativo paSA = null;
  220.             for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  221.                 if(paSATmp.getNome().equals(nomeSAConnettore)) {
  222.                     paSA = paSATmp;    
  223.                     break;
  224.                 }
  225.             }
  226.             if(paSA==null) {
  227.                 throw new Exception("PortaApplicativaServizioApplicativo con nome '"+nomeSAConnettore+"' non trovato");
  228.             }

  229.             PortaApplicativaServizioApplicativoConnettore datiConnettore = paSA.getDatiConnettore();
  230.            
  231.             if(datiConnettore == null) { // succede solo se e' la prima volta che modifico la configurazione di default
  232.                 datiConnettore = new PortaApplicativaServizioApplicativoConnettore();
  233.                 datiConnettore.setNome(CostantiConfigurazione.NOME_CONNETTORE_DEFAULT);
  234.             }
  235.            
  236.             paSA.setDatiConnettore(datiConnettore);
  237.            
  238.             Proprieta prop = new Proprieta();
  239.             prop.setNome(nome);
  240.             prop.setValore(valore);
  241.             datiConnettore.addProprieta(prop);

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

  243.             if(datiConnettore.getProprietaOggetto()==null) {
  244.                 datiConnettore.setProprietaOggetto(new ProprietaOggetto());
  245.             }
  246.             datiConnettore.getProprietaOggetto().setUtenteUltimaModifica(userLogin);
  247.             datiConnettore.getProprietaOggetto().setDataUltimaModifica(DateManager.getDate());
  248.            
  249.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  250.            
  251.             ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI);
  252.            
  253.             pa = porteApplicativeCore.getPortaApplicativa(idInt);
  254.            
  255.             for (PortaApplicativaServizioApplicativo paSATmp : pa.getServizioApplicativoList()) {
  256.                 if(paSATmp.getNome().equals(nomeSAConnettore)) {
  257.                     paSA = paSATmp;    
  258.                     break;
  259.                 }
  260.             }
  261.            
  262.             idPaSa = paSA.getId();

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

  265.             int idLista = Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPRIETA;

  266.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  267.            
  268.             List<Proprieta> lista = porteApplicativeCore.porteApplicativeConnettoriMultipliPropList(idPaSa, ricerca);

  269.             porteApplicativeHelper.preparePorteApplicativeConnettoriMultipliPropList(nomePorta, ricerca, lista);

  270.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  271.             // Forward control to the specified success URI
  272.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPERTIES,
  273.                     ForwardParams.ADD());
  274.         } catch (Exception e) {
  275.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  276.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_PROPERTIES,
  277.                     ForwardParams.ADD());
  278.         }
  279.     }
  280.    
  281. }