ConfigurazioneDiagnosticaAppenderPropertiesChange.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.MessaggiDiagnostici;
  32. import org.openspcoop2.core.config.OpenspcoopAppender;
  33. import org.openspcoop2.core.config.Property;
  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.  * diagnosticaAppenderPropChange
  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 ConfigurazioneDiagnosticaAppenderPropertiesChange 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.         // Inizializzo PageData
  61.         PageData pd = new PageData();

  62.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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


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

  68.             String id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  69.             int idInt = Integer.parseInt(id);
  70.             String idprop = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID_PROPRIETA);
  71.             int idPropInt = Integer.parseInt(idprop);
  72.             String valore = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE);

  73.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

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

  93.             // Se idhid = null, devo visualizzare la pagina per la
  94.             // modifica dati
  95.             if (confHelper.isEditModeInProgress()) {
  96.                 // setto la barra del titolo
  97.                 List<Parameter> lstParam = new ArrayList<>();
  98.                
  99.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  100.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  101.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI,
  102.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_LIST));
  103.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  104.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES_LIST,
  105.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  106.                         ));
  107.                 lstParam.add(new Parameter(oap.getNome(), null));
  108.                
  109.                 ServletUtils.setPageDataTitle(pd, lstParam);


  110.                 // Prendo i dati dal db
  111.                 String nome = oap.getNome();
  112.                 valore = oap.getValore();

  113.                 // preparo i campi
  114.                 List<DataElement> dati = new ArrayList<>();
  115.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  116.                 DataElement dataElement = new DataElement();
  117.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  118.                 dataElement.setType(DataElementType.TITLE);
  119.                 dati.add(dataElement);
  120.                
  121.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, nome, valore,false);
  122.                
  123.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  124.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);
  125.                
  126.                 pd.setDati(dati);

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

  128.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  129.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES,
  130.                         ForwardParams.CHANGE());
  131.             }

  132.             // Controlli sui campi immessi
  133.             boolean isOk = confHelper.diagnosticaAppenderPropCheckData(TipoOperazione.CHANGE);
  134.             if (!isOk) {
  135.                 // setto la barra del titolo
  136.                 List<Parameter> lstParam = new ArrayList<>();
  137.                
  138.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  139.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  140.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI,
  141.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_LIST));
  142.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  143.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES_LIST,
  144.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  145.                         ));
  146.                 lstParam.add(new Parameter(oap.getNome(), null));
  147.                
  148.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  151.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  152.                
  153.                 DataElement dataElement = new DataElement();
  154.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  155.                 dataElement.setType(DataElementType.TITLE);
  156.                 dati.add(dataElement);
  157.                
  158.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, oap.getNome(), valore, false);
  159.                
  160.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  161.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);
  162.                
  163.                 pd.setDati(dati);

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

  165.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  166.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES,
  167.                         ForwardParams.CHANGE());
  168.             }

  169.             // Modifico i dati della property nel db
  170.             for (int k = 0; k < oa.sizePropertyList(); k++) {
  171.                 Property tmpOap = oa.getProperty(k);
  172.                 if (idPropInt == tmpOap.getId().intValue()) {
  173.                     oa.removeProperty(k);
  174.                     break;
  175.                 }
  176.             }

  177.             Property newOap = new Property();
  178.             newOap.setNome(oap.getNome());
  179.             newOap.setValore(valore);
  180.             oa.addProperty(newOap);

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

  182.             // Preparo la lista
  183.             newConfigurazione = confCore.getConfigurazioneGenerale();
  184.             md = newConfigurazione.getMessaggiDiagnostici();
  185.             oa = null;
  186.             for (int j = 0; j < md.sizeOpenspcoopAppenderList(); j++) {
  187.                 oa = md.getOpenspcoopAppender(j);
  188.                 if (idInt == oa.getId().intValue()) {
  189.                     break;
  190.                 }
  191.             }

  192.             if(oa==null) {
  193.                 throw new Exception("Appender non trovato");
  194.             }
  195.            
  196.             confHelper.prepareDiagnosticaAppenderPropList(oa, oa.getPropertyList());

  197.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  198.            
  199.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  200.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  201.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES,
  202.                     ForwardParams.CHANGE());
  203.         } catch (Exception e) {
  204.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  205.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES, ForwardParams.CHANGE());
  206.         }
  207.     }
  208. }