ConfigurazioneDumpAppenderPropertiesChange.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.  * ConfigurazioneDumpAppenderPropertiesChange
  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 ConfigurazioneDumpAppenderPropertiesChange 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.             int idInt = Integer.parseInt(id);
  68.             String idprop = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID_PROPRIETA);
  69.             int idPropInt = Integer.parseInt(idprop);
  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.             Dump t = newConfigurazione.getDump();
  77.             OpenspcoopAppender oa = null;
  78.             String oldTipo = null;
  79.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  80.                 oa = t.getOpenspcoopAppender(j);
  81.                 if (idInt == oa.getId().intValue()) {
  82.                     oldTipo = oa.getTipo();
  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.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  99.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  100.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_APPENDER_MESSAGGI_DIAGNOSTICI,
  101.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_LIST));
  102.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + oa.getTipo(),
  103.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_DUMP_APPENDER_PROPERTIES_LIST,
  104.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, oa.getId()+"")
  105.                         ));
  106.                 lstParam.add(new Parameter(oap.getNome(), null));

  107.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

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

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

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

  122.                 pd.setDati(dati);

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

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

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

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

  142.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

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

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

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

  154.                 pd.setDati(dati);

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

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

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

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

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

  173.             // Preparo la lista
  174.             newConfigurazione = confCore.getConfigurazioneGenerale();
  175.             t = newConfigurazione.getDump();
  176.             oa = null;
  177.             for (int j = 0; j < t.sizeOpenspcoopAppenderList(); j++) {
  178.                 oa = t.getOpenspcoopAppender(j);
  179.                 if (oldTipo.equals(oa.getTipo()))  {
  180.                     break;
  181.                 }
  182.             }

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

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

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