PorteApplicativeTrasformazioniList.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 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.Liste;
  31. import org.openspcoop2.core.config.PortaApplicativa;
  32. import org.openspcoop2.core.config.TrasformazioneRegola;
  33. import org.openspcoop2.core.config.Trasformazioni;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.MessageType;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * PorteApplicativeTrasformazioniList
  45.  *
  46.  * @author Giuliano Pintori (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public class PorteApplicativeTrasformazioniList 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.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  56.         // Inizializzo PageData
  57.         PageData pd = new PageData();

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

  59.         // Inizializzo GeneralData
  60.         GeneralData gd = generalHelper.initGeneralData(request);
  61.  

  62.         try {
  63.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  64.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  65.             String nomePorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  66.             String cambiaPosizione = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_POSIZIONE);
  67.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  68.            
  69.             String idTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  70.             if(!porteApplicativeHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  71.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  72.             }
  73.             // Preparo il menu
  74.             porteApplicativeHelper.makeMenu();
  75.            
  76.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  77.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  78.                 long idTrasformazione = Long.parseLong(idTrasformazioneS);
  79.                 PortaApplicativa portaApplicativa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta));
  80.                
  81.                 Trasformazioni trasformazioni = portaApplicativa.getTrasformazioni();
  82.                 if(trasformazioni != null) {
  83.                     TrasformazioneRegola regolaToMove = null;
  84.                     for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  85.                         if(reg.getId().longValue() == idTrasformazione) {
  86.                             regolaToMove = reg;
  87.                             break;
  88.                         }
  89.                     }
  90.                     if(regolaToMove==null) {
  91.                         throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  92.                     }
  93.                    
  94.                     int posizioneAttuale = regolaToMove.getPosizione();
  95.                     int posizioneNuova = cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU) ? (posizioneAttuale - 1) : (posizioneAttuale + 1);
  96.                    
  97.                     TrasformazioneRegola regolaToSwitch = null;
  98.                     for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  99.                         if(reg.getPosizione() == posizioneNuova) {
  100.                             regolaToSwitch = reg;
  101.                             break;
  102.                         }
  103.                     }
  104.                     if(regolaToSwitch==null) {
  105.                         throw new Exception("TrasformazioneRegola con id '"+posizioneNuova+"' non trovata");
  106.                     }
  107.                    
  108.                     regolaToMove.setPosizione(posizioneNuova);
  109.                     regolaToSwitch.setPosizione(posizioneAttuale);
  110.                    
  111.                     porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), portaApplicativa);
  112.                     if(CostantiControlStation.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_REGOLA_TRASFORMAZIONE)
  113.                         pd.setMessage(CostantiControlStation.MESSAGGIO_CONFERMA_REGOLA_TRASFORMAZIONE_SPOSTATA_CORRETTAMENTE, MessageType.INFO);
  114.                 }
  115.             }
  116.    
  117.             // Preparo la lista
  118.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  119.            
  120.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI;
  121.            
  122.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  123.            
  124.            
  125.             List<TrasformazioneRegola> lista = porteApplicativeCore.porteAppTrasformazioniList(Long.parseLong(idPorta), ricerca);
  126.            
  127.             porteApplicativeHelper.preparePorteAppTrasformazioniRegolaList(nomePorta, ricerca, lista);
  128.    
  129.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  130.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  131.            
  132.             // Forward control to the specified success URI
  133.             return ServletUtils.getStrutsForward (mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI, ForwardParams.LIST());
  134.         } catch (Exception e) {
  135.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI, ForwardParams.LIST());
  136.         }  
  137.     }
  138.            
  139. }