ConfigurazioneAccessoRegistro.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.Cache;
  32. import org.openspcoop2.core.config.constants.AlgoritmoCache;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.lib.mvc.Costanti;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.GeneralData;
  38. import org.openspcoop2.web.lib.mvc.PageData;
  39. import org.openspcoop2.web.lib.mvc.Parameter;
  40. import org.openspcoop2.web.lib.mvc.ServletUtils;

  41. /**
  42.  * registro
  43.  *
  44.  * @author Andrea Poli (apoli@link.it)
  45.  * @author Stefano Corallo (corallo@link.it)
  46.  * @author Sandra Giangrandi (sandra@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class ConfigurazioneAccessoRegistro extends Action {

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

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

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         GeneralHelper generalHelper = new GeneralHelper(session);

  58.         // Inizializzo GeneralData
  59.         GeneralData gd = generalHelper.initGeneralData(request);

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

  61.         try {
  62.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  63.             String statocache = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_STATO_CACHE_REGISTRY);
  64.             String dimensionecache = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_DIMENSIONE_CACHE_REGISTRY);
  65.             String algoritmocache = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ALGORITMO_CACHE_REGISTRY);
  66.             String idlecache = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_IDLE_CACHE_REGISTRY);
  67.             String lifecache = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_LIFE_CACHE_REGISTRY);
  68.             String applicaModificaS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_APPLICA_MODIFICA);
  69.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);

  70.             ConfigurazioneCore confCore = new ConfigurazioneCore();

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

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

  75.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  76.                     ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  77.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_REGISTRO, null));

  78.             ServletUtils.setPageDataTitle(pd, lstParam);

  79.             // Prendo il registro (dalla tabella configurazione)
  80.             AccessoRegistro ar = confCore.getAccessoRegistro();

  81.             // Se statohid == null, visualizzo la pagina per la modifica dati
  82.             // In caso contrario, modifico i dati della porta di dominio nel db
  83.             if (confHelper.isEditModeInProgress() && !applicaModifica) {
  84.                 Cache arc = ar.getCache();
  85.                 if (arc == null) {
  86.                     if (statocache == null) {
  87.                         statocache = ConfigurazioneCostanti.DEFAULT_VALUE_DISABILITATO;
  88.                     }
  89.                     dimensionecache = "";
  90.                     algoritmocache = ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_ALGORITMO_CACHE_LRU;
  91.                     idlecache = "";
  92.                     lifecache = "";
  93.                 } else {
  94.                     if (statocache == null) {
  95.                         statocache = ConfigurazioneCostanti.DEFAULT_VALUE_ABILITATO;
  96.                     }
  97.                     dimensionecache = arc.getDimensione();
  98.                     if(arc.getAlgoritmo()!=null)
  99.                         algoritmocache = arc.getAlgoritmo().toString();
  100.                     idlecache = arc.getItemIdleTime();
  101.                     lifecache = arc.getItemLifeSecond();
  102.                 }
  103.                 // preparo i campi
  104.                 List<DataElement> dati = new ArrayList<>();
  105.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  106.                 dati = confHelper.addConfigurazioneRegistroToDati(statocache, dimensionecache, algoritmocache, idlecache, lifecache, dati);

  107.                 pd.setDati(dati);

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

  109.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  110.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI,
  111.                         ConfigurazioneCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI);
  112.             }

  113.             // Controlli sui campi immessi
  114.             boolean isOk = confHelper.registroCheckData();
  115.             if (!isOk) {
  116.                 // preparo i campi
  117.                 List<DataElement> dati = new ArrayList<>();

  118.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  119.                
  120.                 dati = confHelper.addConfigurazioneRegistroToDati(statocache, dimensionecache, algoritmocache, idlecache, lifecache, dati);

  121.                 pd.setDati(dati);

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

  123.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  124.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI,
  125.                         ConfigurazioneCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI);
  126.             }

  127.             // Modifico i dati del registro nel db
  128.             if (statocache.equals(ConfigurazioneCostanti.DEFAULT_VALUE_ABILITATO)) {
  129.                 Cache arcNew = new Cache();
  130.                 arcNew.setDimensione(dimensionecache);
  131.                 arcNew.setAlgoritmo(AlgoritmoCache.toEnumConstant(algoritmocache));
  132.                 arcNew.setItemIdleTime(idlecache);
  133.                 arcNew.setItemLifeSecond(confHelper.convertLifeCacheValue(lifecache));
  134.                 ar.setCache(arcNew);
  135.             } else {
  136.                 ar.setCache(null);
  137.             }

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

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

  141.             dati =  confHelper.addConfigurazioneRegistroToDati(statocache, dimensionecache,
  142.                     algoritmocache, idlecache, lifecache, dati);


  143.             pd.setDati(dati);
  144.            
  145.             pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ACCESSO_REGISTRO_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

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

  147.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  148.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI,
  149.                     ConfigurazioneCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI);
  150.         } catch (Exception e) {
  151.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  152.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI,
  153.                     ConfigurazioneCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE_ACCESSO_REGISTRO_SERVIZI);
  154.         }
  155.     }


  156. }