ConfigurazioneDiagnosticaDatasourcePropertiesAdd.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.MessaggiDiagnostici;
  32. import org.openspcoop2.core.config.OpenspcoopSorgenteDati;
  33. import org.openspcoop2.core.config.Property;
  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.DataElementType;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.Parameter;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;
  43. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

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

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

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

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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



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

  66.             String id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  67.             int idInt = Integer.parseInt(id);
  68.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME);
  69.             String valore = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE);

  70.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  71.             // Preparo il menu
  72.             confHelper.makeMenu();

  73.             // Prendo il datasource
  74.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  75.             MessaggiDiagnostici md = newConfigurazione.getMessaggiDiagnostici();
  76.             List<OpenspcoopSorgenteDati> lista = md.getOpenspcoopSorgenteDatiList();
  77.             OpenspcoopSorgenteDati od = null;
  78.             for (int j = 0; j < md.sizeOpenspcoopSorgenteDatiList(); j++) {
  79.                 od = lista.get(j);
  80.                 if (idInt == od.getId().intValue()) {
  81.                     break;
  82.                 }
  83.             }

  84.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  85.             // dati
  86.             if (confHelper.isEditModeInProgress()) {
  87.                 // setto la barra del titolo
  88.                 List<Parameter> lstParam = new ArrayList<>();
  89.                
  90.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  91.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  92.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_MESSAGGI_DIAGNOSTICI,
  93.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_LIST));
  94.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + od.getNome(),
  95.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES_LIST,
  96.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, od.getId()+"")
  97.                         ));
  98.                 lstParam.add(ServletUtils.getParameterAggiungi());
  99.                
  100.                 ServletUtils.setPageDataTitle(pd, lstParam);

  101.                 // preparo i campi
  102.                 List<DataElement> dati = new ArrayList<>();
  103.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  104.                 DataElement dataElement = new DataElement();
  105.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  106.                 dataElement.setType(DataElementType.TITLE);
  107.                 dati.add(dataElement);
  108.                
  109.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, "", "",false);

  110.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, null, null, dati);

  111.                 pd.setDati(dati);

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

  113.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  114.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES,
  115.                         ForwardParams.ADD());
  116.             }

  117.             // Controlli sui campi immessi
  118.             boolean isOk = confHelper.diagnosticaDatasourcePropCheckData(TipoOperazione.ADD);
  119.             if (!isOk) {
  120.                 // setto la barra del titolo
  121.                 List<Parameter> lstParam = new ArrayList<>();
  122.                
  123.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  124.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  125.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_MESSAGGI_DIAGNOSTICI,
  126.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_LIST));
  127.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + od.getNome(),
  128.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES_LIST,
  129.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, od.getId()+"")
  130.                         ));
  131.                 lstParam.add(ServletUtils.getParameterAggiungi());
  132.                
  133.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  136.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  137.                
  138.                 DataElement dataElement = new DataElement();
  139.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  140.                 dataElement.setType(DataElementType.TITLE);
  141.                 dati.add(dataElement);
  142.                
  143.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, nome, valore,  false);
  144.                
  145.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, null, null, dati);

  146.                 pd.setDati(dati);

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

  148.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  149.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES,
  150.                         ForwardParams.ADD());
  151.             }

  152.             // Inserisco la proprietà nel db
  153.             Property odp = new Property();
  154.             odp.setNome(nome);
  155.             odp.setValore(valore);
  156.             od.addProperty(odp);

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

  158.             // Preparo la lista
  159.             newConfigurazione = confCore.getConfigurazioneGenerale();
  160.             md = newConfigurazione.getMessaggiDiagnostici();
  161.             lista = md.getOpenspcoopSorgenteDatiList();
  162.             od = null;
  163.             for (int j = 0; j < md.sizeOpenspcoopSorgenteDatiList(); j++) {
  164.                 od = lista.get(j);
  165.                 if (idInt == od.getId().intValue()) {
  166.                     break;
  167.                 }
  168.             }
  169.            
  170.             if(od==null) {
  171.                 throw new Exception("Datasource non trovato");
  172.             }
  173.            
  174.             List<Property> lista1 = od.getPropertyList();

  175.             confHelper.prepareDiagnosticaDatasourcePropList(od, lista1);

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

  177.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  178.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES,
  179.                     ForwardParams.ADD());
  180.         } catch (Exception e) {
  181.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  182.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_DATASOURCE_PROPERTIES, ForwardParams.ADD());
  183.         }
  184.     }
  185. }