ConfigurazioneCanaliAdd.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.servlet.GeneralHelper;
  37. import org.openspcoop2.web.lib.mvc.Costanti;
  38. import org.openspcoop2.web.lib.mvc.DataElement;
  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.Parameter;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

  54.    

  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.            
  67.             String idCanaleS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_ID_CANALE);
  68.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_NOME);
  69.             String descrizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CANALI_DESCRIZIONE);

  70.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  71.             // Preparo il menu
  72.             confHelper.makeMenu();
  73.             List<Parameter> lstParam = new ArrayList<>();
  74.            
  75.             // setto la barra del titolo
  76.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  77.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_CANALI, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_CANALI_LIST));
  78.             lstParam.add(ServletUtils.getParameterAggiungi());
  79.             ServletUtils.setPageDataTitle(pd, lstParam);

  80.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  81.             // dati
  82.             if (confHelper.isEditModeInProgress()) {
  83.                
  84.                 if(nome == null) {
  85.                     nome = "";
  86.                     descrizione = "";
  87.                 }
  88.                
  89.                 // preparo i campi
  90.                 List<DataElement> dati = new ArrayList<>();
  91.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  92.                 dati = confHelper.addCanaleToDati(TipoOperazione.ADD, dati, idCanaleS, nome, descrizione);

  93.                 pd.setDati(dati);

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

  95.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  96.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI,
  97.                         ForwardParams.ADD());
  98.             }

  99.             // Controlli sui campi immessi
  100.             boolean isOk = confHelper.canaleCheckData(TipoOperazione.ADD, null);
  101.             if (!isOk) {

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

  104.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  105.                
  106.                 dati = confHelper.addCanaleToDati(TipoOperazione.ADD, dati, idCanaleS, nome, descrizione);
  107.                
  108.                 pd.setDati(dati);

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

  110.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  111.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI,
  112.                         ForwardParams.ADD());
  113.             }

  114.             // rileggo la configurazione
  115.             Configurazione configurazioneGenerale = confCore.getConfigurazioneGenerale();
  116.            
  117.             if(configurazioneGenerale.getGestioneCanali() == null) // non dovrebbe mai essere null...
  118.                 configurazioneGenerale.setGestioneCanali(new CanaliConfigurazione());
  119.            
  120.             // salvataggio canale
  121.             CanaleConfigurazione canale = new CanaleConfigurazione();
  122.             canale.setNome(nome);
  123.             canale.setDescrizione(descrizione);
  124.             canale.setCanaleDefault(false);
  125.            
  126.             configurazioneGenerale.getGestioneCanali().addCanale(canale);
  127.            
  128.             confCore.performUpdateOperation(userLogin, confHelper.smista(), configurazioneGenerale);
  129.            
  130.             // Preparo la lista
  131.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  132.             int idLista = Liste.CONFIGURAZIONE_CANALI;

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

  134.             List<CanaleConfigurazione> lista = confCore.canaleConfigurazioneList(ricerca);
  135.            
  136.             confHelper.prepareCanaleConfigurazioneList(ricerca, lista);
  137.                        
  138.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

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

  140.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  141.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI,
  142.                     ForwardParams.ADD());
  143.         } catch (Exception e) {
  144.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  145.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_CANALI, ForwardParams.ADD());
  146.         }
  147.     }


  148. }