PorteDelegateDel.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.allarmi.constants.RuoloPorta;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.PortaDelegata;
  33. import org.openspcoop2.core.controllo_traffico.AttivazionePolicy;
  34. import org.openspcoop2.core.controllo_traffico.constants.RuoloPolicy;
  35. import org.openspcoop2.core.id.IDPortaDelegata;
  36. import org.openspcoop2.core.id.IDSoggetto;
  37. import org.openspcoop2.core.mapping.MappingFruizionePortaDelegata;
  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.ConsoleSearch;
  42. import org.openspcoop2.web.ctrlstat.core.Utilities;
  43. import org.openspcoop2.web.ctrlstat.plugins.IExtendedBean;
  44. import org.openspcoop2.web.ctrlstat.plugins.IExtendedListServlet;
  45. import org.openspcoop2.web.ctrlstat.plugins.WrapperExtendedBean;
  46. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  47. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  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.  * porteDelegateDel
  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 PorteDelegateDel 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  75.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  76.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  77.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  78.             boolean useIdSogg = parentPD!=null && parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_SOGGETTO;
  79.             int soggInt = -1;
  80.             if(useIdSogg){
  81.                 String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  82.                 soggInt = Integer.parseInt(idsogg);
  83.             }
  84.             String objToRemove = porteDelegateHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  85.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  86.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);
  87.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  88.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  89.             IExtendedListServlet extendedServlet = porteDelegateCore.getExtendedServletPortaDelegata();
  90.             List<Object> listPerformOperations = new ArrayList<>();
  91.            
  92.             for (int i = 0; i < idsToRemove.size(); i++) {

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

  151.             // Preparo il menu
  152.             porteDelegateHelper.makeMenu();

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

  155.             List<PortaDelegata> lista = null;
  156.             int idLista = -1;
  157.             if(useIdSogg){
  158.                 idLista = Liste.PORTE_DELEGATE_BY_SOGGETTO;
  159.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  160.                 lista = porteDelegateCore.porteDelegateList(soggInt, ricerca);
  161.             }else{
  162.                 idLista = Liste.PORTE_DELEGATE;
  163.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  164.                 lista = porteDelegateCore.porteDelegateList(null, ricerca);
  165.             }

  166.             porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);

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

  168.             // Forward control to the specified success URI
  169.             return ServletUtils.getStrutsForward(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE ,
  170.                     ForwardParams.DEL());
  171.         } catch (Exception e) {
  172.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  173.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE,
  174.                     ForwardParams.DEL());
  175.         }
  176.     }
  177. }