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

  68.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

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

  81.             // Se idhid = null, devo visualizzare la pagina per la
  82.             // modifica dati
  83.             if (confHelper.isEditModeInProgress()) {
  84.                 // setto la barra del titolo
  85.                 List<Parameter> lstParam = new ArrayList<>();

  86.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  87.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  88.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_TRACCIAMENTO ,
  89.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  90.                 lstParam.add(new Parameter(oa.getTipo(), null));

  91.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

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

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

  99.                 pd.setDati(dati);

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

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

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

  110.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  111.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  112.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_TRACCIAMENTO ,
  113.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  114.                 lstParam.add(new Parameter(oa.getTipo(), null));

  115.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

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

  123.                 pd.setDati(dati);

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

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

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

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

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

  142.             // Preparo la lista
  143.             newConfigurazione = confCore.getConfigurazioneGenerale();
  144.             t = newConfigurazione.getTracciamento();

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

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

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