PorteDelegateAzioneDel.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.registry.AccordoServizioParteSpecifica;
  33. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  34. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  35. import org.openspcoop2.message.constants.ServiceBinding;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.core.Utilities;
  39. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  40. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  41. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  42. import org.openspcoop2.web.lib.mvc.Costanti;
  43. import org.openspcoop2.web.lib.mvc.ForwardParams;
  44. import org.openspcoop2.web.lib.mvc.GeneralData;
  45. import org.openspcoop2.web.lib.mvc.PageData;
  46. import org.openspcoop2.web.lib.mvc.Parameter;
  47. import org.openspcoop2.web.lib.mvc.ServletUtils;

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

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

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

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

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  66.         try {
  67.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  69.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  70.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  71.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  72.             int idInt = Integer.parseInt(idPorta);
  73.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  74.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  75.             if(idAsps == null)
  76.                 idAsps = "";
  77.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  78.             String objToRemove = porteDelegateHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  79.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  80.             // Prendo la porta applicativa
  81.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  82.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  83.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  84.            
  85.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  86.             String nomePorta = portaDelegata.getNome();

  87.             Long idAspsLong = Long.parseLong(idAsps);
  88.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idAspsLong);
  89.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  90.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  91.            
  92.             List<String> azioni = new ArrayList<>();
  93.             for (int i = 0; i < idsToRemove.size(); i++) {

  94.                 String azione = idsToRemove.get(i);
  95.                 azioni.add(azione);
  96.                
  97.             }
  98.            
  99.             StringBuilder inUsoMessage = new StringBuilder();
  100.            
  101.             String userLogin = ServletUtils.getUserLoginFromSession(porteDelegateHelper.getSession());
  102.            
  103.             PorteDelegateUtilities.deletePortaDelegataAzioni(portaDelegata, asps, porteDelegateCore, porteDelegateHelper, inUsoMessage, azioni, userLogin);
  104.            
  105.             // imposto msg di errore se presente
  106.             if (inUsoMessage.length()>0) {
  107.                 pd.setMessage(inUsoMessage.toString());
  108.             }
  109.            
  110.             String labelPerPorta = null;
  111.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  112.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  113.                         porteDelegateHelper.getLabelAzioniDi(serviceBinding),
  114.                         porteDelegateHelper.getLabelAzioni(serviceBinding),
  115.                         portaDelegata);
  116.             }
  117.             else {
  118.                 labelPerPorta = porteDelegateHelper.getLabelAzioniDi(serviceBinding)+nomePorta;
  119.             }
  120.            
  121.             // Preparo il menu
  122.             porteDelegateHelper.makeMenu();
  123.            
  124.             // ricarico la porta dal db
  125.             portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  126.            
  127.             List<String> listaAzioni = portaDelegata.getAzione().getAzioneDelegataList();
  128.            
  129.             // Preparo la lista
  130.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  131.             int idLista = Liste.PORTE_DELEGATE_AZIONI;
  132.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  133.            
  134.             List<Parameter> listaParametriSessione = new ArrayList<>();
  135.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, idPorta));
  136.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg));
  137.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps));
  138.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione));
  139.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  140.            
  141.             // imposto menu' contestuale
  142.             porteDelegateHelper.impostaComandiMenuContestualePD(idsogg, idAsps, idFruizione);
  143.            
  144.             porteDelegateHelper.preparePorteAzioneList(ricerca,
  145.                     listaAzioni, idPorta, parentPD, lstParam, nomePorta, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  146.                     listaParametriSessione, labelPerPorta, serviceBinding, aspc);

  147.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  148.             // Forward control to the specified success URI
  149.             return ServletUtils.getStrutsForward (mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  150.                     ForwardParams.DEL());
  151.         } catch (Exception e) {
  152.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  153.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  154.                     ForwardParams.DEL());
  155.         }  
  156.     }
  157. }