ScopeUtilities.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.scope;

  21. import java.util.HashMap;
  22. import java.util.List;

  23. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  24. import org.openspcoop2.core.config.PortaApplicativa;
  25. import org.openspcoop2.core.config.PortaDelegata;
  26. import org.openspcoop2.core.config.driver.FiltroRicercaPorteApplicative;
  27. import org.openspcoop2.core.config.driver.FiltroRicercaPorteDelegate;
  28. import org.openspcoop2.core.id.IDPortaApplicativa;
  29. import org.openspcoop2.core.id.IDPortaDelegata;
  30. import org.openspcoop2.core.id.IDScope;
  31. import org.openspcoop2.core.registry.Scope;
  32. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  33. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCore;
  34. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCore;

  35. /**
  36.  * ScopeUtilities
  37.  *
  38.  * @author Andrea Poli (apoli@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  *
  42.  */
  43. public class ScopeUtilities {

  44.     public static void findOggettiDaAggiornare(IDScope oldIdScope, Scope scopeNEW, ScopeCore scopeCore, List<Object> listOggettiDaAggiornare) throws Exception {
  45.        
  46.         // Cerco se utilizzato in porte delegate
  47.         PorteDelegateCore pdCore = new PorteDelegateCore(scopeCore);
  48.         FiltroRicercaPorteDelegate filtroRicercaPD = new FiltroRicercaPorteDelegate();
  49.         filtroRicercaPD.setIdScope(oldIdScope);
  50.         List<IDPortaDelegata> listPD = pdCore.getAllIdPorteDelegate(filtroRicercaPD);
  51.         if(listPD!=null && listPD.size()>0){
  52.             for (IDPortaDelegata idPD : listPD) {
  53.                 PortaDelegata portaDelegata = pdCore.getPortaDelegata(idPD);
  54.                 if(portaDelegata.getScope()!=null){
  55.                     for (org.openspcoop2.core.config.Scope scopeConfig : portaDelegata.getScope().getScopeList()) {
  56.                         if(scopeConfig.getNome().equals(oldIdScope.getNome())){
  57.                             scopeConfig.setNome(scopeNEW.getNome());
  58.                         }
  59.                     }
  60.                 }
  61.                 listOggettiDaAggiornare.add(portaDelegata);
  62.             }
  63.         }
  64.        
  65.        
  66.        
  67.         // Cerco se utilizzato in porte applicative
  68.         PorteApplicativeCore paCore = new PorteApplicativeCore(scopeCore);
  69.         FiltroRicercaPorteApplicative filtroRicercaPA = new FiltroRicercaPorteApplicative();
  70.         filtroRicercaPA.setIdScope(oldIdScope);
  71.         List<IDPortaApplicativa> listPA = paCore.getAllIdPorteApplicative(filtroRicercaPA);
  72.         if(listPA!=null && listPA.size()>0){
  73.             for (IDPortaApplicativa idPA : listPA) {
  74.                 PortaApplicativa portaApplicativa = paCore.getPortaApplicativa(idPA);
  75.                 if(portaApplicativa.getScope()!=null){
  76.                     for (org.openspcoop2.core.config.Scope scopeConfig : portaApplicativa.getScope().getScopeList()) {
  77.                         if(scopeConfig.getNome().equals(oldIdScope.getNome())){
  78.                             scopeConfig.setNome(scopeNEW.getNome());
  79.                         }
  80.                     }
  81.                 }
  82.                 listOggettiDaAggiornare.add(portaApplicativa);
  83.             }
  84.         }
  85.        
  86.     }
  87.    
  88.     public static boolean deleteScope(Scope scope, String userLogin, ScopeCore scopeCore, ScopeHelper scopeHelper, StringBuilder inUsoMessage, String newLine) throws Exception {
  89.         HashMap<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  90.         boolean normalizeObjectIds = !scopeHelper.isModalitaCompleta();
  91.         boolean scopeInUso = scopeCore.isScopeInUso(scope.getNome(),whereIsInUso,normalizeObjectIds);
  92.        
  93.         if (scopeInUso) {
  94.             inUsoMessage.append(DBOggettiInUsoUtils.toString(new IDScope(scope.getNome()), whereIsInUso, true, newLine));
  95.             inUsoMessage.append(newLine);

  96.         } else {
  97.             scopeCore.performDeleteOperation(userLogin, scopeHelper.smista(), scope);
  98.            
  99.             return true;
  100.         }
  101.        
  102.         return false;
  103.     }
  104.    
  105. }