ConfigIntegrationReaderInUso.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.protocol.engine.registry;

  21. import java.sql.Connection;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  26. import org.openspcoop2.core.config.driver.IDriverConfigurazioneGet;
  27. import org.openspcoop2.core.config.driver.db.DriverConfigurazioneDB;
  28. import org.openspcoop2.core.id.IDServizioApplicativo;
  29. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  30. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReaderInUso;
  31. import org.openspcoop2.protocol.sdk.registry.RegistryException;
  32. import org.openspcoop2.utils.UtilsRuntimeException;
  33. import org.slf4j.Logger;

  34. /**
  35.  *  ConfigIntegrationReaderInUso
  36.  *
  37.  * @author Poli Andrea (apoli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class ConfigIntegrationReaderInUso implements IConfigIntegrationReaderInUso {
  42.    
  43.     private IDriverConfigurazioneGet driverConfigurazioneGET;
  44.     @SuppressWarnings("unused")
  45.     private Logger log;
  46.    
  47.     public ConfigIntegrationReaderInUso() {
  48.         // nop
  49.     }


  50.     @Override
  51.     public void init(IDriverConfigurazioneGet driverConfigurazione,Logger log) {
  52.         this.driverConfigurazioneGET = driverConfigurazione;
  53.         this.log = log;
  54.     }
  55.    
  56.    
  57.     // SERVIZI APPLICATIVI
  58.    
  59.     @Override
  60.     public boolean inUso(IDServizioApplicativo idServizioApplicativo, boolean verificaRuoli) throws RegistryException{
  61.         if(this.driverConfigurazioneGET instanceof DriverConfigurazioneDB) {
  62.             DriverConfigurazioneDB driverDB = (DriverConfigurazioneDB) this.driverConfigurazioneGET;
  63.             Connection connection = null;
  64.             try {
  65.                 connection = driverDB.getConnection("inUso(IDServizioApplicativo)");
  66.                
  67.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<>();
  68.                
  69.                 boolean normalizeObjectIds = true;
  70.                 return DBOggettiInUsoUtils.isServizioApplicativoInUso(connection, driverDB.getTipoDB(), idServizioApplicativo, whereIsInUso, true, normalizeObjectIds, verificaRuoli);
  71.                
  72.             }
  73.             catch(Exception e) {
  74.                 throw new RegistryException(e.getMessage(),e);
  75.             }
  76.             finally {
  77.                 driverDB.releaseConnection(connection);
  78.             }
  79.         }
  80.         else {
  81.             throw new UtilsRuntimeException("Not Implemented");
  82.         }
  83.     }
  84.    
  85.     @Override
  86.     public String getDettagliInUso(IDServizioApplicativo idServizioApplicativo, boolean verificaRuoli) throws RegistryException{
  87.         if(this.driverConfigurazioneGET instanceof DriverConfigurazioneDB) {
  88.             DriverConfigurazioneDB driverDB = (DriverConfigurazioneDB) this.driverConfigurazioneGET;
  89.             Connection connection = null;
  90.             try {
  91.                 connection = driverDB.getConnection("getDettagliInUso(IDServizioApplicativo)");
  92.                
  93.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<>();
  94.                
  95.                 boolean normalizeObjectIds = true;
  96.                 boolean inUso = DBOggettiInUsoUtils.isServizioApplicativoInUso(connection, driverDB.getTipoDB(), idServizioApplicativo, whereIsInUso, true, normalizeObjectIds, verificaRuoli);
  97.                 if(inUso) {
  98.                     return DBOggettiInUsoUtils.toString(idServizioApplicativo , whereIsInUso, false, "\n", normalizeObjectIds);
  99.                 }
  100.                 else {
  101.                     return null;
  102.                 }
  103.             }
  104.             catch(Exception e) {
  105.                 throw new RegistryException(e.getMessage(),e);
  106.             }
  107.             finally {
  108.                 driverDB.releaseConnection(connection);
  109.             }
  110.         }
  111.         else {
  112.             throw new UtilsRuntimeException("Not Implemented");
  113.         }
  114.     }

  115.    
  116. }