ConfigurazioneDumpAppenderPropertiesDel.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.OpenspcoopAppender;
  31. import org.openspcoop2.core.config.Property;
  32. import org.openspcoop2.core.config.Dump;
  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.  * ConfigurazioneDumpAppenderPropertiesDel
  43.  *
  44.  * @author Andrea Poli (apoli@link.it)
  45.  * @author Giuliano Pintori (pintori@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  *
  49.  */
  50. public final class ConfigurazioneDumpAppenderPropertiesDel extends Action {

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

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

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

  56.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

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

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

  67.             int idPropInt = 0;

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

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

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

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

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

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

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

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

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