PorteApplicativeResponseCachingConfigurazioneRegolaAdd.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.pa;

  21. import java.util.List;
  22. import java.util.ArrayList;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.PortaApplicativa;
  33. import org.openspcoop2.core.config.ResponseCachingConfigurazione;
  34. import org.openspcoop2.core.config.ResponseCachingConfigurazioneRegola;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  40. import org.openspcoop2.web.lib.mvc.DataElement;
  41. import org.openspcoop2.web.lib.mvc.ForwardParams;
  42. import org.openspcoop2.web.lib.mvc.GeneralData;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.Parameter;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;
  46. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

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

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

  59.         // Inizializzo PageData
  60.         PageData pd = new PageData();

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

  62.         // Inizializzo GeneralData
  63.         GeneralData gd = generalHelper.initGeneralData(request);

  64.         String userLogin = ServletUtils.getUserLoginFromSession(session);
  65.        
  66.         try {
  67.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  69.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  70.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  71.            
  72.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  73.             int idInt = Integer.parseInt(idPorta);
  74.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  75.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  76.             if(idAsps == null)
  77.                 idAsps = "";
  78.            
  79.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  80.             // Preparo il menu
  81.             porteApplicativeHelper.makeMenu();

  82.             // Prendo nome della porta applicativa
  83.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  84.             String nomePorta = pa.getNome();
  85.            
  86.             String returnCode = porteApplicativeHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_RETURN_CODE);
  87.             if(returnCode == null)
  88.                 returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_QUALSIASI;
  89.            
  90.             String statusMin = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_RETURN_CODE_MIN);
  91.             if(statusMin == null)
  92.                 statusMin = "";
  93.             String statusMax = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_RETURN_CODE_MAX);
  94.             if(statusMax == null)
  95.                 statusMax = "";
  96.             String fault = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_FAULT);
  97.             String cacheSeconds = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_CACHE_TIMEOUT_SECONDS);
  98.             if(cacheSeconds == null)
  99.                 cacheSeconds = "";
  100.            
  101.             String postBackElementName = porteApplicativeHelper.getPostBackElementName();
  102.            
  103.             // se ho modificato il soggetto ricalcolo il servizio e il service binding
  104.             if (postBackElementName != null &&
  105.                 postBackElementName.equals(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_RETURN_CODE)) {
  106.                 statusMin = "";
  107.                 statusMax = "";
  108.             }

  109.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  110.            
  111.             String labelPerPorta = null;
  112.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  113.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  114.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_CONFIG_DI,
  115.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE,
  116.                         pa);
  117.             }
  118.             else {
  119.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_CONFIG_DI+nomePorta;
  120.             }
  121.            
  122.             lstParam.add(new Parameter(labelPerPorta, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING,
  123.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  124.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  125.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  126.            
  127.             String labelPagLista = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLE;
  128.            
  129.             lstParam.add(new Parameter(labelPagLista,
  130.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA_LIST,
  131.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  132.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  133.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  134.                     ));
  135.             lstParam.add(ServletUtils.getParameterAggiungi());
  136.            
  137.            
  138.             ServletUtils.setPageDataTitle(pd, lstParam);

  139.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  140.             // dati
  141.             if (porteApplicativeHelper.isEditModeInProgress()) {
  142.                 // preparo i campi
  143.                 List<DataElement> dati = new ArrayList<>();
  144.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  145.                 dati = porteApplicativeHelper.addResponseCachingConfigurazioneRegola(TipoOperazione.ADD, returnCode, statusMin, statusMax, fault, cacheSeconds, dati);
  146.                
  147.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  148.                 pd.setDati(dati);

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

  150.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA,
  151.                         ForwardParams.ADD());
  152.             }

  153.             // Controlli sui campi immessi
  154.             boolean isOk = porteApplicativeHelper.responseCachingConfigurazioneRegolaCheckData(TipoOperazione.ADD, Long.parseLong(idPorta));
  155.             if (!isOk) {

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

  158.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  159.                
  160.                 dati = porteApplicativeHelper.addResponseCachingConfigurazioneRegola(TipoOperazione.ADD, returnCode, statusMin, statusMax, fault, cacheSeconds, dati);
  161.                
  162.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  163.                 pd.setDati(dati);

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

  165.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA,  ForwardParams.ADD());
  166.             }

  167.             // salvataggio regola
  168.             ResponseCachingConfigurazioneRegola regola = new ResponseCachingConfigurazioneRegola();
  169.            
  170.             if(returnCode.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_QUALSIASI)) {
  171.                 regola.setReturnCodeMin(null);
  172.                 regola.setReturnCodeMax(null);
  173.             } else if(returnCode.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_ESATTO)) {
  174.                 regola.setReturnCodeMin(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  175.                 regola.setReturnCodeMax(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  176.             } else { // intervallo
  177.                 regola.setReturnCodeMin(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  178.                 regola.setReturnCodeMax(StringUtils.isNotEmpty(statusMax) ? Integer.parseInt(statusMax) : null);
  179.             }
  180.            
  181.             regola.setFault(ServletUtils.isCheckBoxEnabled(fault));
  182.             regola.setCacheTimeoutSeconds(StringUtils.isNotEmpty(cacheSeconds) ? Integer.parseInt(cacheSeconds) : null);
  183.            
  184.             ResponseCachingConfigurazione configurazione = pa.getResponseCaching();
  185.             configurazione.addRegola(regola);
  186.            
  187.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  188.            
  189.             // Preparo la lista
  190.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  191.             int idLista = Liste.PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA;

  192.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  193.             List<ResponseCachingConfigurazioneRegola> lista = porteApplicativeCore.getResponseCachingConfigurazioneRegolaList(Long.parseLong(idPorta), ricerca);

  194.             porteApplicativeHelper.prepareResponseCachingConfigurazioneRegolaList(nomePorta, ricerca, lista, configurazione.getCacheTimeoutSeconds());
  195.                        
  196.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  197.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  198.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA,
  199.                     ForwardParams.ADD());
  200.         } catch (Exception e) {
  201.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  202.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_RESPONSE_CACHING_CONFIGURAZIONE_REGOLA, ForwardParams.ADD());
  203.         }
  204.     }


  205. }