ConfigurazioneDiagnosticaAppenderAdd.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.OpenspcoopAppender;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.lib.mvc.Costanti;
  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.  * diagnosticaAppenderAdd
  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 ConfigurazioneDiagnosticaAppenderAdd 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 tipo = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_TIPO);

  66.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  67.             // Preparo il menu
  68.             confHelper.makeMenu();

  69.             // Se tipo = null, devo visualizzare la pagina per l'inserimento
  70.             // dati
  71.             if (confHelper.isEditModeInProgress()) {
  72.                 // setto la barra del titolo
  73.                 List<Parameter> lstParam = new ArrayList<>();

  74.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  75.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  76.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI ,
  77.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_LIST));
  78.                 lstParam.add(ServletUtils.getParameterAggiungi());

  79.                 ServletUtils.setPageDataTitle(pd, lstParam);

  80.                 // preparo i campi
  81.                 List<DataElement> dati = new ArrayList<>();
  82.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  83.                
  84.                 dati = confHelper.addTipoDiagnosticaAppenderToDati(TipoOperazione.ADD,
  85.                         ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_DIAGNOSTICA, dati, null , 0);

  86.                 pd.setDati(dati);

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

  88.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  89.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER,
  90.                         ForwardParams.ADD());
  91.             }

  92.             // Controlli sui campi immessi
  93.             boolean isOk = confHelper.diagnosticaAppenderCheckData(TipoOperazione.ADD);
  94.             if (!isOk) {
  95.                 // setto la barra del titolo
  96.                 List<Parameter> lstParam = new ArrayList<>();

  97.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  98.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  99.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI ,
  100.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_LIST));
  101.                 lstParam.add(ServletUtils.getParameterAggiungi());

  102.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  105.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  106.                
  107.                 dati = confHelper.addTipoDiagnosticaAppenderToDati (TipoOperazione.ADD,tipo, dati, null , 0);

  108.                 pd.setDati(dati);

  109.      
  110.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  111.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  112.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER,
  113.                         ForwardParams.ADD());
  114.             }

  115.             // Inserisco l'appender nel db
  116.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  117.             MessaggiDiagnostici md = newConfigurazione.getMessaggiDiagnostici();
  118.             if (md == null)
  119.                 md = new MessaggiDiagnostici();
  120.             OpenspcoopAppender oa = new OpenspcoopAppender();
  121.             oa.setTipo(tipo);
  122.             md.addOpenspcoopAppender(oa);
  123.             newConfigurazione.setMessaggiDiagnostici(md);

  124.             confCore.performUpdateOperation(userLogin, confHelper.smista(), newConfigurazione);
  125.            
  126.             // Preparo la lista
  127.             newConfigurazione = confCore.getConfigurazioneGenerale();
  128.             md = newConfigurazione.getMessaggiDiagnostici();
  129.            
  130.             confHelper.prepareDiagnosticaAppenderList(md.getOpenspcoopAppenderList());

  131.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  132.            
  133.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  134.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  135.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER,
  136.                     ForwardParams.ADD());
  137.         } catch (Exception e) {
  138.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  139.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER, ForwardParams.ADD());
  140.         }
  141.     }
  142. }