ConfigurazioneDiagnosticaAppenderPropertiesDel.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 javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import javax.servlet.http.HttpSession;

  25. import org.apache.struts.action.Action;
  26. import org.apache.struts.action.ActionForm;
  27. import org.apache.struts.action.ActionForward;
  28. import org.apache.struts.action.ActionMapping;
  29. import org.openspcoop2.core.config.Configurazione;
  30. import org.openspcoop2.core.config.MessaggiDiagnostici;
  31. import org.openspcoop2.core.config.OpenspcoopAppender;
  32. import org.openspcoop2.core.config.Property;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.Utilities;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  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.ServletUtils;

  41. /**
  42.  * diagnosticaAppenderPropDel
  43.  *
  44.  * @author Andrea Poli (apoli@link.it)
  45.  * @author Stefano Corallo (corallo@link.it)
  46.  * @author Sandra Giangrandi (sandra@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazioneDiagnosticaAppenderPropertiesDel extends Action {

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

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

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         GeneralHelper generalHelper = new GeneralHelper(session);

  58.         // Inizializzo GeneralData
  59.         GeneralData gd = generalHelper.initGeneralData(request);

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

  61.         try {
  62.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  63.             String id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  64.             int idInt = Integer.parseInt(id);
  65.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  66.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  67.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  68.             int idPropInt = 0;

  69.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  70.             MessaggiDiagnostici md = newConfigurazione.getMessaggiDiagnostici();
  71.             OpenspcoopAppender oa = null;
  72.             for (int j = 0; j < md.sizeOpenspcoopAppenderList(); j++) {
  73.                 oa = md.getOpenspcoopAppender(j);
  74.                 if (idInt == oa.getId().intValue()) {
  75.                     break;
  76.                 }
  77.             }

  78.             for (int i = 0; i < idsToRemove.size(); i++) {

  79.                 idPropInt = Integer.parseInt(idsToRemove.get(i));

  80.                 for (int j = 0; j < oa.sizePropertyList(); j++) {
  81.                     Property oap = oa.getProperty(j);
  82.                     if (idPropInt == oap.getId().intValue()) {
  83.                         oa.removeProperty(j);
  84.                     }
  85.                 }
  86.             }

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

  88.             // Preparo il menu
  89.             confHelper.makeMenu();

  90.             // Preparo la lista
  91.             newConfigurazione = confCore.getConfigurazioneGenerale();
  92.             md = newConfigurazione.getMessaggiDiagnostici();
  93.             oa = null;
  94.             for (int j = 0; j < md.sizeOpenspcoopAppenderList(); j++) {
  95.                 oa = md.getOpenspcoopAppender(j);
  96.                 if (idInt == oa.getId().intValue()) {
  97.                     break;
  98.                 }
  99.             }

  100.             if(oa==null) {
  101.                 throw new Exception("Appender non trovato");
  102.             }
  103.            
  104.             confHelper.prepareDiagnosticaAppenderPropList(oa, oa.getPropertyList());

  105.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_APPENDER_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  106.            
  107.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  108.             // Forward control to the specified success URI
  109.             return ServletUtils.getStrutsForward (mapping,
  110.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES,
  111.                     ForwardParams.DEL());
  112.         } catch (Exception e) {
  113.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  114.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_DIAGNOSTICA_APPENDER_PROPERTIES, ForwardParams.DEL());
  115.         }
  116.     }
  117. }