ConfigurazioneDumpAppenderChange.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.  * ConfigurazioneDumpAppenderChange
  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 ConfigurazioneDumpAppenderChange 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 id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  65.             int idInt = Integer.parseInt(id);
  66.             String tipo = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_TIPO);

  67.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

  70.             // Prendo l'appender
  71.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  72.             Dump t = newConfigurazione.getDump();
  73.             OpenspcoopAppender oa = null;
  74.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  75.                 oa = t.getOpenspcoopAppender(j);
  76.                 if (idInt == oa.getId().intValue()) {
  77.                     break;
  78.                 }
  79.             }

  80.             // Se idhid = null, devo visualizzare la pagina per la
  81.             // modifica 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_APPENDER_DUMP ,
  88.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  89.                 lstParam.add(new Parameter(oa.getTipo(), null));

  90.                 ServletUtils.setPageDataTitle(pd, lstParam);

  91.                 // Prendo i dati dal db
  92.                 tipo = oa.getTipo();

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

  96.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  97.                 dati = confHelper.addTipoDumpAppenderToDati(TipoOperazione.CHANGE, oa.getTipo(), dati, oa.getId() + "", oa.sizePropertyList());

  98.                 pd.setDati(dati);

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

  100.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  101.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  102.                         ForwardParams.CHANGE());
  103.             }

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

  109.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  110.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  111.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_DUMP ,
  112.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  113.                 lstParam.add(new Parameter(oa.getTipo(), null));

  114.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  117.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  118.                
  119.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  120.                 dati = confHelper.addTipoDumpAppenderToDati(TipoOperazione.CHANGE, tipo,
  121.                         dati, oa.getId() + "", oa.sizePropertyList());

  122.                 pd.setDati(dati);

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

  124.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  125.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  126.                         ForwardParams.CHANGE());
  127.             }

  128.             // Modifico i dati dell'appender nel db
  129.             for (int i = 0; i < t.sizeOpenspcoopAppenderList(); i++) {
  130.                 OpenspcoopAppender tmpOa = t.getOpenspcoopAppender(i);
  131.                 if (idInt == tmpOa.getId().intValue()) {
  132.                     t.removeOpenspcoopAppender(i);
  133.                     break;
  134.                 }
  135.             }

  136.             OpenspcoopAppender newOa = new OpenspcoopAppender();
  137.             newOa.setTipo(tipo);
  138.             t.addOpenspcoopAppender(newOa);
  139.             newConfigurazione.setDump(t);

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

  141.             // Preparo la lista
  142.             newConfigurazione = confCore.getConfigurazioneGenerale();
  143.             t = newConfigurazione.getDump();

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

  145.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  146.            
  147.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  148.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  149.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER,
  150.                     ForwardParams.CHANGE());
  151.         } catch (Exception e) {
  152.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  153.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER, ForwardParams.CHANGE());
  154.         }
  155.     }
  156. }