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

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

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

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

  58.         // Inizializzo PageData
  59.         PageData pd = new PageData();

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

  61.         // Inizializzo GeneralData
  62.         GeneralData gd = generalHelper.initGeneralData(request);

  63.         //  String userLogin = ServletUtils.getUserLoginFromSession(session);  

  64.         try {
  65.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  66.             String ruoloPortaParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_RUOLO_PORTA);
  67.             RuoloPolicy ruoloPorta = null;
  68.             if(ruoloPortaParam!=null) {
  69.                 ruoloPorta = RuoloPolicy.toEnumConstant(ruoloPortaParam);
  70.             }
  71.             String nomePorta = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_NOME_PORTA);
  72.             ServiceBinding serviceBinding = null;
  73.             String serviceBindingParam = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_RATE_LIMITING_POLICY_GLOBALI_LINK_SERVICE_BINDING);
  74.             if(serviceBindingParam!=null && !"".equals(serviceBindingParam)) {
  75.                 serviceBinding = ServiceBinding.valueOf(serviceBindingParam);
  76.             }
  77.            
  78.             String idTab = confHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  79.             if(!confHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  80.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  81.             }
  82.            
  83.             String cambiaPosizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_POLICY_ACTIVE_POSIZIONE);
  84.            
  85.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  86.            
  87.             int idLista = Liste.CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY;
  88.            
  89.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  90.            
  91.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  92.                
  93.                 String idPolicyS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_POLICY_ID);
  94.                 long idPolicyLong = Long.parseLong(idPolicyS);
  95.                 String risorsaPolicy = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONTROLLO_TRAFFICO_POLICY_RISORSA);
  96.                
  97.                 ConsoleSearch ricercaPerRisorsa = new ConsoleSearch(true);
  98.                 ricercaPerRisorsa.addFilter(idLista, Filtri.FILTRO_TIPO_RISORSA_POLICY, risorsaPolicy);
  99.                 List<AttivazionePolicy> lista = confCore.attivazionePolicyList(ricercaPerRisorsa, ruoloPorta, nomePorta);

  100.                 if(lista != null && !lista.isEmpty()) {
  101.                     AttivazionePolicy regolaToMove = null;
  102.                     int index = 0;
  103.                     for (int i = 0; i < lista.size(); i++) {
  104.                         if(lista.get(i).getId().longValue() == idPolicyLong) {
  105.                             regolaToMove = lista.get(i);
  106.                             index = i;
  107.                             break;
  108.                         }
  109.                     }
  110.                    
  111.                     AttivazionePolicy regolaToSwitch = null; // se arrivo qua dovrebbe esistere sempre, e' la grafica che me lo assicura
  112.                     if(cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU)) {
  113.                         if(index>0) {
  114.                             regolaToSwitch = lista.get((index-1));
  115.                         }
  116.                     }
  117.                     else {
  118.                         if(index<(lista.size()-1)) {
  119.                             regolaToSwitch = lista.get((index+1));
  120.                         }
  121.                     }
  122.                    
  123.                     if(regolaToMove!=null && regolaToSwitch!=null) {
  124.                         int posizioneAttuale = regolaToMove.getPosizione();
  125.                         regolaToMove.setPosizione(regolaToSwitch.getPosizione());
  126.                         regolaToSwitch.setPosizione(posizioneAttuale);
  127.                        
  128.                         List<Object> list = new ArrayList<>();
  129.                         list.add(regolaToMove);
  130.                         list.add(regolaToSwitch);
  131.                         confCore.performUpdateOperation(userLogin, confHelper.smista(), list.toArray(new Object[1]));
  132. //                      if(CostantiControlStation.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_POLICY) {
  133. //                          pd.setMessage(CostantiControlStation.MESSAGGIO_CONFERMA_REGOLA_POLICY_SPOSTATA_CORRETTAMENTE, MessageType.INFO);
  134. //                      }
  135.                        
  136.                         String msgCompletato = confHelper.eseguiResetJmx(TipoOperazione.CHANGE, ruoloPorta, nomePorta);
  137.                         if(msgCompletato!=null && !"".equals(msgCompletato)){
  138.                             pd.setMessage(msgCompletato,Costanti.MESSAGE_TYPE_INFO);
  139.                         }
  140.                     }
  141.                        
  142.                 }
  143.             }
  144.            
  145.            
  146.             // Preparo il menu
  147.             confHelper.makeMenu();

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

  150.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);
  151.            
  152.             List<TipoRisorsaPolicyAttiva> listaTipoRisorsa =
  153.                     confHelper.gestisciCriteriFiltroRisorsaPolicy(ricerca, ruoloPorta, nomePorta);
  154.            
  155.             List<AttivazionePolicy> lista = confCore.attivazionePolicyList(ricerca, ruoloPorta, nomePorta);
  156.            
  157.             confHelper.prepareAttivazionePolicyList(ricerca, lista, listaTipoRisorsa,
  158.                     idLista, ruoloPorta, nomePorta, serviceBinding);
  159.            
  160.             // salvo l'oggetto ricerca nella sessione
  161.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  162.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  163.            
  164.             // Forward control to the specified success URI
  165.             return ServletUtils.getStrutsForward (mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY,
  166.                     ForwardParams.LIST());
  167.         } catch (Exception e) {
  168.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  169.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CONTROLLO_TRAFFICO_ATTIVAZIONE_POLICY, ForwardParams.LIST());
  170.         }  
  171.     }
  172.    
  173. }