ConfigurazionePluginsArchiviJarDel.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.Date;
  23. import java.util.List;

  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.servlet.http.HttpSession;

  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.RegistroPlugin;
  33. import org.openspcoop2.core.config.RegistroPluginArchivio;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.core.Utilities;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  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.ServletUtils;

  43. /**
  44.  * ConfigurazionePluginsArchiviJarDel
  45.  *
  46.  * @author Giuliano Pintori (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazionePluginsArchiviJarDel 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.            
  64.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_NOME);

  65.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  66.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  67.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  68.            
  69.             RegistroPlugin registro = confCore.getDatiRegistroPlugin(nome);

  70.             List<Object> archiviToRemove = new ArrayList<>();
  71.            
  72.             for (int i = 0; i < idsToRemove.size(); i++) {
  73.                 String nomeJar = idsToRemove.get(i);
  74.                 RegistroPluginArchivio archivio = new RegistroPluginArchivio();
  75.                 archivio.setNome(nomeJar);
  76.                 archivio.setNomePlugin(nome);
  77.                 archiviToRemove.add(archivio);
  78.             }

  79.             Object[] oggetti = archiviToRemove.toArray(new RegistroPluginArchivio[archiviToRemove.size()]);
  80.             confCore.performDeleteOperation(userLogin, confHelper.smista(), oggetti);
  81.            
  82.             registro.setData(new Date());
  83.             confCore.performUpdateOperation(userLogin, confHelper.smista(), registro);
  84.            
  85.             // Aggiorno classLoader interno
  86.             confCore.updatePluginClassLoader();

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

  89.            
  90.             // Preparo la lista
  91.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  92.             int idLista = Liste.CONFIGURAZIONE_PLUGINS_ARCHIVI_JAR;

  93.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);
  94.            
  95.             List<RegistroPluginArchivio> lista = confCore.pluginsArchiviJarList(nome, ricerca);  
  96.            
  97.             confHelper.preparePluginsArchiviJarList(nome, ricerca, lista);

  98.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  99.             // Forward control to the specified success URI
  100.             return ServletUtils.getStrutsForward (mapping,
  101.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI_JAR,
  102.                     ForwardParams.DEL());
  103.         } catch (Exception e) {
  104.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  105.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI_JAR, ForwardParams.DEL());
  106.         }
  107.     }
  108. }