ConfigurazioneCanaliNodiChange.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.CanaleConfigurazioneNodo;
  33. import org.openspcoop2.core.config.CanaliConfigurazione;
  34. import org.openspcoop2.core.config.Configurazione;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.MessageType;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.Parameter;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;
  46. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

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

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

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

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  65.         try {
  66.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
  67.            
  68.             String idNodoS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_ID_NODO);
  69.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_NOME);
  70.             String descrizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_DESCRIZIONE);
  71.             String [] canali = confHelper.getParameterValues(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_CANALI);
  72.            
  73.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  74.             Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  75.             CanaliConfigurazione gestioneCanali = configurazioneGenerale.getGestioneCanali();
  76.             List<CanaleConfigurazione> canaleList = gestioneCanali != null ? gestioneCanali.getCanaleList() : new ArrayList<>();
  77.            
  78.             long idNodo = Long.parseLong(idNodoS);
  79.             CanaleConfigurazioneNodo oldNodo = null;
  80.             String oldNome = null;
  81.             if(configurazioneGenerale.getGestioneCanali() != null) {
  82.                 for (CanaleConfigurazioneNodo nodo : configurazioneGenerale.getGestioneCanali().getNodoList()) {
  83.                     if(nodo.getId().longValue() == idNodo) {
  84.                         oldNodo = nodo;
  85.                         oldNome = nodo.getNome();
  86.                         break;
  87.                     }
  88.                 }
  89.             }
  90.            

  91.             // Preparo il menu
  92.             confHelper.makeMenu();
  93.             List<Parameter> lstParam = new ArrayList<>();
  94.            
  95.             // setto la barra del titolo
  96.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  97.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_CANALI_NODI, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_CANALI_NODI_LIST));
  98.             if(oldNodo!=null) {
  99.                 lstParam.add(new Parameter(oldNodo.getNome(), null));
  100.             }
  101.             ServletUtils.setPageDataTitle(pd, lstParam);

  102.             List<String> aliases = confCore.getJmxPdDAliases();
  103.             boolean selectListNode = false;
  104.             if(aliases!=null && aliases.size()>1){
  105.                 selectListNode = true;
  106.             }
  107.             if(selectListNode) {
  108.                 if(gestioneCanali.sizeNodoList()>0) {
  109.                     for (CanaleConfigurazioneNodo confNodo : gestioneCanali.getNodoList()) {
  110.                         if(!oldNome.equals(confNodo.getNome()) && aliases.contains(confNodo.getNome())) {
  111.                             aliases.remove(confNodo.getNome());
  112.                         }
  113.                     }
  114.                 }
  115.                 if(aliases.isEmpty()) {
  116.                     pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_CANALI_NODI_TUTTI_REGISTRATI, MessageType.INFO);
  117.                    
  118.                     pd.disableEditMode();

  119.                     List<DataElement> dati = new ArrayList<>();

  120.                     dati.add(ServletUtils.getDataElementForEditModeFinished());

  121.                     pd.setDati(dati);

  122.                     ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  123.                     return ServletUtils.getStrutsForwardEditModeCheckError(mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  124.                             ForwardParams.CHANGE());
  125.                 }
  126.             }
  127.            
  128.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  129.             // dati
  130.             if (confHelper.isEditModeInProgress()) {
  131.                
  132.                 if(nome == null) {
  133.                     nome = oldNodo.getNome();
  134.                     descrizione = oldNodo.getDescrizione();
  135.                     canali = oldNodo.getCanaleList().toArray(new String[oldNodo.sizeCanaleList()]);
  136.                 }
  137.                 // preparo i campi
  138.                 List<DataElement> dati = new ArrayList<>();
  139.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  140.                 dati = confHelper.addCanaleNodoToDati(TipoOperazione.CHANGE, dati, idNodoS, oldNome, nome, descrizione, canali, canaleList,
  141.                         selectListNode, aliases);
  142.                
  143.                 pd.setDati(dati);

  144.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  145.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  146.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  147.                         ForwardParams.CHANGE());
  148.             }

  149.             // Controlli sui campi immessi
  150.             boolean isOk = confHelper.canaleNodoCheckData(TipoOperazione.CHANGE, oldNodo.getNome());
  151.             if (!isOk) {

  152.                 // preparo i campi
  153.                 List<DataElement> dati = new ArrayList<>();

  154.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  155.                
  156.                 dati = confHelper.addCanaleNodoToDati(TipoOperazione.CHANGE, dati, idNodoS, oldNome, nome, descrizione, canali, canaleList,
  157.                         selectListNode, aliases);
  158.                
  159.                 pd.setDati(dati);

  160.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  161.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  162.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  163.                         ForwardParams.CHANGE());
  164.             }

  165.             // rileggo la configurazione
  166.             configurazioneGenerale = confCore.getConfigurazioneGenerale();
  167.            
  168.             if(configurazioneGenerale.getGestioneCanali() == null) // non dovrebbe mai essere null...
  169.                 configurazioneGenerale.setGestioneCanali(new CanaliConfigurazione());
  170.            
  171.             // salvataggio regola
  172.             for (CanaleConfigurazioneNodo nodo : configurazioneGenerale.getGestioneCanali().getNodoList()) {
  173.                 if(nodo.getId().longValue() == idNodo) {
  174.                     nodo.setNome(nome);
  175.                     if(descrizione!=null && !"".equals(descrizione)) {
  176.                         nodo.setDescrizione(descrizione);
  177.                     }
  178.                     else {
  179.                         nodo.setDescrizione(null);
  180.                     }
  181.                    
  182.                     nodo.getCanaleList().clear();
  183.                     for(String canale : canali) {
  184.                         nodo.getCanaleList().add(canale);
  185.                     }
  186.                    
  187.                     break;
  188.                 }
  189.             }
  190.            
  191.             confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);
  192.            
  193.             // Preparo la lista
  194.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  195.             int idLista = Liste.CONFIGURAZIONE_CANALI_NODI;

  196.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);
  197.            
  198.             List<CanaleConfigurazioneNodo> lista = confCore.canaleNodoConfigurazioneList(ricerca);
  199.            
  200.             confHelper.prepareCanaleNodoConfigurazioneList(ricerca, lista);

  201.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  202.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  203.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  204.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  205.                     ForwardParams.CHANGE());
  206.         } catch (Exception e) {
  207.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  208.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI, ForwardParams.CHANGE());
  209.         }
  210.     }


  211. }