ConfigurazioneSystemPropertiesChange.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.Property;
  32. import org.openspcoop2.core.config.SystemProperties;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.DataElementType;
  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.  * porteDelegateWSRequestChange
  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 ConfigurazioneSystemPropertiesChange 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 id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  67.             int idInt = Integer.parseInt(id);
  68.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_NOME);
  69.             String valore = confHelper.getLockedParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE,false);

  70.             // Wrap value
  71.             valore = confHelper.wrapValoreProprieta(valore);

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

  74.             // Prendo il nome della porta applicativa
  75.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  76.             SystemProperties systemProperties = confCore.getSystemPropertiesPdD();


  77.             // Se valore = null, devo visualizzare la pagina per la
  78.             // modifica dati
  79.             if (confHelper.isEditModeInProgress()) {

  80.                 if(valore==null && systemProperties!=null){
  81.                     for (int i = 0; i < systemProperties.sizeSystemPropertyList(); i++) {
  82.                         Property sp = systemProperties.getSystemProperty(i);
  83.                         if (idInt == sp.getId() ) {
  84.                             nome = sp.getNome();
  85.                             valore = sp.getValore();
  86.                             break;
  87.                         }
  88.                     }
  89.                 }

  90.                 // setto la barra del titolo
  91.                 List<Parameter> lstParam = new ArrayList<>();

  92.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  93.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA,
  94.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_SYSTEM_PROPERTIES_LIST));
  95.                 lstParam.add(new Parameter(nome, null));

  96.                 ServletUtils.setPageDataTitle(pd, lstParam);


  97.                 // preparo i campi
  98.                 List<DataElement> dati = new ArrayList<>();
  99.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  100.                 DataElement dataElement = new DataElement();
  101.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  102.                 dataElement.setType(DataElementType.TITLE);
  103.                 dati.add(dataElement);
  104.                
  105.                 dati = confHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE, dati, nome, valore,  false);

  106.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  107.                 pd.setDati(dati);

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

  109.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  110.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_SYSTEM_PROPERTIES,
  111.                         ForwardParams.CHANGE());
  112.             }

  113.             // Controlli sui campi immessi
  114.             boolean isOk = confHelper.systemPropertiesCheckData(TipoOperazione.CHANGE);
  115.             if (!isOk) {

  116.                 // setto la barra del titolo
  117.                 List<Parameter> lstParam = new ArrayList<>();

  118.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  119.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA_SISTEMA,
  120.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_SYSTEM_PROPERTIES_LIST));
  121.                 lstParam.add(new Parameter(nome, null));

  122.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  126.                 DataElement dataElement = new DataElement();
  127.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  128.                 dataElement.setType(DataElementType.TITLE);
  129.                 dati.add(dataElement);
  130.                
  131.                 dati = confHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE, dati, nome, valore, false);

  132.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  133.                 pd.setDati(dati);

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

  135.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  136.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_SYSTEM_PROPERTIES,
  137.                         ForwardParams.CHANGE());
  138.             }

  139.             if(systemProperties!=null){
  140.                 for (int i = 0; i < systemProperties.sizeSystemPropertyList(); i++) {
  141.                     Property sp = systemProperties.getSystemProperty(i);
  142.                     if (nome.equals(sp.getNome())) {
  143.                         systemProperties.removeSystemProperty(i);
  144.                         break;
  145.                     }
  146.                 }
  147.             }

  148.             Property sp = new Property();
  149.             sp.setNome(nome);
  150.             sp.setValore(valore);
  151.             if(systemProperties==null) {
  152.                 systemProperties = new SystemProperties();
  153.             }
  154.             systemProperties.addSystemProperty(sp);

  155.             confCore.performUpdateOperation(userLogin, confHelper.smista(), systemProperties);

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

  158.             int idLista = Liste.SYSTEM_PROPERTIES;

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

  160.             List<Property> lista = confCore.systemPropertyList(ricerca);

  161.             confHelper.prepareSystemPropertiesList(ricerca, lista);

  162.             // refresh via JMX
  163.             confHelper.refreshSystemProperties();
  164.            
  165.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  166.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  167.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_SYSTEM_PROPERTIES,
  168.                     ForwardParams.CHANGE());

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