ConfigurazioneTracciamentoDatasourceAdd.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.config;

  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.config.Configurazione;
  31. import org.openspcoop2.core.config.OpenspcoopSorgenteDati;
  32. import org.openspcoop2.core.config.Tracciamento;
  33. import org.openspcoop2.utils.TipiDatabase;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.PageData;
  40. import org.openspcoop2.web.lib.mvc.Parameter;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;
  42. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  43. /**
  44.  * tracciamentoDatasourceAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class ConfigurazioneTracciamentoDatasourceAdd extends Action {

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

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

  57.         // Inizializzo PageData
  58.         PageData pd = new PageData();

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);

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

  63.         try {
  64.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  65.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME);
  66.             String nomeJndi = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME_JNDI);
  67.             String tipoDatabase = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_TIPO_DATABASE);

  68.             String[] tipiDb = TipiDatabase.toStringArray();
  69.             String[] tipoDbList = new String[tipiDb.length-1];
  70.             int j = 0;
  71.             for (int i = 0; i < tipiDb.length; i++) {
  72.                 if (!tipiDb[i].equals(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_DATABASE_DEFAULT)) {
  73.                     tipoDbList[j] = tipiDb[i];
  74.                     j++;
  75.                 }
  76.             }

  77.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  78.             // Preparo il menu
  79.             confHelper.makeMenu();

  80.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  81.             // dati
  82.             if (confHelper.isEditModeInProgress()) {
  83.                 // setto la barra del titolo
  84.                 List<Parameter> lstParam = new ArrayList<>();

  85.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  86.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  87.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_TRACCIAMENTO,
  88.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_LIST));
  89.                 lstParam.add(ServletUtils.getParameterAggiungi());

  90.                 ServletUtils.setPageDataTitle(pd, lstParam);

  91.                 // preparo i campi
  92.                 List<DataElement> dati = new ArrayList<>();
  93.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  94.                 dati = confHelper.addTracciamentoDatasourceToDati(TipoOperazione.ADD, "", "", null,
  95.                         tipoDbList, dati, null, 0);


  96.                 pd.setDati(dati);

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

  98.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  99.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE,
  100.                         ForwardParams.ADD());
  101.             }

  102.             // Controlli sui campi immessi
  103.             boolean isOk = confHelper.tracciamentoDatasourceCheckData(TipoOperazione.ADD);
  104.             if (!isOk) {
  105.                 // setto la barra del titolo
  106.                 List<Parameter> lstParam = new ArrayList<>();

  107.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  108.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  109.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_TRACCIAMENTO,
  110.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_LIST));
  111.                 lstParam.add(ServletUtils.getParameterAggiungi());
  112.                
  113.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  116.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  117.                
  118.                 dati = confHelper. addTracciamentoDatasourceToDati(TipoOperazione.ADD, nome, nomeJndi, tipoDatabase,
  119.                         tipoDbList, dati, null,0);

  120.                 pd.setDati(dati);

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

  122.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  123.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE,
  124.                         ForwardParams.ADD());
  125.             }

  126.             // Inserisco l'appender nel db
  127.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  128.             Tracciamento t = newConfigurazione.getTracciamento();
  129.             if (t == null)
  130.                 t = new Tracciamento();
  131.             OpenspcoopSorgenteDati od = new OpenspcoopSorgenteDati();
  132.             od.setNome(nome);
  133.             od.setNomeJndi(nomeJndi);
  134.             od.setTipoDatabase(tipoDatabase);
  135.             t.addOpenspcoopSorgenteDati(od);
  136.             newConfigurazione.setTracciamento(t);

  137.             confCore.performUpdateOperation(userLogin, confHelper.smista(), newConfigurazione);

  138.             // Preparo la lista
  139.             newConfigurazione = confCore.getConfigurazioneGenerale();
  140.             t = newConfigurazione.getTracciamento();
  141.             List<OpenspcoopSorgenteDati> lista = t.getOpenspcoopSorgenteDatiList();

  142.             confHelper.prepareTracciamentoDatasourceList(lista);

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

  144.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  145.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE,
  146.                     ForwardParams.ADD());
  147.         } catch (Exception e) {
  148.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  149.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE, ForwardParams.ADD());
  150.         }
  151.     }

  152.    
  153. }