PddCore.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.pdd;

  21. import java.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.List;

  24. import org.openspcoop2.core.commons.ISearch;
  25. import org.openspcoop2.core.registry.PortaDominio;
  26. import org.openspcoop2.core.registry.constants.PddTipologia;
  27. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  28. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  29. import org.openspcoop2.core.registry.driver.FiltroRicerca;
  30. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  31. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  32. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  33. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  34. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationDB;
  35. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationException;
  36. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationNotFound;

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

  45.     public PddCore() throws DriverControlStationException {
  46.         super();
  47.     }
  48.     public PddCore(ControlStationCore core) throws DriverControlStationException {
  49.         super(core);
  50.     }
  51.    
  52.     public List<PortaDominio> porteDominioWithSubject(String subject) throws DriverRegistroServiziException{
  53.         Connection con = null;
  54.         String nomeMetodo = "porteDominioWithSubject";
  55.         DriverRegistroServiziDB driver = null;

  56.         try {
  57.             // prendo una connessione
  58.             con = ControlStationCore.dbM.getConnection();
  59.             // istanzio il driver
  60.             driver = new DriverRegistroServiziDB(con, ControlStationCore.log, this.tipoDB);

  61.             return driver.porteDominioWithSubject(subject);
  62.            
  63.         } catch (DriverRegistroServiziException e) {
  64.             ControlStationCore.logError("[ControlStationCore::" + nomeMetodo + "] DriverRegistroServiziException :" + e.getMessage(), e);
  65.             throw e;
  66.         } catch (Exception e) {
  67.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  68.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  69.         } finally {
  70.             ControlStationCore.dbM.releaseConnection(con);
  71.         }
  72.     }

  73.     public List<String> getAllIdPorteDominio(FiltroRicerca filtroRicerca) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  74.         Connection con = null;
  75.         String nomeMetodo = "getAllIdPorteDominio";
  76.         DriverControlStationDB driver = null;

  77.         try {
  78.             // prendo una connessione
  79.             con = ControlStationCore.dbM.getConnection();
  80.             // istanzio il driver
  81.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  82.             return driver.getDriverRegistroServiziDB().getAllIdPorteDominio(filtroRicerca);

  83.         } catch (DriverRegistroServiziNotFound de) {
  84.             ControlStationCore.logDebug(getPrefixError(nomeMetodo,  de),de);
  85.             throw de;
  86.         } catch (Exception e) {
  87.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  88.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  89.         } finally {
  90.             ControlStationCore.dbM.releaseConnection(con);
  91.         }
  92.     }
  93.    
  94.     public long existPdd(String nomePdd) throws DriverControlStationException {
  95.         Connection con = null;
  96.         String nomeMetodo = "existPdd";
  97.         DriverControlStationDB driver = null;

  98.         try {
  99.             // prendo una connessione
  100.             con = ControlStationCore.dbM.getConnection();
  101.             // istanzio il driver
  102.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  103.             return driver.existPdd(nomePdd);

  104.         } catch (Exception e) {
  105.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  106.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  107.         } finally {
  108.             ControlStationCore.dbM.releaseConnection(con);
  109.         }

  110.     }
  111.    
  112.     public PdDControlStation getPdDControlStation(String pdd) throws DriverControlStationException, DriverControlStationNotFound {
  113.         Connection con = null;
  114.         String nomeMetodo = "getPdd";
  115.         DriverControlStationDB driver = null;

  116.         try {
  117.             // prendo una connessione
  118.             con = ControlStationCore.dbM.getConnection();
  119.             // istanzio il driver
  120.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  121.             return driver.getPdDControlStation(pdd);

  122.         } catch (DriverControlStationNotFound e) {
  123.             throw e;
  124.         } catch (Exception e) {
  125.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  126.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  127.         } finally {
  128.             ControlStationCore.dbM.releaseConnection(con);
  129.         }
  130.     }
  131.    
  132.     public PdDControlStation getPdDControlStation(long idPdd) throws DriverControlStationException, DriverControlStationNotFound {
  133.         Connection con = null;
  134.         String nomeMetodo = "getPdd";
  135.         DriverControlStationDB driver = null;

  136.         try {
  137.             // prendo una connessione
  138.             con = ControlStationCore.dbM.getConnection();
  139.             // istanzio il driver
  140.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  141.             return driver.getPdDControlStation(idPdd);

  142.         } catch (DriverControlStationNotFound e) {
  143.             throw e;
  144.         } catch (Exception e) {
  145.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  146.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  147.         } finally {
  148.             ControlStationCore.dbM.releaseConnection(con);
  149.         }

  150.     }
  151.    
  152.     public PortaDominio getPortaDominio(String nomePdD) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  153.         String nomeMetodo = "getPortaDominio(" + nomePdD + ")";
  154.         Connection con = null;
  155.         DriverControlStationDB driver = null;
  156.         try {
  157.             // prendo una connessione
  158.             con = ControlStationCore.dbM.getConnection();
  159.             // istanzio il driver
  160.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  161.             return driver.getDriverRegistroServiziDB().getPortaDominio(nomePdD);

  162.         } catch (DriverRegistroServiziNotFound de) {
  163.             ControlStationCore.logDebug(getPrefixError(nomeMetodo,  de),de);
  164.             throw de;
  165.         } catch (Exception e) {
  166.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  167.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  168.         } finally {
  169.             ControlStationCore.dbM.releaseConnection(con);
  170.         }
  171.     }
  172.    
  173.     public List<PortaDominio> pddListSinglePdd(String userLogin, ISearch ricerca) throws DriverRegistroServiziException {
  174.         return this.pddListSinglePdd(userLogin,null,ricerca);
  175.     }
  176.     public List<PortaDominio> pddListSinglePdd(String userLogin,String tipo, ISearch ricerca) throws DriverRegistroServiziException {
  177.         Connection con = null;
  178.         String nomeMetodo = "pddListSinglePdd";
  179.         DriverControlStationDB driver = null;

  180.         try {
  181.             // prendo una connessione
  182.             con = ControlStationCore.dbM.getConnection();
  183.             // istanzio il driver
  184.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  185.             return driver.getDriverRegistroServiziDB().porteDominioList(userLogin, tipo, ricerca);

  186.         } catch (Exception e) {
  187.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  188.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  189.         } finally {
  190.             ControlStationCore.dbM.releaseConnection(con);
  191.         }

  192.     }
  193.    
  194.    
  195.     public List<PdDControlStation> pddList(String userLogin, ISearch ricerca) throws DriverControlStationException {
  196.         Connection con = null;
  197.         String nomeMetodo = "pddList";
  198.         DriverControlStationDB driver = null;

  199.         try {
  200.             // prendo una connessione
  201.             con = ControlStationCore.dbM.getConnection();
  202.             // istanzio il driver
  203.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  204.             return driver.pddList(userLogin, ricerca);

  205.         } catch (Exception e) {
  206.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  207.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  208.         } finally {
  209.             ControlStationCore.dbM.releaseConnection(con);
  210.         }

  211.     }
  212.    
  213.     public List<PortaDominio> porteDominioList(String userLogin, ISearch ricerca) throws DriverRegistroServiziException {
  214.         String nomeMetodo = "porteDominioList()";
  215.         try {
  216.             List<PortaDominio> list = new ArrayList<>();
  217.             List<PdDControlStation> listControlStation = this.pddList(userLogin, ricerca);
  218.             while (!listControlStation.isEmpty()) {
  219.                 list.add(listControlStation.remove(0));
  220.             }
  221.             return list;
  222.         } catch (Exception e) {
  223.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  224.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  225.         }
  226.     }
  227.    
  228.     public List<org.openspcoop2.core.config.Soggetto> pddSoggettiList(long idPDD, ISearch ricerca) throws DriverControlStationException {
  229.         Connection con = null;
  230.         String nomeMetodo = "pddSoggettiList";
  231.         DriverControlStationDB driver = null;

  232.         try {
  233.             // prendo una connessione
  234.             con = ControlStationCore.dbM.getConnection();
  235.             // istanzio il driver
  236.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  237.             return driver.pddSoggettiList(idPDD, ricerca);

  238.         } catch (Exception e) {
  239.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  240.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  241.         } finally {
  242.             ControlStationCore.dbM.releaseConnection(con);
  243.         }

  244.     }
  245.    
  246.     public boolean isPddInUsoSinglePdd(PortaDominio pdd, List<String> whereIsInUso) throws DriverRegistroServiziException {
  247.         Connection con = null;
  248.         String nomeMetodo = "isPddInUsoSinglePdd";
  249.         DriverControlStationDB driver = null;

  250.         try {
  251.             // prendo una connessione
  252.             con = ControlStationCore.dbM.getConnection();
  253.             // istanzio il driver
  254.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  255.             return driver.getDriverRegistroServiziDB().isPddInUso(pdd, whereIsInUso);

  256.         } catch (Exception e) {
  257.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  258.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  259.         } finally {
  260.             ControlStationCore.dbM.releaseConnection(con);
  261.         }
  262.     }
  263.    
  264.     public boolean isPddInUso(PdDControlStation pdd, List<String> whereIsInUso, boolean normalizeObjectIds) throws DriverControlStationException {
  265.         Connection con = null;
  266.         String nomeMetodo = "isPddInUso";
  267.         DriverControlStationDB driver = null;

  268.         try {
  269.             // prendo una connessione
  270.             con = ControlStationCore.dbM.getConnection();
  271.             // istanzio il driver
  272.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  273.             return driver.isPddInUso(pdd, whereIsInUso, normalizeObjectIds);

  274.         } catch (Exception e) {
  275.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  276.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  277.         } finally {
  278.             ControlStationCore.dbM.releaseConnection(con);
  279.         }
  280.     }
  281.    
  282.     public List<SoggettoCtrlStat> soggettiWithServer(String nomePdD) throws DriverControlStationException {
  283.         Connection con = null;
  284.         String nomeMetodo = "soggettiWithServer";
  285.         DriverControlStationDB driver = null;

  286.         try {
  287.             // prendo una connessione
  288.             con = ControlStationCore.dbM.getConnection();
  289.             // istanzio il driver
  290.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  291.             return driver.soggettiWithServer(nomePdD);

  292.         } catch (Exception e) {
  293.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  294.             throw new DriverControlStationException(getPrefixError(nomeMetodo,  e),e);
  295.         } finally {
  296.             ControlStationCore.dbM.releaseConnection(con);
  297.         }
  298.     }
  299.    
  300.     public boolean existsPddOperativa() throws DriverRegistroServiziException {
  301.         Connection con = null;
  302.         String nomeMetodo = "existsPddOperativa";
  303.         DriverControlStationDB driver = null;

  304.         try {
  305.             // prendo una connessione
  306.             con = ControlStationCore.dbM.getConnection();
  307.             // istanzio il driver
  308.             driver = new DriverControlStationDB(con, null, this.tipoDB);
  309.            
  310.             FiltroRicerca filtro = new FiltroRicerca();
  311.             filtro.setTipo(PddTipologia.OPERATIVO.toString());
  312.             try{
  313.                 List<String> nomi = driver.getDriverRegistroServiziDB().getAllIdPorteDominio(filtro);
  314.                 if(nomi!=null && !nomi.isEmpty()){
  315.                     return true;
  316.                 }
  317.             }catch(DriverRegistroServiziNotFound notFound){
  318.                 // ignore
  319.             }

  320.             return false;
  321.            
  322.         } catch (Exception e) {
  323.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  324.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  325.         } finally {
  326.             ControlStationCore.dbM.releaseConnection(con);
  327.         }
  328.     }
  329.    
  330.     public String getNomePddOperativa() throws DriverRegistroServiziException {
  331.         Connection con = null;
  332.         String nomeMetodo = "getNomePddOperativa";
  333.         DriverControlStationDB driver = null;

  334.         try {
  335.             // prendo una connessione
  336.             con = ControlStationCore.dbM.getConnection();
  337.             // istanzio il driver
  338.             driver = new DriverControlStationDB(con, null, this.tipoDB);
  339.            
  340.             FiltroRicerca filtro = new FiltroRicerca();
  341.             filtro.setTipo(PddTipologia.OPERATIVO.toString());
  342.             try{
  343.                 List<String> nomi = driver.getDriverRegistroServiziDB().getAllIdPorteDominio(filtro);
  344.                 if(nomi!=null && !nomi.isEmpty()){
  345.                     return nomi.get(0); // dovrebbe esisterne solo una
  346.                 }
  347.             }catch(DriverRegistroServiziNotFound notFound){
  348.                 // ignore
  349.             }

  350.             throw new DriverRegistroServiziException("Non e' stata trovata una porta di dominio con tipo '"+PddTipologia.OPERATIVO.toString()+"'");
  351.            
  352.         } catch (Exception e) {
  353.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  354.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  355.         } finally {
  356.             ControlStationCore.dbM.releaseConnection(con);
  357.         }
  358.     }
  359.    
  360.     public boolean isPddEsterna(String nomePdD) throws DriverControlStationException, DriverControlStationNotFound{
  361.         PdDControlStation pdd = null;
  362.         if (nomePdD!=null && (!nomePdD.equals("")) && (!nomePdD.equals("-")) )
  363.             pdd = this.getPdDControlStation(nomePdD);
  364.         boolean pddEsterna = false;
  365.         if( (pdd==null) || PddTipologia.ESTERNO.toString().equals(pdd.getTipo())){
  366.             pddEsterna = true;
  367.         }
  368.         return pddEsterna;
  369.     }
  370. }