ServiziApplicativiList.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.sa;

  21. import java.util.List;

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

  25. import org.apache.struts.action.Action;
  26. import org.apache.struts.action.ActionForm;
  27. import org.apache.struts.action.ActionForward;
  28. import org.apache.struts.action.ActionMapping;
  29. import org.openspcoop2.core.commons.Filtri;
  30. import org.openspcoop2.core.commons.Liste;
  31. import org.openspcoop2.core.config.ServizioApplicativo;
  32. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  34. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.PageData;
  40. import org.openspcoop2.web.lib.mvc.ServletUtils;

  41. /**
  42.  * servizioApplicativoList
  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 ServiziApplicativiList 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.         try {
  61.             ServiziApplicativiHelper saHelper = new ServiziApplicativiHelper(request, pd, session);
  62.            
  63.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione
  64.             Integer parentSA = ServletUtils.getIntegerAttributeFromSession(ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT, session, request);
  65.             if(parentSA == null) parentSA = ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_NONE;
  66.            
  67.             String resetCacheFromLista = saHelper.getParameter(CostantiControlStation.PARAMETRO_RESET_CACHE_FROM_LISTA);
  68.             String verificaCertificatiFromLista = saHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CERTIFICATI_FROM_LISTA);
  69.             boolean arrivoDaLista = "true".equalsIgnoreCase(resetCacheFromLista) || "true".equalsIgnoreCase(verificaCertificatiFromLista);
  70.                        
  71.             String idsogg = saHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_PROVIDER);
  72.             long soggLong = -1;
  73.             // Posso arrivare a questa pagina anche dal menu' senza specificare il soggetto
  74.             boolean useIdSogg;
  75.             if(idsogg != null && !arrivoDaLista){
  76.                 soggLong = Long.parseLong(idsogg);
  77.                 useIdSogg = true;
  78.             } else {
  79.                 useIdSogg = false;
  80.             }
  81.            
  82.             parentSA = useIdSogg ? ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_SOGGETTO : ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_NONE;

  83.             // salvo il punto di ingresso
  84.             ServletUtils.setObjectIntoSession(request, session, parentSA, ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT);

  85.             // Preparo il menu
  86.             saHelper.makeMenu();

  87.             // Preparo la lista
  88.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  89.            
  90.             ServiziApplicativiCore saCore = new ServiziApplicativiCore();
  91.                        
  92.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  93.             List<ServizioApplicativo> lista = null;
  94.             int idLista = -1;
  95.             if(!useIdSogg){
  96.                 idLista = Liste.SERVIZIO_APPLICATIVO;
  97.             }
  98.             else {
  99.                 idLista = Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO;
  100.             }
  101.            
  102.             // poiche' esistono filtri che hanno necessita di postback salvo in sessione
  103.             if(!ServletUtils.isSearchDone(saHelper)) {
  104.                 lista = ServletUtils.getRisultatiRicercaFromSession(request, session, idLista,  ServizioApplicativo.class);
  105.             }
  106.            
  107.             ricerca = saHelper.checkSearchParameters(idLista, ricerca);
  108.            
  109.             saHelper.clearFiltroSoggettoByPostBackProtocollo(0, ricerca, idLista);
  110.            
  111.             if(!useIdSogg){
  112.                 boolean filtroSoggetto = false;
  113.                 if(saHelper.isSoggettoMultitenantSelezionato()) {
  114.                     List<String> protocolli = saCore.getProtocolli(request, session,false);
  115.                     if(protocolli!=null && protocolli.size()==1) { // dovrebbe essere l'unico caso in cui un soggetto multitenant รจ selezionato
  116.                         String protocollo = protocolli.get(0);
  117.                         filtroSoggetto = !saCore.isSupportatoAutenticazioneApplicativiEsterniErogazione(protocollo);  // devono essere fatti vedere anche quelli
  118.                     }
  119.                 }
  120.                 if(filtroSoggetto) {
  121.                     ricerca.addFilter(idLista, Filtri.FILTRO_SOGGETTO, saHelper.getSoggettoMultitenantSelezionato());
  122.                 }
  123.                
  124.                 if(lista==null) {
  125.                     if(saCore.isVisioneOggettiGlobale(userLogin)){
  126.                         lista = saCore.soggettiServizioApplicativoList(null, ricerca);
  127.                     }else{
  128.                         lista = saCore.soggettiServizioApplicativoList(userLogin, ricerca);
  129.                     }
  130.                 }
  131.             }else {
  132.                 if(lista==null) {
  133.                     lista = saCore.soggettiServizioApplicativoList(ricerca,soggLong);
  134.                 }
  135.             }
  136.            
  137.             if(!saHelper.isPostBackFilterElement()) {
  138.                 ServletUtils.setRisultatiRicercaIntoSession(request, session, idLista, lista); // salvo poiche' esistono filtri che hanno necessita di postback
  139.             }
  140.            
  141.             saHelper.prepareServizioApplicativoList(ricerca, lista, useIdSogg);

  142.             String msg = saHelper.getParameter(Costanti.PARAMETER_NAME_MSG_ERROR_EXPORT);
  143.             if(msg!=null && !"".equals(msg)){
  144.                 pd.setMessage("Errore durante esportazione: "+msg);
  145.             }
  146.            
  147.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  148.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  149.             return ServletUtils.getStrutsForward(mapping, ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI, ForwardParams.LIST());

  150.         } catch (Exception e) {
  151.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  152.                     ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI, ForwardParams.LIST());
  153.         }
  154.     }
  155. }