PorteDelegateTrasformazioniRispostaList.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.pd;

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

  44. /**
  45.  * PorteDelegateTrasformazioniRispostaList
  46.  *
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public class PorteDelegateTrasformazioniRispostaList extends Action {

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

  55.         HttpSession session = request.getSession(true);
  56.         String userLogin = ServletUtils.getUserLoginFromSession(session);

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

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  63.         try {
  64.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  65.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  66.             String nomePorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  67.    
  68.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE);
  69.             long idTrasformazione = Long.parseLong(id);
  70.            
  71.             String cambiaPosizione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_POSIZIONE);
  72.             String idTrasformazioneRispostaS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE_RISPOSTA);
  73.            
  74.             // Preparo il menu
  75.             porteDelegateHelper.makeMenu();
  76.            
  77.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  78.             if(StringUtils.isNotEmpty(cambiaPosizione)) {
  79.                 long idTrasformazioneRisposta = Long.parseLong(idTrasformazioneRispostaS);
  80.                 PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(Long.parseLong(idPorta));
  81.                
  82.                 Trasformazioni trasformazioni = portaDelegata.getTrasformazioni();
  83.                 if(trasformazioni != null) {
  84.                     TrasformazioneRegola oldRegola = null;
  85.                     for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  86.                         if(reg.getId().longValue() == idTrasformazione) {
  87.                             oldRegola = reg;
  88.                             break;
  89.                         }
  90.                     }
  91.                     if(oldRegola==null) {
  92.                         throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  93.                     }
  94.                    
  95.                     TrasformazioneRegolaRisposta rispostaToMove = null;
  96.                    
  97.                     for (int j = 0; j < oldRegola.sizeRispostaList(); j++) {
  98.                         TrasformazioneRegolaRisposta risposta = oldRegola.getRisposta(j);
  99.                         if (risposta.getId().longValue() == idTrasformazioneRisposta) {
  100.                             rispostaToMove = risposta;
  101.                             break;
  102.                         }
  103.                     }
  104.                     if(rispostaToMove==null) {
  105.                         throw new Exception("TrasformazioneRegolaRisposta con id '"+idTrasformazioneRisposta+"' non trovata");
  106.                     }
  107.                    
  108.                     int posizioneAttuale = rispostaToMove.getPosizione();
  109.                     int posizioneNuova = cambiaPosizione.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_POSIZIONE_SU) ? (posizioneAttuale - 1) : (posizioneAttuale + 1);
  110.                    
  111.                     TrasformazioneRegolaRisposta rispostaToSwitch = null;
  112.                     for (int j = 0; j < oldRegola.sizeRispostaList(); j++) {
  113.                         TrasformazioneRegolaRisposta risposta = oldRegola.getRisposta(j);
  114.                         if (risposta.getPosizione() == posizioneNuova) {
  115.                             rispostaToSwitch = risposta;
  116.                             break;
  117.                         }
  118.                     }
  119.                     if(rispostaToSwitch==null) {
  120.                         throw new Exception("TrasformazioneRegolaRisposta con id '"+posizioneNuova+"' non trovata");
  121.                     }
  122.                    
  123.                     rispostaToMove.setPosizione(posizioneNuova);
  124.                     rispostaToSwitch.setPosizione(posizioneAttuale);
  125.                    
  126.                     porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  127.                     if(CostantiControlStation.VISUALIZZA_MESSAGGIO_CONFERMA_SPOSTAMENTO_RISPOSTA_REGOLA_TRASFORMAZIONE)
  128.                         pd.setMessage(CostantiControlStation.MESSAGGIO_CONFERMA_REGOLA_TRASFORMAZIONE_RISPOSTA_SPOSTATA_CORRETTAMENTE, MessageType.INFO);
  129.                    
  130.                     // ricaricare id trasformazione
  131.                     portaDelegata = porteDelegateCore.getPortaDelegata(Long.parseLong(idPorta));

  132.                     TrasformazioneRegola trasformazioneAggiornata = porteDelegateCore.getTrasformazione(portaDelegata.getId(), oldRegola.getNome());
  133.                    
  134.                     idTrasformazione = trasformazioneAggiornata.getId();
  135.                 }
  136.             }
  137.    
  138.             // Preparo la lista
  139.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  140.            
  141.             int idLista = Liste.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE;
  142.            
  143.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  144.            
  145.             List<TrasformazioneRegolaRisposta> lista = porteDelegateCore.porteDelegateTrasformazioniRispostaList(Long.parseLong(idPorta), idTrasformazione, ricerca);
  146.            
  147.             porteDelegateHelper.preparePorteDelegateTrasformazioniRispostaList(nomePorta, idTrasformazione, ricerca, lista);
  148.    
  149.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  150.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  151.            
  152.             // Forward control to the specified success URI
  153.             return ServletUtils.getStrutsForward (mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTA, ForwardParams.LIST());
  154.         } catch (Exception e) {
  155.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTA, ForwardParams.LIST());
  156.         }  
  157.     }
  158.            
  159. }