PorteDelegateTrasformazioniRispostaDel.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.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.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.core.Utilities;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.Costanti;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;

  44. /**
  45.  * PorteDelegateTrasformazioniRispostaDel
  46.  *
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public class PorteDelegateTrasformazioniRispostaDel 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.         // Inizializzo PageData
  57.         PageData pd = new PageData();

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  62.         try {
  63.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  64.            
  65.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  66.             // String idsogg = porteDelegateHelper.getParameter("idsogg");
  67.             // int soggInt = Integer.parseInt(idsogg);
  68.             String nomePorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  69.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_TRASFORMAZIONE);
  70.             long idTrasformazione = Long.parseLong(id);

  71.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  72.             // Preparo il menu
  73.             porteDelegateHelper.makeMenu();

  74.             String objToRemove = porteDelegateHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  75.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  76.             Long idRisp = null;

  77.             // Prendo l'accesso registro
  78.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(Long.parseLong(idPorta));
  79.             Trasformazioni trasformazioni = portaDelegata.getTrasformazioni();
  80.             TrasformazioneRegola regola = null;
  81.            
  82.             for (int j = 0; j < trasformazioni.sizeRegolaList(); j++) {
  83.                 TrasformazioneRegola regolaTmp = trasformazioni.getRegola(j);
  84.                 if (regolaTmp.getId().longValue() == idTrasformazione) {
  85.                     regola = regolaTmp;
  86.                     break;
  87.                 }
  88.             }
  89.             if(regola==null) {
  90.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  91.             }
  92.            
  93.             for (int i = 0; i < idsToRemove.size(); i++) {
  94.                 idRisp = Long.parseLong(idsToRemove.get(i));
  95.                
  96.                 for (int j = 0; j < regola.sizeRispostaList(); j++) {
  97.                     TrasformazioneRegolaRisposta risposta = regola.getRisposta(j);
  98.                     if (risposta.getId().longValue() == idRisp.longValue()) {
  99.                         regola.removeRisposta(j);
  100.                         break;
  101.                     }
  102.                 }
  103.             }

  104.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  105.            
  106.             // ricaricare id trasformazione
  107.             portaDelegata = porteDelegateCore.getPortaDelegata(Long.parseLong(idPorta));

  108.             TrasformazioneRegola trasformazioneAggiornata = porteDelegateCore.getTrasformazione(Long.parseLong(idPorta), regola.getNome());

  109.             // Preparo il menu
  110.             porteDelegateHelper.makeMenu();
  111.            
  112.             // Preparo la lista
  113.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  114.            
  115.             int idLista = Liste.PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTE;
  116.            
  117.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);

  118.             List<TrasformazioneRegolaRisposta> lista = porteDelegateCore.porteDelegateTrasformazioniRispostaList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  119.            
  120.             porteDelegateHelper.preparePorteDelegateTrasformazioniRispostaList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  121.            
  122.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  123.             // Forward control to the specified success URI
  124.             return ServletUtils.getStrutsForward (mapping,
  125.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTA,
  126.                     ForwardParams.DEL());
  127.         } catch (Exception e) {
  128.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  129.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_TRASFORMAZIONI_RISPOSTA, ForwardParams.DEL());
  130.         }
  131.     }

  132. }