ConfigurazioneTracciamentoAppenderPropertiesAdd.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.Tracciamento;
  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.  * tracciamentoAppenderPropAdd
  47.  *
  48.  * @author Andrea Poli (apoli@link.it)
  49.  * @author Stefano Corallo (corallo@link.it)
  50.  * @author Sandra Giangrandi (sandra@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  *
  54.  */
  55. public final class ConfigurazioneTracciamentoAppenderPropertiesAdd extends Action {

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

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

  59.         // Inizializzo PageData
  60.         PageData pd = new PageData();

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

  62.         // Inizializzo GeneralData
  63.         GeneralData gd = generalHelper.initGeneralData(request);

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

  65.         try {
  66.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  67.             String id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  68.             int idInt = Integer.parseInt(id);
  69.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME);
  70.             String valore = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE);

  71.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  72.             // Preparo il menu
  73.             confHelper.makeMenu();

  74.             // Prendo l'appender
  75.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  76.             Tracciamento t = newConfigurazione.getTracciamento();
  77.             OpenspcoopAppender oa = null;
  78.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  79.                 oa = t.getOpenspcoopAppender(j);
  80.                 if (idInt == oa.getId().intValue()) {
  81.                     break;
  82.                 }
  83.             }

  84.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  85.             // dati
  86.             if (confHelper.isEditModeInProgress()) {
  87.                 // setto la barra del titolo
  88.                 List<Parameter> lstParam = new ArrayList<>();

  89.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  90.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  91.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_TRACCIAMENTO,
  92.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  93.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  94.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES_LIST,
  95.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  96.                         ));
  97.                 lstParam.add(ServletUtils.getParameterAggiungi());

  98.                 ServletUtils.setPageDataTitle(pd, lstParam);

  99.                 // preparo i campi
  100.                 List<DataElement> dati = new ArrayList<>();
  101.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  102.                 DataElement dataElement = new DataElement();
  103.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  104.                 dataElement.setType(DataElementType.TITLE);
  105.                 dati.add(dataElement);
  106.                
  107.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, "", "", false);

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

  109.                 pd.setDati(dati);

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

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

  115.             // Controlli sui campi immessi
  116.             boolean isOk = confHelper.tracciamentoAppenderPropCheckData(TipoOperazione.ADD);
  117.             if (!isOk) {
  118.                 // setto la barra del titolo
  119.                 List<Parameter> lstParam = new ArrayList<>();

  120.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  121.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  122.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_TRACCIAMENTO,
  123.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  124.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  125.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES_LIST,
  126.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  127.                         ));
  128.                 lstParam.add(ServletUtils.getParameterAggiungi());

  129.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  133.                 DataElement dataElement = new DataElement();
  134.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  135.                 dataElement.setType(DataElementType.TITLE);
  136.                 dati.add(dataElement);
  137.                
  138.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.ADD, dati, nome, valore, false);

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

  140.                 pd.setDati(dati);

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

  142.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  143.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES,
  144.                         ForwardParams.ADD());
  145.             }

  146.             // Inserisco la proprietà nel db
  147.             Property oap = new Property();
  148.             oap.setNome(nome);
  149.             oap.setValore(valore);
  150.             oa.addProperty(oap);

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

  152.             // Preparo la lista
  153.             newConfigurazione = confCore.getConfigurazioneGenerale();
  154.             t = newConfigurazione.getTracciamento();
  155.             oa = null;
  156.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  157.                 oa = t.getOpenspcoopAppender(j);
  158.                 if (idInt == oa.getId().intValue()) {
  159.                     break;
  160.                 }
  161.             }

  162.             if(oa==null) {
  163.                 throw new Exception("Appender non trovato");
  164.             }
  165.            
  166.             confHelper.prepareTracciamentoAppenderPropList(oa, oa.getPropertyList());

  167.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  168.            
  169.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  170.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  171.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES,
  172.                     ForwardParams.ADD());
  173.         } catch (Exception e) {
  174.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  175.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES, ForwardParams.ADD());
  176.         }
  177.     }
  178. }