ConfigurazioneHandlersServizioDel.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.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.Configurazione;
  33. import org.openspcoop2.core.config.ConfigurazioneGeneraleHandler;
  34. import org.openspcoop2.core.config.ConfigurazioneHandler;
  35. import org.openspcoop2.core.config.ConfigurazioneServiceHandlers;
  36. import org.openspcoop2.core.config.constants.FaseServiceHandler;
  37. import org.openspcoop2.core.constants.TipoPdD;
  38. import org.openspcoop2.core.plugins.utils.handlers.ConfigurazioneHandlerBean;
  39. import org.openspcoop2.message.constants.ServiceBinding;
  40. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  41. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  42. import org.openspcoop2.web.ctrlstat.core.Utilities;
  43. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  44. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  45. import org.openspcoop2.web.lib.mvc.Costanti;
  46. import org.openspcoop2.web.lib.mvc.ForwardParams;
  47. import org.openspcoop2.web.lib.mvc.GeneralData;
  48. import org.openspcoop2.web.lib.mvc.PageData;
  49. import org.openspcoop2.web.lib.mvc.ServletUtils;

  50. /**
  51.  * ConfigurazioneHandlersServizioDel
  52.  *
  53.  * @author Giuliano Pintori (pintori@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  *
  57.  */
  58. public final class ConfigurazioneHandlersServizioDel extends Action {

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

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

  62.         // Inizializzo PageData
  63.         PageData pd = new PageData();

  64.         GeneralHelper generalHelper = new GeneralHelper(session);

  65.         // Inizializzo GeneralData
  66.         GeneralData gd = generalHelper.initGeneralData(request);

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

  68.         try {
  69.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
  70.            
  71.             TipoPdD ruoloPorta = null;
  72.             String idPortaS = null;
  73.             ServiceBinding serviceBinding = null;
  74.            
  75.             String idTab = confHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  76.             if(!confHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  77.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  78.             }
  79.             String fase = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_FASE);

  80.             FaseServiceHandler faseSH = FaseServiceHandler.toEnumConstant(fase);        
  81.            
  82.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  83.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  84.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  85.             List<Object> oggettiDaAggiornare = new ArrayList<>();
  86.             List<ConfigurazioneHandler> listaDaAggiornare = null;
  87.             Configurazione configurazione = confCore.getConfigurazioneGenerale();
  88.            
  89.             if(configurazione.getConfigurazioneHandler() == null)
  90.                 configurazione.setConfigurazioneHandler(new ConfigurazioneGeneraleHandler());
  91.            
  92.             if(configurazione.getConfigurazioneHandler().getService() == null)
  93.                 configurazione.getConfigurazioneHandler().setService(new ConfigurazioneServiceHandlers());
  94.            
  95.             switch (faseSH) {
  96.             case EXIT:
  97.                 listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getExitList();
  98.                 break;
  99.             case INIT:
  100.                 listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getInitList();
  101.                 break;
  102.             case INTEGRATION_MANAGER_REQUEST:
  103.                 listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getIntegrationManagerRequestList();
  104.                 break;
  105.             case INTEGRATION_MANAGER_RESPONSE:
  106.                 listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getIntegrationManagerResponseList();
  107.                 break;
  108.             }
  109.             oggettiDaAggiornare.add(configurazione);
  110.            
  111.             if(listaDaAggiornare!=null) {
  112.                 for(int j = listaDaAggiornare.size() -1; j >= 0 ; j--) {
  113.                     for (int i = 0; i < idsToRemove.size(); i++) {
  114.                         if(idsToRemove.get(i).equals(listaDaAggiornare.get(j).getTipo())) {
  115.                             listaDaAggiornare.remove(j);
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.            
  121.             // update sul db
  122.             confCore.performUpdateOperation(userLogin, confHelper.smista(), oggettiDaAggiornare.toArray(new Object[oggettiDaAggiornare.size()]));
  123.             // Preparo il menu
  124.             confHelper.makeMenu();
  125.            
  126.             // Preparo la lista
  127.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  128.             int idLista = Liste.CONFIGURAZIONE_HANDLERS_SERVIZIO;

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

  130.             List<ConfigurazioneHandlerBean> lista = confCore.handlersServizioList(ricerca, fase);
  131.            
  132.             confHelper.prepareHandlersServizioList(ricerca, lista, ruoloPorta, idPortaS, serviceBinding, fase);
  133.                        
  134.             if(ruoloPorta == null) {
  135.                 pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_SERVICE_HANDLERS_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  136.             }
  137.            
  138.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  139.             // Forward control to the specified success URI
  140.             return ServletUtils.getStrutsForward (mapping,
  141.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_SERVIZIO,
  142.                     ForwardParams.DEL());
  143.         } catch (Exception e) {
  144.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  145.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_SERVIZIO, ForwardParams.DEL());
  146.         }
  147.     }
  148. }