DBOggettiInUsoUtils_pdd.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.utils;

  21. import java.sql.Connection;
  22. import java.sql.PreparedStatement;
  23. import java.sql.ResultSet;
  24. import java.util.List;

  25. import org.openspcoop2.core.constants.CostantiDB;
  26. import org.openspcoop2.core.id.IDSoggetto;
  27. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  28. import org.openspcoop2.utils.UtilsException;
  29. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  30. import org.openspcoop2.utils.sql.ISQLQueryObject;
  31. import org.openspcoop2.utils.sql.SQLObjectFactory;

  32. /**
  33.  * DBOggettiInUsoUtils_pdd
  34.  *
  35.  * @author Andrea Poli (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  *
  39.  */
  40. public class DBOggettiInUsoUtils_pdd {

  41.     protected static boolean isPddInUso(Connection con, String tipoDB, String nomePdd, List<String> whereIsInUso, boolean normalizeObjectIds) throws UtilsException {
  42.         String nomeMetodo = "pddInUso";

  43.         PreparedStatement stmt = null;
  44.         ResultSet risultato = null;
  45.         String queryString;

  46.         try {

  47.             // Controllo che il pdd non sia in uso
  48.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(tipoDB);
  49.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  50.             sqlQueryObject.addSelectField("*");
  51.             sqlQueryObject.addWhereCondition("server = ?");
  52.             queryString = sqlQueryObject.createSQLQuery();
  53.             stmt = con.prepareStatement(queryString);
  54.             stmt.setString(1, nomePdd);
  55.             risultato = stmt.executeQuery();
  56.             boolean isInUso = false;
  57.             while (risultato.next()) {
  58.                 String tipo_soggetto = risultato.getString("tipo_soggetto");
  59.                 String nome_soggetto = risultato.getString("nome_soggetto");
  60.                 IDSoggetto idSoggetto = new IDSoggetto(tipo_soggetto, nome_soggetto);
  61.                 if(normalizeObjectIds) {
  62.                     String protocollo = ProtocolFactoryManager.getInstance().getProtocolByOrganizationType(tipo_soggetto);
  63.                     whereIsInUso.add(DBOggettiInUsoUtils.getProtocolPrefix(protocollo)+NamingUtils.getLabelSoggetto(protocollo, idSoggetto));
  64.                 }
  65.                 else {
  66.                     whereIsInUso.add(tipo_soggetto + "/" + nome_soggetto);
  67.                 }
  68.                 isInUso = true;
  69.             }

  70.             return isInUso;

  71.         } catch (Exception se) {
  72.             throw new UtilsException("[DBOggettiInUsoUtils::" + nomeMetodo + "] Exception: " + se.getMessage(),se);
  73.         } finally {
  74.             // Chiudo statement and resultset
  75.             JDBCUtilities.closeResources(risultato, stmt);
  76.         }
  77.     }

  78.     protected static String toString(String nomePdd, List<String> whereIsInUso, boolean prefix, String separator){
  79.         String prefixString = "";
  80.         if(prefix){
  81.             prefixString = "La Porta di Dominio ["+nomePdd+"] non è eliminabile poichè: "+separator;
  82.         }
  83.         return prefixString+
  84.                 "risulta associata ad uno o pi&ugrave; Soggetti: " + DBOggettiInUsoUtils.formatList(whereIsInUso,separator)+separator;
  85.     }
  86.    
  87. }