GruppiCore.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.gruppi;

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

  25. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  26. import org.openspcoop2.core.commons.ISearch;
  27. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  28. import org.openspcoop2.core.id.IDGruppo;
  29. import org.openspcoop2.core.registry.Gruppo;
  30. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  31. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  32. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationDB;

  33. /**
  34.  * GruppiCore
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author Giuliano Pintori (pintori@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class GruppiCore extends ControlStationCore {

  42.     public GruppiCore() throws Exception {
  43.         super();
  44.     }
  45.     public GruppiCore(ControlStationCore core) throws Exception {
  46.         super(core);
  47.     }
  48.    
  49.    
  50.    
  51.     public List<Gruppo> gruppiList(String superuser,ISearch ricerca) throws DriverConfigurazioneException {
  52.         Connection con = null;
  53.         String nomeMetodo = "gruppiList";
  54.         DriverControlStationDB driver = null;

  55.         try {
  56.             // prendo una connessione
  57.             con = ControlStationCore.dbM.getConnection();
  58.             // istanzio il driver
  59.             driver = new DriverControlStationDB(con, null, this.tipoDB);
  60.             return driver.getDriverRegistroServiziDB().gruppiList(superuser, ricerca);
  61.         } catch (Exception e) {
  62.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  63.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  64.         } finally {
  65.             ControlStationCore.dbM.releaseConnection(con);
  66.         }
  67.     }
  68.    
  69.     public Gruppo getGruppo(long id) throws DriverConfigurazioneException {
  70.         Connection con = null;
  71.         String nomeMetodo = "getGruppo";
  72.         DriverControlStationDB driver = null;

  73.         try {
  74.             // prendo una connessione
  75.             con = ControlStationCore.dbM.getConnection();
  76.             // istanzio il driver
  77.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  78.             return driver.getDriverRegistroServiziDB().getGruppo(id);

  79.         } catch (Exception e) {
  80.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  81.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  82.         } finally {
  83.             ControlStationCore.dbM.releaseConnection(con);
  84.         }

  85.     }
  86.    
  87.     public Gruppo getGruppo(String nome) throws DriverConfigurazioneException {
  88.         Connection con = null;
  89.         String nomeMetodo = "getGruppo";
  90.         DriverControlStationDB driver = null;

  91.         try {
  92.             // prendo una connessione
  93.             con = ControlStationCore.dbM.getConnection();
  94.             // istanzio il driver
  95.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  96.             IDGruppo idGruppo = new IDGruppo(nome);
  97.             return driver.getDriverRegistroServiziDB().getGruppo(idGruppo);

  98.         } catch (Exception e) {
  99.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  100.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  101.         } finally {
  102.             ControlStationCore.dbM.releaseConnection(con);
  103.         }

  104.     }
  105.    
  106.     public boolean existsGruppo(String nome) throws DriverConfigurazioneException {
  107.         Connection con = null;
  108.         String nomeMetodo = "existsGruppo";
  109.         DriverControlStationDB driver = null;

  110.         try {
  111.             // prendo una connessione
  112.             con = ControlStationCore.dbM.getConnection();
  113.             // istanzio il driver
  114.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  115.             IDGruppo idGruppo = new IDGruppo(nome);
  116.             return driver.getDriverRegistroServiziDB().existsGruppo(idGruppo);

  117.         } catch (Exception e) {
  118.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  119.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  120.         } finally {
  121.             ControlStationCore.dbM.releaseConnection(con);
  122.         }

  123.     }
  124.    
  125.     public boolean isGruppoInUso(String gruppo, Map<ErrorsHandlerCostant, List<String>> whereIsInUso, boolean normalizeObjectIds) throws DriverConfigurazioneException {
  126.         Connection con = null;
  127.         String nomeMetodo = "isGruppoInUso";
  128.         DriverControlStationDB driver = null;

  129.         try {
  130.             // prendo una connessione
  131.             con = ControlStationCore.dbM.getConnection();
  132.             // istanzio il driver
  133.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  134.             return driver.isGruppoInUso(new IDGruppo(gruppo), whereIsInUso, normalizeObjectIds);

  135.         } catch (Exception e) {
  136.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  137.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  138.         } finally {
  139.             ControlStationCore.dbM.releaseConnection(con);
  140.         }

  141.     }
  142.    
  143.     public boolean isGruppoConfigInUso(String gruppo, Map<ErrorsHandlerCostant, List<String>> whereIsInUso, boolean normalizeObjectIds) throws DriverConfigurazioneException {
  144.         Connection con = null;
  145.         String nomeMetodo = "isGruppoConfigInUso";
  146.         DriverControlStationDB driver = null;

  147.         try {
  148.             // prendo una connessione
  149.             con = ControlStationCore.dbM.getConnection();
  150.             // istanzio il driver
  151.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  152.             return driver.isGruppoConfigInUso(new IDGruppo(gruppo), whereIsInUso, normalizeObjectIds);

  153.         } catch (Exception e) {
  154.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  155.             throw new DriverConfigurazioneException(getPrefixError(nomeMetodo,  e),e);
  156.         } finally {
  157.             ControlStationCore.dbM.releaseConnection(con);
  158.         }

  159.     }
  160.    
  161.     public String getDettagliGruppoInUso(IDGruppo gruppo) throws DriverConfigurazioneException {
  162.         EnumMap<ErrorsHandlerCostant, List<String>> whereIsInUso = new EnumMap<>(ErrorsHandlerCostant.class);
  163.         boolean normalizeObjectIds = true;
  164.         boolean gruppoInUso  = this.isGruppoInUso(gruppo.getNome(), whereIsInUso, normalizeObjectIds );
  165.        
  166.         StringBuilder inUsoMessage = new StringBuilder();
  167.         if(gruppoInUso) {
  168.             String s = DBOggettiInUsoUtils.toString(gruppo, whereIsInUso, false, "\n");
  169.             if(s!=null && s.startsWith("\n") && s.length()>1) {
  170.                 s = s.substring(1);
  171.             }
  172.             inUsoMessage.append(s);
  173.             inUsoMessage.append("\n");
  174.         } else {
  175.             inUsoMessage.append(GruppiCostanti.LABEL_IN_USO_BODY_HEADER_NESSUN_RISULTATO);
  176.         }
  177.        
  178.         return inUsoMessage.toString();
  179.     }
  180. }