PorteApplicativeConnettoriMultipliConfigProprietaAdd.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.Proprieta;
  33. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  39. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniCostanti;
  40. import org.openspcoop2.web.lib.mvc.Costanti;
  41. import org.openspcoop2.web.lib.mvc.DataElement;
  42. import org.openspcoop2.web.lib.mvc.ForwardParams;
  43. import org.openspcoop2.web.lib.mvc.GeneralData;
  44. import org.openspcoop2.web.lib.mvc.PageData;
  45. import org.openspcoop2.web.lib.mvc.Parameter;
  46. import org.openspcoop2.web.lib.mvc.ServletUtils;
  47. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  48. /**
  49.  * PorteApplicativeConnettoriMultipliConfigProprietaAdd
  50.  *
  51.  * @author Andrea Poli (apoli@link.it)
  52.  * @author Giuliano Pintori (pintori@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  *
  56.  */
  57. public final class PorteApplicativeConnettoriMultipliConfigProprietaAdd extends Action {

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

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

  61.         // Inizializzo PageData
  62.         PageData pd = new PageData();

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

  64.         // Inizializzo GeneralData
  65.         GeneralData gd = generalHelper.initGeneralData(request);

  66.         try {
  67.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  69.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  70.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  71.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  72.             int idInt = Integer.parseInt(idPorta);
  73.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  74.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_PROP);
  75.             String valore = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE);
  76.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  81.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  82.             // Preparo il menu
  83.             porteApplicativeHelper.makeMenu();

  84.             // Prendo nome della porta applicativa
  85.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  86.             String nomePorta = pa.getNome();
  87.             long idAspsLong = Long.parseLong(idAsps);
  88.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idAspsLong);
  89.            
  90.             Parameter pIdPorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta);
  91.             Parameter pNomePorta = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME, nomePorta);
  92.             Parameter pIdSogg = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg);
  93.             Parameter pIdAsps = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps);
  94.             String accessoDaAPSParametro = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS);
  95.             Parameter pAccessoDaAPS = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONNETTORE_DA_LISTA_APS, accessoDaAPSParametro != null ? accessoDaAPSParametro : "");
  96.             String connettoreAccessoGruppi = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI);
  97.             Parameter pConnettoreAccessoDaGruppi = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_GRUPPI, connettoreAccessoGruppi);
  98.             String connettoreRegistro = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO);
  99.             Parameter pConnettoreRegistro = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_REGISTRO, connettoreRegistro);
  100.             String connettoreAccessoCM = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_LISTA_CONNETTORI_MULTIPLI);
  101.             Parameter pConnettoreAccessoCM = new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CONNETTORE_ACCESSO_DA_LISTA_CONNETTORI_MULTIPLI, connettoreAccessoCM);
  102.            
  103.             boolean accessoDaListaAPS = false;
  104.             if(Costanti.CHECK_BOX_ENABLED_TRUE.equals(accessoDaAPSParametro)) {
  105.                 accessoDaListaAPS = true;
  106.             }
  107.            
  108.             boolean isModalitaCompleta = porteApplicativeHelper.isModalitaCompleta();
  109.             Boolean vistaErogazioni = ServletUtils.getBooleanAttributeFromSession(ErogazioniCostanti.ASPS_EROGAZIONI_ATTRIBUTO_VISTA_EROGAZIONI, session, request).getValue();
  110.             // setto la barra del titolo
  111.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  112.            
  113.             String labelPerPorta = null;
  114.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  115.                 if(accessoDaListaAPS) {
  116.                     if(!isModalitaCompleta) {
  117.                         if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  118.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG;
  119.                         } else {
  120.                             labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_DI+
  121.                                     porteApplicativeHelper.getLabelIdServizio(asps);
  122.                         }
  123.                     }
  124.                     else {
  125.                         labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG;
  126.                     }
  127.                 }
  128.                 else {
  129.                     labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  130.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_DI,
  131.                             PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG,
  132.                             pa);
  133.                 }
  134.             }
  135.             else {
  136.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_DI+nomePorta;
  137.             }
  138.            
  139.             if(accessoDaListaAPS) {
  140.                 lstParam.remove(lstParam.size()-1);
  141.             }
  142.            
  143.             lstParam.add(new Parameter(labelPerPorta,PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONFIGURAZIONE_CONNETTORI_MULTIPLI, pIdSogg, pIdPorta, pIdAsps,
  144.                     pConnettoreAccessoDaGruppi, pConnettoreRegistro, pConnettoreAccessoCM));
  145.            
  146.             String labelPagLista = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPRIETA;
  147.            
  148.             List<Parameter> listaParametriServletProprietaCustom = new ArrayList<>();
  149.             listaParametriServletProprietaCustom.add(pIdSogg);
  150.             listaParametriServletProprietaCustom.add(pIdPorta);
  151.             listaParametriServletProprietaCustom.add(pNomePorta);
  152.             listaParametriServletProprietaCustom.add(pIdAsps);
  153.             listaParametriServletProprietaCustom.add(pAccessoDaAPS);
  154.             listaParametriServletProprietaCustom.add(pConnettoreAccessoDaGruppi);
  155.             listaParametriServletProprietaCustom.add(pConnettoreRegistro);
  156.             listaParametriServletProprietaCustom.add(pConnettoreAccessoCM);
  157.             lstParam.add(new Parameter(labelPagLista, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPERTIES_LIST,   listaParametriServletProprietaCustom.toArray(new Parameter[listaParametriServletProprietaCustom.size()])));
  158.            
  159.            
  160.             lstParam.add(ServletUtils.getParameterAggiungi());

  161.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  162.             // l'inserimento dati
  163.             if (porteApplicativeHelper.isEditModeInProgress()) {
  164.                 // setto la barra del titolo
  165.                 ServletUtils.setPageDataTitle(pd, lstParam);

  166.                 // preparo i campi
  167.                 List<DataElement> dati = new ArrayList<>();
  168.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  169.                 dati = porteApplicativeHelper.addProprietaConnettoriMultipliConfigToDati(dati, TipoOperazione.ADD, nome, valore,PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPRIETA);
  170.                
  171.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  172.                 pd.setDati(dati);

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

  174.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPERTIES,
  175.                         ForwardParams.ADD());
  176.             }

  177.             // Controlli sui campi immessi
  178.             boolean isOk = porteApplicativeHelper.proprietaConnettoriMultipliConfigCheckData(TipoOperazione.ADD, idPorta, nome, valore);
  179.             if (!isOk) {
  180.                
  181.                 // setto la barra del titolo
  182.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  185.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  186.                
  187.                 dati = porteApplicativeHelper.addProprietaConnettoriMultipliConfigToDati(dati, TipoOperazione.ADD, nome, valore,PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPRIETA);
  188.                
  189.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  190.                 pd.setDati(dati);

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

  192.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPERTIES,
  193.                         ForwardParams.ADD());
  194.             }

  195.             // Inserisco il ruolo nel db
  196.            
  197.            
  198.             Proprieta prop = new Proprieta();
  199.             prop.setNome(nome);
  200.             prop.setValore(valore);
  201.             pa.getBehaviour().addProprieta(prop);

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

  203.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  206.             int idLista = Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPRIETA;

  207.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  208.            
  209.             List<Proprieta> lista = porteApplicativeCore.porteApplicativeConnettoriMultipliConfigPropList(idInt, ricerca);

  210.             porteApplicativeHelper.preparePorteApplicativeConnettoriMultipliConfigPropList(nomePorta, ricerca, lista);

  211.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  212.             // Forward control to the specified success URI
  213.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPERTIES,
  214.                     ForwardParams.ADD());
  215.         } catch (Exception e) {
  216.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  217.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI_CONFIG_PROPERTIES,
  218.                     ForwardParams.ADD());
  219.         }
  220.     }
  221.    
  222. }