AccordiServizioParteSpecificaPorteApplicativeDel.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.aps;

  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.id.IDPortaApplicativa;
  32. import org.openspcoop2.core.id.IDServizio;
  33. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  34. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  35. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  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.costanti.CostantiControlStation;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.lib.mvc.Costanti;
  42. import org.openspcoop2.web.lib.mvc.ForwardParams;
  43. import org.openspcoop2.web.lib.mvc.GeneralData;
  44. import org.openspcoop2.web.lib.mvc.PageData;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;

  46. /**
  47.  * serviziPorteAppDel
  48.  *
  49.  * @author Andrea Poli (apoli@link.it)
  50.  * @author Stefano Corallo (corallo@link.it)
  51.  * @author Sandra Giangrandi (sandra@link.it)
  52.  * @author $Author$
  53.  * @version $Rev$, $Date$
  54.  *
  55.  */
  56. public final class AccordiServizioParteSpecificaPorteApplicativeDel extends Action {

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

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

  60.         // Salvo il vecchio PageData
  61.         PageData pdold = ServletUtils.getPageDataFromSession(request, session);

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

  64.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  67.         try {
  68.             AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  69.             /*
  70.              * Validate the request parameters specified by the user Note: Basic
  71.              * field validation done in porteDomForm.java Business logic
  72.              * validation done in porteDomAdd.java
  73.              */
  74.             String id = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID);
  75.             long idServizioLong = Long.parseLong(id);
  76.             String objToRemove = apsHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  77.             // gli id contenuti nell'array sono i nomi delle porte applicative
  78.             // da rimuovere
  79.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  80.             // prendo l'id del soggetto erogatore lo propago
  81.             // lo metto nel pd come campo hidden
  82.             pd.setHidden(pdold.getHidden());

  83.             // Preparo il menu
  84.             apsHelper.makeMenu();

  85.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore();

  86.             // Prendo l'id del soggetto erogatore del servizio
  87.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idServizioLong);
  88.             IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);

  89.             String superUser   = ServletUtils.getUserLoginFromSession(session);

  90.             StringBuilder inUsoMessage = new StringBuilder();
  91.            
  92.             for (int i = 0; i < idsToRemove.size(); i++) {

  93.                 // ricevo come parametro l'id della pa associata al mapping da cancellare
  94.                 IDPortaApplicativa idPortaApplicativa = new IDPortaApplicativa();
  95.                 idPortaApplicativa.setNome(idsToRemove.get(i));
  96.                
  97.                 AccordiServizioParteSpecificaUtilities.deleteAccordoServizioParteSpecificaPorteApplicative(idPortaApplicativa, idServizio,
  98.                         superUser, apsCore, apsHelper, inUsoMessage);
  99.                
  100.             }// for
  101.            
  102.             if (inUsoMessage.length()>0) {
  103.                 pd.setMessage(inUsoMessage.toString());
  104.             }

  105.             // Preparo la lista
  106.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  107.             int idLista = Liste.CONFIGURAZIONE_EROGAZIONE;

  108.             ricerca = apsHelper.checkSearchParameters(idLista, ricerca);

  109.            
  110.             List<MappingErogazionePortaApplicativa> lista = apsCore.mappingServiziPorteAppList(idServizio,asps.getId(), ricerca);
  111.             apsHelper.prepareServiziConfigurazioneList(lista, id, null, ricerca);
  112.            
  113.             // reset posizione tab
  114.             if(!apsHelper.isModalitaCompleta())
  115.                 ServletUtils.setObjectIntoSession(request, session, "0", CostantiControlStation.PARAMETRO_ID_TAB);

  116.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  117.            
  118.             ForwardParams fwP = apsHelper.isModalitaCompleta() ? ForwardParams.DEL() : AccordiServizioParteSpecificaCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE;
  119.             // Forward control to the specified success URI
  120.             return ServletUtils.getStrutsForward (mapping, AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE, fwP);
  121.         } catch (Exception e) {
  122.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  123.                     AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_PORTE_APPLICATIVE,
  124.                     ForwardParams.DEL());
  125.         }  
  126.     }
  127. }