RemoteStoresKeysList.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.remote_stores;

  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.commons.lang.StringUtils;
  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.Filtri;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.commons.SearchUtils;
  33. import org.openspcoop2.pdd.core.keystore.RemoteStore;
  34. import org.openspcoop2.pdd.core.keystore.RemoteStoreKeyEntry;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * RemoteStoresKeysList
  45.  *
  46.  * @author Pintori Giuliano (pintori@link.it)
  47.  * @author Poli Andrea (apoli@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  */
  51. public class RemoteStoresKeysList 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.             RemoteStoresHelper remoteStoresHelper = new RemoteStoresHelper(request, pd, session);

  62.             RemoteStoresCore remoteStoresCore = new RemoteStoresCore();

  63.             // Preparo il menu
  64.             remoteStoresHelper.makeMenu();
  65.            
  66.             // Preparo la lista
  67.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  68.            
  69.             // controllo che ci siano a disposizione dei remote stores
  70.             List<RemoteStore> remoteStoresList = remoteStoresCore.remoteStoresList();
  71.            
  72.             if(remoteStoresList == null || remoteStoresList.isEmpty()) {
  73.                 pd.setMessage(RemoteStoresCostanti.LABEL_NESSUN_REMOTE_STORE_PRESENTE, Costanti.MESSAGE_TYPE_INFO);
  74.                 pd.disableEditMode();
  75.                
  76.                 // salvo l'oggetto ricerca nella sessione
  77.                 ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  78.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  79.                 // Forward control to the specified success URI
  80.                 return ServletUtils.getStrutsForward (mapping,
  81.                         RemoteStoresCostanti.OBJECT_NAME_REMOTE_STORES_KEYS,
  82.                         ForwardParams.LIST());
  83.             }

  84.             int idLista = Liste.REMOTE_STORE_KEY;
  85.            
  86.             // poiche' esistono filtri che hanno necessita di postback salvo in sessione
  87.             List<RemoteStoreKeyEntry> lista = null;
  88.             if(!ServletUtils.isSearchDone(remoteStoresHelper)) {
  89.                 lista = ServletUtils.getRisultatiRicercaFromSession(request, session, idLista, RemoteStoreKeyEntry.class);
  90.             }

  91.             ricerca = remoteStoresHelper.checkSearchParameters(idLista, ricerca);
  92.            
  93.             // lettura del remote store corrente dai filtri di ricerca
  94.             String filterRemoteStoreId = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_REMOTE_STORE_ID);
  95.             // primo ingresso, seleziono il primo elemento della lista di remote stores
  96.             long remoteStoreId = -1;
  97.             if(StringUtils.isEmpty(filterRemoteStoreId)) {
  98.                 remoteStoreId = remoteStoresList.get(0).getId();
  99.             } else {
  100.                 remoteStoreId = Long.parseLong(filterRemoteStoreId);
  101.             }
  102.            
  103.             if(lista==null) {
  104.                 lista = remoteStoresCore.remoteStoreKeysList(ricerca, remoteStoreId);
  105.             }
  106.            
  107.             if(!remoteStoresHelper.isPostBackFilterElement()) {
  108.                 ServletUtils.setRisultatiRicercaIntoSession(request, session, idLista, lista); // salvo poiche' esistono filtri che hanno necessita di postback
  109.             }
  110.            
  111.             remoteStoresHelper.prepareRemoteStoreKeysList(ricerca, lista, remoteStoreId);
  112.            
  113.             // salvo l'oggetto ricerca nella sessione
  114.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  115.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  116.             // Forward control to the specified success URI
  117.             return ServletUtils.getStrutsForward (mapping,
  118.                     RemoteStoresCostanti.OBJECT_NAME_REMOTE_STORES_KEYS,
  119.                     ForwardParams.LIST());
  120.         } catch (Exception e) {
  121.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  122.                     RemoteStoresCostanti.OBJECT_NAME_REMOTE_STORES_KEYS, ForwardParams.LIST());
  123.         }
  124.     }
  125. }