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

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

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

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

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  60.         try {
  61.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  62.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  63.             int idInt = Integer.parseInt(id);
  64.            
  65.             String tokenList = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TOKEN_AUTHORIZATION);
  66.             boolean isToken = tokenList!=null && !"".equals(tokenList) && Boolean.valueOf(tokenList);
  67.            
  68.             String objToRemove = porteDelegateHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  69.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  70.             // Elimino il servizioApplicativo della porta delegata dal db
  71.             // StringTokenizer objTok = new StringTokenizer(objToRemove, ",");
  72.             // int[] idToRemove = new int[objTok.countTokens()];
  73.             //
  74.             // int k = 0;
  75.             // while (objTok.hasMoreElements()) {
  76.             // idToRemove[k++] = Integer.parseInt(objTok.nextToken());
  77.             // }

  78.             // Prendo la porta delegata
  79.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  80.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);

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

  82.                 String ruolo = idsToRemove.get(i);
  83.                
  84.                 if(isToken) {
  85.                     if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getRuoli()!=null) {
  86.                         for (int j = 0; j < pde.getAutorizzazioneToken().getRuoli().sizeRuoloList(); j++) {
  87.                             if(pde.getAutorizzazioneToken().getRuoli().getRuolo(j).getNome().equals(ruolo)){
  88.                                 pde.getAutorizzazioneToken().getRuoli().removeRuolo(j);
  89.                                 break;
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.                 else {
  95.                     for (int j = 0; j < pde.getRuoli().sizeRuoloList(); j++) {
  96.                         if(pde.getRuoli().getRuolo(j).getNome().equals(ruolo)){
  97.                             pde.getRuoli().removeRuolo(j);
  98.                             break;
  99.                         }
  100.                     }
  101.                 }
  102.             }

  103.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  104.            
  105.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

  106.             // Preparo il menu
  107.             porteDelegateHelper.makeMenu();

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

  110.             int idLista = Liste.PORTE_DELEGATE_RUOLI;
  111.             if(isToken) {
  112.                 idLista = Liste.PORTE_DELEGATE_TOKEN_RUOLI;
  113.             }

  114.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  115.            
  116.             List<String> lista = isToken ?
  117.                     porteDelegateCore.portaDelegataRuoliTokenList(Integer.parseInt(id), ricerca)
  118.                     :
  119.                     porteDelegateCore.portaDelegataRuoliList(Integer.parseInt(id), ricerca);

  120.             porteDelegateHelper.preparePorteDelegateRuoliList(pde.getNome(), ricerca, lista);

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

  122.             // Forward control to the specified success URI
  123.             return ServletUtils.getStrutsForward(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RUOLI,
  124.                     ForwardParams.DEL());
  125.         } catch (Exception e) {
  126.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  127.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_RUOLI,
  128.                     ForwardParams.DEL());
  129.         }
  130.     }
  131. }