ConfigurazioneCanaliNodiAdd.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.  * ConfigurazioneCanaliNodiAdd
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  *
  54.  */
  55. public final class ConfigurazioneCanaliNodiAdd extends Action {

  56.    

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

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

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

  62.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  66.         try {
  67.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
  68.            
  69.             String idNodoS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_ID_NODO);
  70.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_NOME);
  71.             String descrizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_DESCRIZIONE);
  72.             String [] canali = confHelper.getParameterValues(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NODI_CANALI);
  73.            
  74.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  75.             Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  76.             CanaliConfigurazione gestioneCanali = configurazioneGenerale.getGestioneCanali();
  77.             List<CanaleConfigurazione> canaleList = gestioneCanali != null ? gestioneCanali.getCanaleList() : new ArrayList<>();

  78.             // Preparo il menu
  79.             confHelper.makeMenu();
  80.             List<Parameter> lstParam = new ArrayList<>();
  81.             // setto la barra del titolo
  82.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  83.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_CANALI_NODI, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_CANALI_NODI_LIST));
  84.             lstParam.add(ServletUtils.getParameterAggiungi());
  85.             ServletUtils.setPageDataTitle(pd, lstParam);
  86.            
  87.             List<String> aliases = confCore.getJmxPdDAliases();
  88.             boolean selectListNode = false;
  89.             if(aliases!=null && aliases.size()>1){
  90.                 selectListNode = true;
  91.             }
  92.             if(selectListNode) {
  93.                 if(gestioneCanali.sizeNodoList()>0) {
  94.                     for (CanaleConfigurazioneNodo confNodo : gestioneCanali.getNodoList()) {
  95.                         if(aliases.contains(confNodo.getNome())) {
  96.                             aliases.remove(confNodo.getNome());
  97.                         }
  98.                     }
  99.                 }
  100.                 if(aliases.isEmpty()) {
  101.                     pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_CANALI_NODI_TUTTI_REGISTRATI, MessageType.INFO);
  102.                    
  103.                     pd.disableEditMode();

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

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

  106.                     pd.setDati(dati);

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

  108.                     return ServletUtils.getStrutsForwardEditModeCheckError(mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  109.                             ForwardParams.ADD());
  110.                 }
  111.             }

  112.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  113.             // dati
  114.             if (confHelper.isEditModeInProgress()) {
  115.                
  116.                 if(nome == null) {
  117.                     nome = "";
  118.                     descrizione = "";
  119.                     canali = new String[0];
  120.                 }
  121.                
  122.                 // preparo i campi
  123.                 List<DataElement> dati = new ArrayList<>();
  124.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  125.                 dati = confHelper.addCanaleNodoToDati(TipoOperazione.ADD, dati, idNodoS, null, nome, descrizione, canali, canaleList,
  126.                         selectListNode, aliases);

  127.                 pd.setDati(dati);

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

  129.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  130.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  131.                         ForwardParams.ADD());
  132.             }

  133.             // Controlli sui campi immessi
  134.             boolean isOk = confHelper.canaleNodoCheckData(TipoOperazione.ADD, null);
  135.             if (!isOk) {

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

  138.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  139.                
  140.                 dati = confHelper.addCanaleNodoToDati(TipoOperazione.ADD, dati, idNodoS, null,nome, descrizione, canali, canaleList,
  141.                         selectListNode, aliases);
  142.                
  143.                 pd.setDati(dati);

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

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

  149.             // rileggo la configurazione
  150.             configurazioneGenerale = confCore.getConfigurazioneGenerale();
  151.            
  152.             if(configurazioneGenerale.getGestioneCanali() == null) // non dovrebbe mai essere null...
  153.                 configurazioneGenerale.setGestioneCanali(new CanaliConfigurazione());
  154.            
  155.             // salvataggio nodo
  156.             CanaleConfigurazioneNodo nodo = new CanaleConfigurazioneNodo();
  157.             nodo.setNome(nome);
  158.             nodo.setDescrizione(descrizione);
  159.             if(nodo.getCanaleList() == null)
  160.                 nodo.setCanaleList(new ArrayList<>());
  161.            
  162.             for(String canale : canali) {
  163.                 nodo.getCanaleList().add(canale);
  164.             }
  165.            
  166.             configurazioneGenerale.getGestioneCanali().addNodo(nodo);
  167.            
  168.             confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);
  169.            
  170.             // Preparo la lista
  171.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  172.             int idLista = Liste.CONFIGURAZIONE_CANALI_NODI;

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

  174.             List<CanaleConfigurazioneNodo> lista = confCore.canaleNodoConfigurazioneList(ricerca);
  175.            
  176.             confHelper.prepareCanaleNodoConfigurazioneList(ricerca, lista);
  177.                        
  178.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

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

  180.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  181.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI,
  182.                     ForwardParams.ADD());
  183.         } catch (Exception e) {
  184.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  185.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI_NODI, ForwardParams.ADD());
  186.         }
  187.     }


  188. }