ConfigurazioneTracciamentoAppenderPropertiesChange.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.  * tracciamentoAppenderPropChange
  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 ConfigurazioneTracciamentoAppenderPropertiesChange 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 idprop = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID_PROPRIETA);
  70.             int idPropInt = Integer.parseInt(idprop);
  71.             String valore = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE);

  72.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

  75.             // Prendo l'appender
  76.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  77.             Tracciamento t = newConfigurazione.getTracciamento();
  78.             OpenspcoopAppender oa = null;
  79.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  80.                 oa = t.getOpenspcoopAppender(j);
  81.                 if (idInt == oa.getId().intValue()) {
  82.                     break;
  83.                 }
  84.             }
  85.             Property oap = null;
  86.             for (int i = 0; i < oa.sizePropertyList(); i++) {
  87.                 oap = oa.getProperty(i);
  88.                 if (idPropInt == oap.getId().intValue()) {
  89.                     break;
  90.                 }
  91.             }

  92.             // Se idhid = null, devo visualizzare la pagina per la
  93.             // modifica 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_TRACCIAMENTO,
  100.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  101.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  102.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES_LIST,
  103.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  104.                         ));
  105.                 lstParam.add(new Parameter(oap.getNome(), null));

  106.                 ServletUtils.setPageDataTitle(pd, lstParam);

  107.                 // Prendo i dati dal db
  108.                 String nome = oap.getNome();
  109.                 valore = oap.getValore();

  110.                 // preparo i campi
  111.                 List<DataElement> dati = new ArrayList<>();
  112.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  113.                 DataElement dataElement = new DataElement();
  114.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  115.                 dataElement.setType(DataElementType.TITLE);
  116.                 dati.add(dataElement);
  117.                
  118.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, nome, valore,false);    

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

  120.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);

  121.                 pd.setDati(dati);

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

  123.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  124.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES,
  125.                         ForwardParams.CHANGE());
  126.             }

  127.             // Controlli sui campi immessi
  128.             boolean isOk = confHelper.tracciamentoAppenderPropCheckData(TipoOperazione.CHANGE);
  129.             if (!isOk) {
  130.                 // setto la barra del titolo
  131.                 List<Parameter> lstParam = new ArrayList<>();

  132.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  133.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  134.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI,
  135.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_LIST));
  136.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  137.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES_LIST,
  138.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  139.                         ));
  140.                 lstParam.add(new Parameter(oap.getNome(), null));

  141.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  145.                 DataElement dataElement = new DataElement();
  146.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  147.                 dataElement.setType(DataElementType.TITLE);
  148.                 dati.add(dataElement);
  149.                
  150.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, oap.getNome(), valore,false);

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

  152.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);

  153.                 pd.setDati(dati);

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

  155.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  156.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES,
  157.                         ForwardParams.CHANGE());
  158.             }

  159.             // Modifico i dati della property nel db
  160.             for (int k = 0; k < oa.sizePropertyList(); k++) {
  161.                 Property tmpOap = oa.getProperty(k);
  162.                 if (idPropInt == tmpOap.getId().intValue()) {
  163.                     oa.removeProperty(k);
  164.                     break;
  165.                 }
  166.             }

  167.             Property newOap = new Property();
  168.             newOap.setNome(oap.getNome());
  169.             newOap.setValore(valore);
  170.             oa.addProperty(newOap);

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

  172.             // Preparo la lista
  173.             newConfigurazione = confCore.getConfigurazioneGenerale();
  174.             t = newConfigurazione.getTracciamento();
  175.             oa = null;
  176.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  177.                 oa = t.getOpenspcoopAppender(j);
  178.                 if (idInt == oa.getId().intValue()) {
  179.                     break;
  180.                 }
  181.             }

  182.             if(oa==null) {
  183.                 throw new Exception("Appender non trovato");
  184.             }
  185.            
  186.             confHelper.prepareTracciamentoAppenderPropList(oa, oa.getPropertyList());

  187.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  188.            
  189.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  190.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  191.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES,
  192.                     ForwardParams.CHANGE());
  193.         } catch (Exception e) {
  194.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  195.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_APPENDER_PROPERTIES, ForwardParams.CHANGE());
  196.         }
  197.     }
  198. }