PorteApplicativeDel.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.allarmi.constants.RuoloPorta;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.PortaApplicativa;
  33. import org.openspcoop2.core.controllo_traffico.AttivazionePolicy;
  34. import org.openspcoop2.core.controllo_traffico.constants.RuoloPolicy;
  35. import org.openspcoop2.core.id.IDPortaApplicativa;
  36. import org.openspcoop2.core.id.IDSoggetto;
  37. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  38. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  39. import org.openspcoop2.monitor.engine.alarm.wrapper.ConfigurazioneAllarmeBean;
  40. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  41. import org.openspcoop2.web.ctrlstat.core.Utilities;
  42. import org.openspcoop2.web.ctrlstat.plugins.IExtendedBean;
  43. import org.openspcoop2.web.ctrlstat.plugins.IExtendedListServlet;
  44. import org.openspcoop2.web.ctrlstat.plugins.WrapperExtendedBean;
  45. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  46. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  47. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  48. import org.openspcoop2.web.lib.mvc.Costanti;
  49. import org.openspcoop2.web.lib.mvc.ForwardParams;
  50. import org.openspcoop2.web.lib.mvc.GeneralData;
  51. import org.openspcoop2.web.lib.mvc.PageData;
  52. import org.openspcoop2.web.lib.mvc.ServletUtils;
  53. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  54. /**
  55.  * porteAppDel
  56.  *
  57.  * @author Andrea Poli (apoli@link.it)
  58.  * @author Stefano Corallo (corallo@link.it)
  59.  * @author Sandra Giangrandi (sandra@link.it)
  60.  * @author $Author$
  61.  * @version $Rev$, $Date$
  62.  *
  63.  */
  64. public final class PorteApplicativeDel extends Action {

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

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

  68.         // Inizializzo PageData
  69.         PageData pd = new PageData();

  70.         GeneralHelper generalHelper = new GeneralHelper(session);

  71.         // Inizializzo GeneralData
  72.         GeneralData gd = generalHelper.initGeneralData(request);

  73.         try {
  74.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  75.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  76.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  77.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  78.             boolean useIdSogg = parentPA!=null && parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_SOGGETTO;
  79.            
  80.             int soggInt = -1 ;
  81.             if(useIdSogg){
  82.                 String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  83.                 soggInt = Integer.parseInt(idsogg);
  84.             }
  85.             String objToRemove = porteApplicativeHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  86.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  87.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteApplicativeCore);
  88.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  89.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  90.            
  91.             IExtendedListServlet extendedServlet = porteApplicativeCore.getExtendedServletPortaApplicativa();
  92.             List<Object> listPerformOperations = new ArrayList<>();
  93.            
  94.             for (int i = 0; i < idsToRemove.size(); i++) {

  95.                 // Elimino la porta applicativa
  96.                 PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idsToRemove.get(i)));
  97.            
  98.                 if(extendedServlet!=null){
  99.                     List<IExtendedBean> listExt = null;
  100.                     try{
  101.                         listExt = extendedServlet.extendedBeanList(TipoOperazione.DEL,porteApplicativeHelper,porteApplicativeCore,pa);
  102.                     }catch(Exception e){
  103.                         ControlStationCore.logError(e.getMessage(), e);
  104.                     }
  105.                     if(listExt!=null && !listExt.isEmpty()){
  106.                         for (IExtendedBean iExtendedBean : listExt) {
  107.                             WrapperExtendedBean wrapper = new WrapperExtendedBean();
  108.                             wrapper.setExtendedBean(iExtendedBean);
  109.                             wrapper.setExtendedServlet(extendedServlet);
  110.                             wrapper.setOriginalBean(pa);
  111.                             wrapper.setManageOriginalBean(false);      
  112.                             listPerformOperations.add(wrapper);
  113.                         }
  114.                     }
  115.                 }
  116.                
  117.                 // cancellazione del mapping
  118.                 MappingErogazionePortaApplicativa mappingErogazione = new MappingErogazionePortaApplicativa();
  119.                 IDSoggetto soggettoErogatore = new IDSoggetto(pa.getTipoSoggettoProprietario(),pa.getNomeSoggettoProprietario());
  120.                 IDPortaApplicativa idPortaApplicativa = new IDPortaApplicativa();
  121.                 idPortaApplicativa.setNome(pa.getNome());
  122.                 mappingErogazione.setIdPortaApplicativa(idPortaApplicativa);
  123.                 mappingErogazione.setIdServizio(IDServizioFactory.getInstance().getIDServizioFromValues(pa.getServizio().getTipo(), pa.getServizio().getNome(),
  124.                         soggettoErogatore, pa.getServizio().getVersione()));
  125.                 if(porteApplicativeCore.existsMappingErogazionePortaApplicativa(mappingErogazione)) {
  126.                     listPerformOperations.add(mappingErogazione);
  127.                 }
  128.                
  129.                 // cancello per policy associate alla porta se esistono
  130.                 List<AttivazionePolicy> listAttivazione = confCore.attivazionePolicyList(new ConsoleSearch(true), RuoloPolicy.APPLICATIVA, pa.getNome());
  131.                 if(listAttivazione!=null && !listAttivazione.isEmpty()) {
  132.                     listPerformOperations.addAll(listAttivazione);
  133.                 }
  134.                
  135.                 if(confCore.isConfigurazioneAllarmiEnabled()) {
  136.                     // cancello allarmi associati alla porta se esistono
  137.                     List<ConfigurazioneAllarmeBean> listAllarmi = confCore.allarmiList(new ConsoleSearch(true), RuoloPorta.APPLICATIVA, pa.getNome());
  138.                     if(listAllarmi!=null && !listAllarmi.isEmpty()) {
  139.                         listPerformOperations.addAll(listAllarmi);
  140.                     }
  141.                 }
  142.                
  143.                 // cancellazione della porta
  144.                 listPerformOperations.add(pa);
  145.             }
  146.            
  147.             porteApplicativeCore.performDeleteOperation(userLogin, porteApplicativeHelper.smista(), listPerformOperations.toArray(new Object[1]));

  148.             // Preparo il menu
  149.             porteApplicativeHelper.makeMenu();

  150.             // Preparo la lista
  151.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  152.            
  153.             List<PortaApplicativa> lista = null;
  154.             int idLista = -1;
  155.             if(useIdSogg){
  156.                 idLista = Liste.PORTE_APPLICATIVE_BY_SOGGETTO;
  157.                 ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  158.                 lista = porteApplicativeCore.porteAppList(soggInt, ricerca);
  159.             }else{
  160.                 idLista = Liste.PORTE_APPLICATIVE;
  161.                 ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  162.                 lista = porteApplicativeCore.porteAppList(null, ricerca);
  163.             }

  164.             porteApplicativeHelper.preparePorteAppList(ricerca, lista, idLista);

  165.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  166.             // Forward control to the specified success URI
  167.             return ServletUtils.getStrutsForward (mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  168.                     ForwardParams.DEL());
  169.         } catch (Exception e) {
  170.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  171.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  172.                     ForwardParams.DEL());
  173.         }  
  174.     }
  175. }