ConfigurazioneDumpAppenderAdd.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.OpenspcoopAppender;
  32. import org.openspcoop2.core.config.Dump;
  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.  * ConfigurazioneDumpAppenderAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public final class ConfigurazioneDumpAppenderAdd extends Action {

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

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

  64.             String tipo = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_TIPO);

  65.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

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

  73.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  74.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  75.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_DUMP ,
  76.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  77.                 lstParam.add(ServletUtils.getParameterAggiungi());

  78.                 ServletUtils.setPageDataTitle(pd, lstParam);

  79.                 // preparo i campi
  80.                 List<DataElement> dati = new ArrayList<>();
  81.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  82.                 dati = confHelper.addTipoDumpAppenderToDati(TipoOperazione.ADD,
  83.                         ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_DUMP, dati, null , 0);

  84.                 pd.setDati(dati);

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

  86.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  87.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  88.                         ForwardParams.ADD());
  89.             }

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

  95.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  96.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  97.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_DUMP ,
  98.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  99.                 lstParam.add(ServletUtils.getParameterAggiungi());

  100.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  103.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  104.                 dati = confHelper.addTipoDumpAppenderToDati(TipoOperazione.ADD,tipo, dati, null , 0);

  105.                 pd.setDati(dati);

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

  107.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  108.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  109.                         ForwardParams.ADD());
  110.             }

  111.             // Inserisco l'appender nel db
  112.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  113.             Dump t = newConfigurazione.getDump();
  114.             if (t == null)
  115.                 t = new Dump();
  116.             OpenspcoopAppender oa = new OpenspcoopAppender();
  117.             oa.setTipo(tipo);
  118.             t.addOpenspcoopAppender(oa);
  119.             newConfigurazione.setDump(t);

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

  121.             // Preparo la lista
  122.             newConfigurazione = confCore.getConfigurazioneGenerale();
  123.             t = newConfigurazione.getDump();

  124.             confHelper.prepareDumpAppenderList(t.getOpenspcoopAppenderList());

  125.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  126.            
  127.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  128.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  129.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  130.                     ForwardParams.ADD());
  131.         } catch (Exception e) {
  132.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  133.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER, ForwardParams.ADD());
  134.         }
  135.     }
  136. }