PorteDelegateServizioApplicativoDel.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.PortaDelegataServizioApplicativo;
  33. import org.openspcoop2.core.config.ServizioApplicativo;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.Utilities;
  36. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * porteDelegateServizioApplicativoDel
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class PorteDelegateServizioApplicativoDel extends Action {

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

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

  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 id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  66.             int idInt = Integer.parseInt(id);
  67.            
  68.             String tokenList = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TOKEN_AUTHORIZATION);
  69.             boolean isToken = tokenList!=null && !"".equals(tokenList) && Boolean.valueOf(tokenList);
  70.            
  71.             String objToRemove = porteDelegateHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  72.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  73.             String servizioApplicativo = "";

  74.             // Prendo la porta delegata
  75.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  76.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);

  77.             for (int i = 0; i < idsToRemove.size(); i++) {

  78.                 servizioApplicativo = idsToRemove.get(i);
  79.                 if(isToken) {
  80.                     if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getServiziApplicativi()!=null) {
  81.                         for (int j = 0; j < pde.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList(); j++) {
  82.                             PortaDelegataServizioApplicativo sa = pde.getAutorizzazioneToken().getServiziApplicativi().getServizioApplicativo(j);
  83.                             if (servizioApplicativo.equals(sa.getNome())) {
  84.                                 pde.getAutorizzazioneToken().getServiziApplicativi().removeServizioApplicativo(j);
  85.                                 break;
  86.                             }
  87.                         }
  88.                     }
  89.                 }
  90.                 else {
  91.                     for (int j = 0; j < pde.sizeServizioApplicativoList(); j++) {
  92.                         PortaDelegataServizioApplicativo sa = pde.getServizioApplicativo(j);
  93.                         if (servizioApplicativo.equals(sa.getNome())) {
  94.                             pde.removeServizioApplicativo(j);
  95.                             break;
  96.                         }
  97.                     }
  98.                 }
  99.             }

  100.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  101.            
  102.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

  103.             // Preparo il menu
  104.             porteDelegateHelper.makeMenu();

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

  107.             int idLista = Liste.PORTE_DELEGATE_SERVIZIO_APPLICATIVO;
  108.             if(isToken) {
  109.                 idLista = Liste.PORTE_DELEGATE_TOKEN_SERVIZIO_APPLICATIVO;
  110.             }

  111.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);

  112.             List<ServizioApplicativo> lista = isToken ?
  113.                     porteDelegateCore.porteDelegateServizioApplicativoTokenList(Integer.parseInt(id), ricerca)
  114.                     :
  115.                     porteDelegateCore.porteDelegateServizioApplicativoList(Integer.parseInt(id), ricerca);

  116.             porteDelegateHelper.preparePorteDelegateServizioApplicativoList(pde.getNome(), ricerca, lista);

  117.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  118.             // Forward control to the specified success URI
  119.             return ServletUtils.getStrutsForward(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SERVIZIO_APPLICATIVO,
  120.                     ForwardParams.DEL());
  121.         } catch (Exception e) {
  122.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  123.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SERVIZIO_APPLICATIVO,
  124.                     ForwardParams.DEL());
  125.         }
  126.     }
  127. }