ConfigurazioneDumpAppenderPropertiesAdd.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.Property;
  33. import org.openspcoop2.core.config.Dump;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  37. import org.openspcoop2.web.lib.mvc.DataElement;
  38. import org.openspcoop2.web.lib.mvc.DataElementType;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.Parameter;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  45. /**
  46.  * ConfigurazioneDumpAppenderPropertiesAdd
  47.  *
  48.  * @author Andrea Poli (apoli@link.it)
  49.  * @author Giuliano Pintori (pintori@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  *
  53.  */
  54. public final class ConfigurazioneDumpAppenderPropertiesAdd 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.             long idLong = Long.parseLong(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 l'appender
  74.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  75.             Dump t = newConfigurazione.getDump();
  76.             OpenspcoopAppender oa = null;
  77.             String oldTipo = null;
  78.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  79.                 oa = t.getOpenspcoopAppender(j);
  80.                 if (idLong == oa.getId().longValue()) {
  81.                     oldTipo = oa.getTipo();
  82.                     break;
  83.                 }
  84.             }

  85.             if(oa==null) {
  86.                 throw new Exception("Appender non trovato");
  87.             }
  88.             if(oldTipo==null) {
  89.                 throw new Exception("Appender 'oldTipo' non trovato");
  90.             }
  91.            
  92.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  93.             // dati
  94.             if (confHelper.isEditModeInProgress()) {
  95.                 // setto la barra del titolo
  96.                 List<Parameter> lstParam = new ArrayList<>();

  97.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  98.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  99.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_DUMP,
  100.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  101.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  102.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_PROPERTIES_LIST,
  103.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  104.                         ));
  105.                 lstParam.add(ServletUtils.getParameterAggiungi());

  106.                 ServletUtils.setPageDataTitle(pd, lstParam);

  107.                 // preparo i campi
  108.                 List<DataElement> dati = new ArrayList<>();
  109.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  110.                 DataElement dataElement = new DataElement();
  111.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  112.                 dataElement.setType(DataElementType.TITLE);
  113.                 dati.add(dataElement);
  114.                
  115.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, "", "", false);

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

  117.                 pd.setDati(dati);

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

  119.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  120.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER_PROPERTIES,
  121.                         ForwardParams.ADD());
  122.             }

  123.             // Controlli sui campi immessi
  124.             boolean isOk = confHelper.dumpAppenderPropCheckData(TipoOperazione.ADD);
  125.             if (!isOk) {
  126.                 // setto la barra del titolo
  127.                 List<Parameter> lstParam = new ArrayList<>();

  128.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  129.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  130.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_DUMP,
  131.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  132.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  133.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_PROPERTIES_LIST,
  134.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  135.                         ));
  136.                 lstParam.add(ServletUtils.getParameterAggiungi());

  137.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  141.                 DataElement dataElement = new DataElement();
  142.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  143.                 dataElement.setType(DataElementType.TITLE);
  144.                 dati.add(dataElement);
  145.                
  146.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, nome, valore, false);

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

  148.                 pd.setDati(dati);

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

  150.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  151.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DUMP_APPENDER_PROPERTIES,
  152.                         ForwardParams.ADD());
  153.             }

  154.             // Inserisco la proprietà nel db
  155.             Property oap = new Property();
  156.             oap.setNome(nome);
  157.             oap.setValore(valore);
  158.             oa.addProperty(oap);

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

  160.             // Preparo la lista
  161.             newConfigurazione = confCore.getConfigurazioneGenerale();
  162.             t = newConfigurazione.getDump();
  163.             oa = null;
  164.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  165.                 oa = t.getOpenspcoopAppender(j);
  166.                 if (oldTipo.equals(oa.getTipo())) {
  167.                     break;
  168.                 }
  169.             }

  170.             if(oa==null) {
  171.                 throw new Exception("Appender non trovato");
  172.             }
  173.            
  174.             confHelper.prepareDumpAppenderPropList(oa, oa.getPropertyList());

  175.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  176.            
  177.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

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