PorteApplicativeAzioneDel.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.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.PortaApplicativa;
  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.  * PorteApplicativeAzioneDel
  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 PorteApplicativeAzioneDel 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.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  68.            
  69.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  70.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  71.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  72.            
  73.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  74.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  75.             if(idAsps == null)
  76.                 idAsps = "";
  77.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  78.             int idInt = Integer.parseInt(idPorta);
  79.             String objToRemove = porteApplicativeHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  80.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  81.             // Prendo la porta applicativa
  82.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  83.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  84.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  85.            
  86.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  87.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  88.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  89.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  90.            
  91.             List<String> azioni = new ArrayList<>();
  92.             for (int i = 0; i < idsToRemove.size(); i++) {

  93.                 String azione = idsToRemove.get(i);
  94.                 azioni.add(azione);
  95.                
  96.             }
  97.            
  98.             StringBuilder inUsoMessage = new StringBuilder();
  99.            
  100.             String userLogin = ServletUtils.getUserLoginFromSession(porteApplicativeHelper.getSession());
  101.            
  102.             PorteApplicativeUtilities.deletePortaApplicativaAzioni(pa, porteApplicativeCore, porteApplicativeHelper,
  103.                     inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE, azioni, userLogin);

  104.             // imposto msg di errore se presente
  105.             if (inUsoMessage.length()>0) {
  106.                 pd.setMessage(inUsoMessage.toString());
  107.             }
  108.            
  109.             String labelPerPorta = null;
  110.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  111.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  112.                         porteApplicativeHelper.getLabelAzioniDi(serviceBinding),
  113.                         porteApplicativeHelper.getLabelAzioni(serviceBinding),
  114.                         pa);
  115.             }
  116.             else {
  117.                 labelPerPorta = porteApplicativeHelper.getLabelAzioniDi(serviceBinding)+pa.getNome();
  118.             }
  119.            
  120.             // Preparo il menu
  121.             porteApplicativeHelper.makeMenu();
  122.             // ricarico la porta
  123.             pa = porteApplicativeCore.getPortaApplicativa(idInt);
  124.             // Prendo nome della porta applicativa
  125.             String nomePorta = pa.getNome();
  126.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  127.             List<String> listaAzioni = pa.getAzione().getAzioneDelegataList();
  128.            
  129.             // Preparo la lista
  130.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  131.             int idLista = Liste.PORTE_APPLICATIVE_AZIONI;
  132.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  133.            
  134.             List<Parameter> listaParametriSessione = new ArrayList<>();
  135.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  136.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  137.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  138.             porteApplicativeHelper.preparePorteAzioneList(ricerca,
  139.                     listaAzioni, idPorta, parentPA, lstParam, nomePorta, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
  140.                     listaParametriSessione, labelPerPorta, serviceBinding, aspc);
  141.            
  142.             // imposto menu' contestuale
  143.             porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);

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