ServiziApplicativiDel.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.sa;

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

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

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

  59.         // Inizializzo GeneralData
  60.         GeneralData gd = generalHelper.initGeneralData(request);
  61.        
  62.         try {
  63.             ServiziApplicativiHelper saHelper = new ServiziApplicativiHelper(request, pd, session);
  64.            
  65.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione
  66.             Integer parentSA = ServletUtils.getIntegerAttributeFromSession(ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT, session, request);
  67.             if(parentSA == null) parentSA = ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_NONE;
  68.             Boolean useIdSogg = parentSA == ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_SOGGETTO;
  69.            
  70.             String provider = saHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_PROVIDER);
  71.            
  72.             long soggLong = -1;
  73.             // se ho fatto la add
  74.             if(useIdSogg)
  75.                 if(provider != null && !provider.equals("")){
  76.                 soggLong = Long.parseLong(provider);
  77.             }
  78.                        
  79.             String objToRemove = saHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  80.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  81.             // Elimino i servizioApplicativo dal db
  82.             // StringTokenizer objTok = new StringTokenizer(objToRemove, ",");
  83.             // int[] idToRemove = new int[objTok.countTokens()];
  84.             //
  85.             // int k = 0;
  86.             // while (objTok.hasMoreElements()) {
  87.             // idToRemove[k++] = Integer.parseInt(objTok.nextToken());
  88.             // }

  89.             ServiziApplicativiCore saCore = new ServiziApplicativiCore();
  90.            
  91.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  92.            
  93.             StringBuilder inUsoMessage = new StringBuilder();

  94.             boolean deleteAlmostOneApplicativo = false;
  95.            
  96.             for (int i = 0; i < idsToRemove.size(); i++) {

  97.                 // Prendo il nome del servizio applicativo
  98.                 ServizioApplicativo sa = saCore.getServizioApplicativo(Long.parseLong(idsToRemove.get(i)));
  99.                
  100.                 boolean deleted = ServiziApplicativiUtilities.deleteServizioApplicativo(sa, userLogin, saCore, saHelper, inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  101.                 if(deleted) {
  102.                     deleteAlmostOneApplicativo = true;
  103.                 }
  104.             }
  105.            
  106.             int idLista = -1;
  107.             if(!useIdSogg){
  108.                 idLista = Liste.SERVIZIO_APPLICATIVO;
  109.             }
  110.             else {
  111.                 idLista = Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO;
  112.             }
  113.             if(deleteAlmostOneApplicativo) {
  114.                 ServletUtils.removeRisultatiRicercaFromSession(request, session, idLista);
  115.             }

  116.             if (inUsoMessage.length()>0) {
  117.                 pd.setMessage(inUsoMessage.toString());
  118.             }

  119.             // Preparo il menu
  120.             saHelper.makeMenu();

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

  123.             List<ServizioApplicativo> lista = null;
  124.            
  125.             if(!useIdSogg){
  126.                 ricerca = saHelper.checkSearchParameters(idLista, ricerca);
  127.                
  128.                 boolean filtroSoggetto = false;
  129.                 if(saHelper.isSoggettoMultitenantSelezionato()) {
  130.                     List<String> protocolli = saCore.getProtocolli(request, session,false);
  131.                     if(protocolli!=null && protocolli.size()==1) { // dovrebbe essere l'unico caso in cui un soggetto multitenant รจ selezionato
  132.                         String protocollo = protocolli.get(0);
  133.                         filtroSoggetto = !saCore.isSupportatoAutenticazioneApplicativiEsterniErogazione(protocollo);  // devono essere fatti vedere anche quelli
  134.                     }
  135.                 }
  136.                 if(filtroSoggetto) {
  137.                     ricerca.addFilter(idLista, Filtri.FILTRO_SOGGETTO, saHelper.getSoggettoMultitenantSelezionato());
  138.                 }
  139.                
  140.                 if(saCore.isVisioneOggettiGlobale(userLogin)){
  141.                     lista = saCore.soggettiServizioApplicativoList(null, ricerca);
  142.                 }else{
  143.                     lista = saCore.soggettiServizioApplicativoList(userLogin, ricerca);
  144.                 }
  145.             }else {
  146.                 ricerca = saHelper.checkSearchParameters(idLista, ricerca);
  147.                
  148.                 lista = saCore.soggettiServizioApplicativoList(ricerca,soggLong);
  149.             }

  150.             saHelper.prepareServizioApplicativoList(ricerca, lista, useIdSogg);

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

  152.             return ServletUtils.getStrutsForward(mapping, ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI, ForwardParams.DEL());
  153.            
  154.         } catch (Exception e) {
  155.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  156.                     ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI, ForwardParams.DEL());
  157.         }
  158.     }
  159. }