ConfigurazioneRegistriChange.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.  * registriChange
  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 ConfigurazioneRegistriChange 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.             String utente = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_UTENTE);
  70.             String password = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PW);
  71.             String confpw = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_CONFERMA_PW);
  72.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  73.             // Preparo il menu
  74.             confHelper.makeMenu();

  75.             // Prendo il registro
  76.             AccessoRegistro ar = confCore.getAccessoRegistro();
  77.             AccessoRegistroRegistro arr = null;
  78.             for (int i = 0; i < ar.sizeRegistroList(); i++) {
  79.                 arr = ar.getRegistro(i);
  80.                 if (nome.equals(arr.getNome())) {
  81.                     break;
  82.                 }
  83.             }

  84.             // Se nomehid = null, devo visualizzare la pagina per la
  85.             // modifica dati
  86.             if (confHelper.isEditModeInProgress()) {
  87.                 // setto la barra del titolo
  88.                 List<Parameter> lstParam = new ArrayList<>();

  89.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  90.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_REGISTRO,
  91.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI));
  92.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_REGISTRI,
  93.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_REGISTRI_LIST));
  94.                 lstParam.add(new Parameter(nome, null));

  95.                 ServletUtils.setPageDataTitle(pd, lstParam);

  96.                 // Prendo i dati dal db solo se non sono stati passati
  97.                 if (location == null) {
  98.                     location = arr.getLocation();
  99.                 }
  100.                 if (tipo == null) {
  101.                     tipo = arr.getTipo().toString();
  102.                 }
  103.                 if (utente == null) {
  104.                     utente = arr.getUser();
  105.                     password = arr.getPassword();
  106.                     confpw = password;
  107.                 }

  108.                 // preparo i campi
  109.                 List<DataElement> dati = new ArrayList<>();
  110.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  111.                 dati = confHelper.addRegistroToDati(TipoOperazione.CHANGE, nome, location, tipo, utente, password, confpw, dati);

  112.                 pd.setDati(dati);

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

  114.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  115.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  116.                         ForwardParams.CHANGE());
  117.             }

  118.             // Controlli sui campi immessi
  119.             boolean isOk = confHelper.registriCheckData(TipoOperazione.CHANGE);
  120.             if (!isOk) {
  121.                 // setto la barra del titolo
  122.                 List<Parameter> lstParam = new ArrayList<>();

  123.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  124.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_REGISTRO,
  125.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI));
  126.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_REGISTRI,
  127.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_REGISTRI_LIST));
  128.                 lstParam.add(new Parameter(nome, null));

  129.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  132.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  133.                
  134.                 dati = confHelper.addRegistroToDati(TipoOperazione.CHANGE, nome, location, tipo, utente, password, confpw, dati);

  135.                 pd.setDati(dati);

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

  137.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  138.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  139.                         ForwardParams.CHANGE());
  140.             }

  141.             // Modifico i dati del registro nel db
  142.             for (int i = 0; i < ar.sizeRegistroList(); i++) {
  143.                 AccessoRegistroRegistro tmpArr = ar.getRegistro(i);
  144.                 if (nome.equals(tmpArr.getNome())) {
  145.                     ar.removeRegistro(i);
  146.                     break;
  147.                 }
  148.             }

  149.             AccessoRegistroRegistro newArr = new AccessoRegistroRegistro();
  150.             newArr.setNome(nome);
  151.             newArr.setLocation(location);
  152.             newArr.setTipo(RegistroTipo.toEnumConstant(tipo));
  153.             if (tipo.equals(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_TIPO_UDDI)) {
  154.                 newArr.setUser(utente);
  155.                 newArr.setPassword(password);
  156.             }
  157.             ar.addRegistro(newArr);

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

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

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

  162.             confHelper.prepareRegistriList(ricerca, lista);

  163.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ACCESSO_REGISTRO_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  164.            
  165.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  166.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  167.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI,
  168.                     ForwardParams.CHANGE());
  169.         } catch (Exception e) {
  170.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  171.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_REGISTRI, ForwardParams.CHANGE());
  172.         }
  173.     }
  174. }