ConfigurazioneControlloTrafficoAttivazionePolicyDel.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.controllo_traffico.AttivazionePolicy;
  32. import org.openspcoop2.core.controllo_traffico.constants.RuoloPolicy;
  33. import org.openspcoop2.core.controllo_traffico.constants.TipoRisorsaPolicyAttiva;
  34. import org.openspcoop2.message.constants.ServiceBinding;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.core.Utilities;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.Costanti;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;


  45. /**    
  46.  * ConfigurazioneControlloTrafficoAttivazionePolicyDel
  47.  *
  48.  * @author Pintori Giuliano (pintori@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  */
  52. public class ConfigurazioneControlloTrafficoAttivazionePolicyDel extends Action {

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

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

  64.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  65.             // Preparo il menu
  66.             confHelper.makeMenu();

  67.             String ruoloPortaParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_RUOLO_PORTA);
  68.             RuoloPolicy ruoloPorta = null;
  69.             if(ruoloPortaParam!=null) {
  70.                 ruoloPorta = RuoloPolicy.toEnumConstant(ruoloPortaParam);
  71.             }
  72.             String nomePorta = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_NOME_PORTA);
  73.             ServiceBinding serviceBinding = null;
  74.             String serviceBindingParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_SERVICE_BINDING);
  75.             if(serviceBindingParam!=null && !"".equals(serviceBindingParam)) {
  76.                 serviceBinding = ServiceBinding.valueOf(serviceBindingParam);
  77.             }
  78.            
  79.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  80.             // Elimino i filtri dal db
  81.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  82.             List<AttivazionePolicy> policyDaEliminare = new ArrayList<>();
  83.             StringBuilder inUsoMessage = new StringBuilder();
  84.            
  85.             for (int i = 0; i < idsToRemove.size(); i++) {

  86.                 long idPolicy = Long.parseLong(idsToRemove.get(i));
  87.                 AttivazionePolicy policy = confCore.getAttivazionePolicy(idPolicy);
  88.                
  89.                 policyDaEliminare.add(policy);
  90.                
  91.             }
  92.                
  93.             List<AttivazionePolicy> policyRimosse = new ArrayList<>();
  94.             ConfigurazioneUtilities.deleteAttivazionePolicy(policyDaEliminare, confHelper, confCore, userLogin, inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE, policyRimosse);
  95.            
  96.             String msgCompletato = confHelper.eseguiResetJmx(TipoOperazione.DEL, ruoloPorta, nomePorta);
  97.            
  98.             if(msgCompletato!=null && !"".equals(msgCompletato)){
  99.                 if(inUsoMessage.length()>0){
  100.                     if(!policyRimosse.isEmpty()){
  101.                         msgCompletato = msgCompletato+"<br/><br/>"+inUsoMessage.toString();
  102.                     }
  103.                     else{
  104.                         msgCompletato = inUsoMessage.toString();
  105.                     }
  106.                 }
  107.             }
  108.             else{
  109.                 msgCompletato = inUsoMessage.toString();
  110.             }
  111.             if(msgCompletato!=null && !"".equals(msgCompletato)){
  112.                 if(inUsoMessage.length()>0)
  113.                     pd.setMessage(msgCompletato);
  114.                 else
  115.                     pd.setMessage(msgCompletato,Costanti.MESSAGE_TYPE_INFO);
  116.             }
  117.            

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

  120.             int idLista = Liste.CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY;

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

  122.             List<TipoRisorsaPolicyAttiva> listaTipoRisorsa =
  123.                     confHelper.gestisciCriteriFiltroRisorsaPolicy(ricerca, ruoloPorta, nomePorta);
  124.            
  125.             List<AttivazionePolicy> lista = confCore.attivazionePolicyList(ricerca, ruoloPorta, nomePorta);

  126.             confHelper.prepareAttivazionePolicyList(ricerca, lista, listaTipoRisorsa,
  127.                     idLista, ruoloPorta, nomePorta, serviceBinding);

  128.             // salvo l'oggetto ricerca nella sessione
  129.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  130.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  131.             // Forward control to the specified success URI
  132.             return ServletUtils.getStrutsForward (mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY, ForwardParams.DEL());
  133.         } catch (Exception e) {
  134.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  135.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY, ForwardParams.DEL());
  136.         }  
  137.     }
  138. }