ConfigurazioneHandlersServizioList.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.costanti.CostantiControlStation;
  43. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  44. import org.openspcoop2.web.lib.mvc.Costanti;
  45. import org.openspcoop2.web.lib.mvc.ForwardParams;
  46. import org.openspcoop2.web.lib.mvc.GeneralData;
  47. import org.openspcoop2.web.lib.mvc.MessageType;
  48. import org.openspcoop2.web.lib.mvc.PageData;
  49. import org.openspcoop2.web.lib.mvc.ServletUtils;

  50. /**
  51.  * ConfigurazioneHandlersServizioList
  52.  *
  53.  * @author Giuliano Pintori (pintori@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  *
  57.  */
  58. public final class ConfigurazioneHandlersServizioList 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.         String userLogin = ServletUtils.getUserLoginFromSession(session);

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

  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.             String cambiaPosizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_POSIZIONE);
  81.             String idHandlerS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_HANDLERS_ID_HANDLER);

  82.             FaseServiceHandler faseSH = FaseServiceHandler.toEnumConstant(fase);        
  83.            
  84.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  85.            
  86.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  87.                
  88.                 Long idHandler = Long.parseLong(idHandlerS);
  89.                
  90.                 List<Object> oggettiDaAggiornare = new ArrayList<>();
  91.                 List<ConfigurazioneHandler> listaDaAggiornare = null;
  92.                 Configurazione configurazione = confCore.getConfigurazioneGenerale();
  93.                
  94.                 if(configurazione.getConfigurazioneHandler() == null)
  95.                     configurazione.setConfigurazioneHandler(new ConfigurazioneGeneraleHandler());
  96.                
  97.                 if(configurazione.getConfigurazioneHandler().getService() == null)
  98.                     configurazione.getConfigurazioneHandler().setService(new ConfigurazioneServiceHandlers());
  99.                
  100.                 switch (faseSH) {
  101.                 case EXIT:
  102.                     listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getExitList();
  103.                     break;
  104.                 case INIT:
  105.                     listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getInitList();
  106.                     break;
  107.                 case INTEGRATION_MANAGER_REQUEST:
  108.                     listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getIntegrationManagerRequestList();
  109.                     break;
  110.                 case INTEGRATION_MANAGER_RESPONSE:
  111.                     listaDaAggiornare =configurazione.getConfigurazioneHandler().getService().getIntegrationManagerResponseList();
  112.                     break;
  113.                 }
  114.                 oggettiDaAggiornare.add(configurazione);
  115.                
  116.                 if(listaDaAggiornare!=null) {
  117.                     for(int j = 0; j < listaDaAggiornare.size() ; j++) {
  118.                         ConfigurazioneHandler handlerToMove = null;
  119.                         ConfigurazioneHandler handlerToCheck = listaDaAggiornare.get(j);
  120.                         if(handlerToCheck.getId().equals(idHandler)) {
  121.                             handlerToMove = handlerToCheck;
  122.                            
  123.                             int posizioneAttuale = handlerToMove.getPosizione();
  124.                            
  125.                             ConfigurazioneHandler handlerToSwitch = null;
  126.                             if(cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU)) {
  127.                                 handlerToSwitch = listaDaAggiornare.get(j-1);
  128.                             } else {
  129.                                 handlerToSwitch = listaDaAggiornare.get(j+1);
  130.                             }
  131.                             int posizioneNuova = handlerToSwitch.getPosizione();
  132.                            
  133.                             handlerToMove.setPosizione(posizioneNuova);
  134.                             handlerToSwitch.setPosizione(posizioneAttuale);
  135.                             break;
  136.                         }
  137.                     }
  138.                 }

  139.                 confCore.performUpdateOperation(userLogin, confHelper.smista(), oggettiDaAggiornare.toArray(new Object[oggettiDaAggiornare.size()]));
  140.                 if(ConfigurazioneCostanti.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_HANDLER) {
  141.                     pd.setMessage(ConfigurazioneCostanti.MESSAGGIO_CONFERMA_HANDLER_SPOSTATO_CORRETTAMENTE, MessageType.INFO);
  142.                 }
  143.                 else {
  144.                     if(ruoloPorta == null) {
  145.                         pd.setMessage(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_MESSAGE_HANDLERS_MODIFICATA_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  146.                     }
  147.                 }
  148.             }


  149.             // Preparo il menu
  150.             confHelper.makeMenu();
  151.            
  152.             // Preparo la lista
  153.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  154.             int idLista = Liste.CONFIGURAZIONE_HANDLERS_SERVIZIO;

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

  156.             List<ConfigurazioneHandlerBean> lista = confCore.handlersServizioList(ricerca, fase);
  157.            
  158.             confHelper.prepareHandlersServizioList(ricerca, lista, ruoloPorta, idPortaS, serviceBinding, fase);
  159.            
  160.             // salvo l'oggetto ricerca nella sessione
  161.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  162.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  163.             // Forward control to the specified success URI
  164.             return ServletUtils.getStrutsForward (mapping,
  165.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_SERVIZIO,
  166.                     ForwardParams.LIST());
  167.         } catch (Exception e) {
  168.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  169.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_HANDLERS_SERVIZIO, ForwardParams.LIST());
  170.         }
  171.     }
  172. }