ConfigurazioneTracciamentoAppenderAdd.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.Tracciamento;
  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.  * tracciamentoAppenderAdd
  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 ConfigurazioneTracciamentoAppenderAdd 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_TRACCIAMENTO ,
  77.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_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.                 dati = confHelper.addTipoTracciamentoAppenderToDati(TipoOperazione.ADD,
  84.                         ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_TRACCIAMENTO, dati, null , 0);

  85.                 pd.setDati(dati);

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

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

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

  96.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  97.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  98.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_TRACCIAMENTO ,
  99.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  100.                 lstParam.add(ServletUtils.getParameterAggiungi());

  101.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  105.                 dati = confHelper.addTipoTracciamentoAppenderToDati(TipoOperazione.ADD,tipo, dati, null , 0);

  106.                 pd.setDati(dati);

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

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

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

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

  122.             // Preparo la lista
  123.             newConfigurazione = confCore.getConfigurazioneGenerale();
  124.             t = newConfigurazione.getTracciamento();

  125.             confHelper.prepareTracciamentoAppenderList(t.getOpenspcoopAppenderList());

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

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