ConfigurazioneCanaliDel.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.commons.Liste;
  31. import org.openspcoop2.core.config.CanaleConfigurazione;
  32. import org.openspcoop2.core.config.CanaliConfigurazione;
  33. import org.openspcoop2.core.config.Configurazione;
  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.  * ConfigurazioneCanaliDel
  45.  *
  46.  * @author Giuliano Pintori (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazioneCanaliDel 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 objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  64.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  65.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  66.             Long id = null;

  67.             // Prendo l'accesso registro
  68.             Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  69.             CanaliConfigurazione gestioneCanali = configurazioneGenerale.getGestioneCanali();
  70.            
  71.             StringBuilder inUsoMessage = new StringBuilder();
  72.            
  73.             for (int i = 0; i < idsToRemove.size(); i++) {

  74.                 id = Long.parseLong(idsToRemove.get(i));

  75.                 for (int j = 0; j < gestioneCanali.sizeCanaleList(); j++) {
  76.                     CanaleConfigurazione canale = gestioneCanali.getCanale(j);
  77.                     if (canale.getId().longValue() == id.longValue()) {
  78.                         if(!canale.isCanaleDefault()) { // canale di default non si puo' eliminare
  79.                             // calcolo utilizzo canale
  80.                             //Non sarĂ  possibil eliminare un canale se utilizzato:
  81.                             //  - in un nodo (vedi lista successiva)
  82.                             //  - assegnato ad una API, ad una erogazione o ad una fruizione
  83.                            
  84.                             boolean deleteCanale = ConfigurazioneCanaliUtilities.deleteCanale(canale, userLogin, confCore, confHelper, inUsoMessage,
  85.                                     org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  86.                             if(deleteCanale) {
  87.                                 gestioneCanali.removeCanale(j);
  88.                             }
  89.                         }
  90.                         else {
  91.                             inUsoMessage.append("Canale '"+canale.getNome()+"' non eliminabile essendo quello di default");
  92.                             inUsoMessage.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  93.                             inUsoMessage.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  94.                         }
  95.                     }
  96.                 }
  97.             }
  98.            
  99.             if (inUsoMessage.length()>0) {
  100.                 pd.setMessage(inUsoMessage.toString());
  101.             }

  102.             confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);

  103.             // Preparo il menu
  104.             confHelper.makeMenu();

  105.            
  106.             // Preparo la lista
  107.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  108.             int idLista = Liste.CONFIGURAZIONE_CANALI;

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

  110.             List<CanaleConfigurazione> lista = confCore.canaleConfigurazioneList(ricerca);
  111.            
  112.             confHelper.prepareCanaleConfigurazioneList(ricerca, lista);
  113.                
  114.             if (inUsoMessage.length() == 0)  {
  115.                 pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  116.             }
  117.            
  118.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  119.             // Forward control to the specified success URI
  120.             return ServletUtils.getStrutsForward (mapping,
  121.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI,
  122.                     ForwardParams.DEL());
  123.         } catch (Exception e) {
  124.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  125.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI, ForwardParams.DEL());
  126.         }
  127.     }
  128. }