ConfigurazionePluginsArchiviList.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.commons.lang.StringUtils;
  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.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  36. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.MessageType;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;

  42. /**
  43.  * ConfigurazionePluginsArchiviList
  44.  *
  45.  * @author Giuliano Pintori (pintori@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  *
  49.  */
  50. public final class ConfigurazionePluginsArchiviList 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.         String userLogin = ServletUtils.getUserLoginFromSession(session);

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

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

  62.             String cambiaPosizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_POSIZIONE);
  63.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_NOME);
  64.            
  65.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  66.             // Preparo il menu
  67.             confHelper.makeMenu();
  68.            
  69.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  70.                
  71.                 List<Object> pluginsDaSpostare =new ArrayList<>();
  72.                
  73.                 RegistroPlugin regolaToMove = confCore.getDatiRegistroPlugin(nome);
  74.                
  75.                 int posizioneAttuale = regolaToMove.getPosizione();
  76.                 int posizioneNuova = cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU) ? (posizioneAttuale - 1) : (posizioneAttuale + 1);
  77.                
  78.                 RegistroPlugin regolaToSwitch = confCore.getDatiRegistroPluginFromPosizione(posizioneNuova);
  79.                
  80.                 regolaToMove.setPosizione(posizioneNuova);
  81.                 regolaToSwitch.setPosizione(posizioneAttuale);
  82.                
  83.                 pluginsDaSpostare.add(regolaToMove);
  84.                 pluginsDaSpostare.add(regolaToSwitch);
  85.                
  86.                 confCore.performUpdateOperation(userLogin, confHelper.smista(), pluginsDaSpostare.toArray(new Object[pluginsDaSpostare.size()]));
  87.                 if(CostantiControlStation.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_PLUGINS_ARCHIVI)
  88.                     pd.setMessage(CostantiControlStation.MESSAGGIO_CONFERMA_PLUGINS_ARCHIVIO_SPOSTATO_CORRETTAMENTE, MessageType.INFO);
  89.             }

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

  92.             int idLista = Liste.CONFIGURAZIONE_PLUGINS_ARCHIVI;

  93.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);

  94.             List<RegistroPlugin> lista = confCore.pluginsArchiviList(ricerca);  
  95.            
  96.             confHelper.preparePluginsArchiviList(ricerca, lista);
  97.            
  98.             // salvo l'oggetto ricerca nella sessione
  99.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

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