ConfigurazioneRegistriAdd.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.config.AccessoRegistro;
  31. import org.openspcoop2.core.config.AccessoRegistroRegistro;
  32. import org.openspcoop2.core.config.constants.RegistroTipo;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  37. import org.openspcoop2.web.lib.mvc.DataElement;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.Parameter;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;
  43. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  44. /**
  45.  * registriAdd
  46.  *
  47.  * @author Andrea Poli (apoli@link.it)
  48.  * @author Stefano Corallo (corallo@link.it)
  49.  * @author Sandra Giangrandi (sandra@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  *
  53.  */
  54. public final class ConfigurazioneRegistriAdd 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 nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME);
  67.             String location = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_LOCATION);
  68.             String tipo = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_TIPO);
  69.             if (tipo == null) {
  70.                 tipo = ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_XML;
  71.             }
  72.             String utente = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_UTENTE);
  73.             String password = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PW);
  74.             String confpw = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONFERMA_PW);

  75.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  76.             // Preparo il menu
  77.             confHelper.makeMenu();

  78.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  79.             // dati
  80.             if (confHelper.isEditModeInProgress()) {
  81.                 // setto la barra del titolo
  82.                 List<Parameter> lstParam = new ArrayList<>();

  83.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  84.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_REGISTRO,
  85.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI));
  86.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_REGISTRI,
  87.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_REGISTRI_LIST));
  88.                 lstParam.add(ServletUtils.getParameterAggiungi());

  89.                 ServletUtils.setPageDataTitle(pd, lstParam);

  90.                 // preparo i campi
  91.                 List<DataElement> dati = new ArrayList<>();
  92.                 dati.add(ServletUtils.getDataElementForEditModeFinished());


  93.                 dati = confHelper.addRegistroToDati(TipoOperazione.ADD, nome != null ? nome : "", location != null ? location : "",
  94.                         tipo,"","","", dati);

  95.                 pd.setDati(dati);

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

  97.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  98.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  99.                         ForwardParams.ADD());
  100.             }

  101.             // Controlli sui campi immessi
  102.             boolean isOk = confHelper.registriCheckData(TipoOperazione.ADD);
  103.             if (!isOk) {
  104.                 // setto la barra del titolo
  105.                 List<Parameter> lstParam = new ArrayList<>();

  106.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  107.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_REGISTRO,
  108.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI));
  109.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_REGISTRI,
  110.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_REGISTRI_LIST));
  111.                 lstParam.add(ServletUtils.getParameterAggiungi());

  112.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  115.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  116.                
  117.                 dati = confHelper.addRegistroToDati(TipoOperazione.ADD,nome, location, tipo, utente, password,
  118.                         confpw, dati);

  119.                 pd.setDati(dati);

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

  121.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  122.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  123.                         ForwardParams.ADD());
  124.             }

  125.             // Inserisco il registro nel db
  126.             AccessoRegistro ar = confCore.getAccessoRegistro();
  127.             AccessoRegistroRegistro arr = new AccessoRegistroRegistro();
  128.             arr.setNome(nome);
  129.             arr.setLocation(location);
  130.             arr.setTipo(RegistroTipo.toEnumConstant(tipo));
  131.             if (tipo.equals(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_UDDI)) {
  132.                 arr.setUser(utente);
  133.                 arr.setPassword(password);
  134.             }
  135.             ar.addRegistro(arr);

  136.             confCore.performUpdateOperation(userLogin, confHelper.smista(), ar);

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

  139.             List<AccessoRegistroRegistro> lista = confCore.registriList(ricerca);

  140.             confHelper.prepareRegistriList(ricerca, lista);

  141.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ACCESSO_REGISTRO_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  142.            
  143.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  144.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  145.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  146.                     ForwardParams.ADD());
  147.         } catch (Exception e) {
  148.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  149.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI, ForwardParams.ADD());
  150.         }
  151.     }


  152. }