AccordiCooperazioneCore.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.ac;

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

  24. import org.openspcoop2.core.commons.DBUtils;
  25. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  26. import org.openspcoop2.core.commons.ISearch;
  27. import org.openspcoop2.core.id.IDAccordoCooperazione;
  28. import org.openspcoop2.core.id.IDSoggetto;
  29. import org.openspcoop2.core.registry.AccordoCooperazione;
  30. import org.openspcoop2.core.registry.Documento;
  31. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  32. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  33. import org.openspcoop2.core.registry.driver.FiltroRicercaAccordi;
  34. import org.openspcoop2.core.registry.driver.ValidazioneStatoPackageException;
  35. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  36. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  37. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  38. import org.openspcoop2.protocol.sdk.validator.ValidazioneResult;
  39. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  40. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationDB;
  41. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;

  42. /**
  43.  * AccordiCooperazioneCore
  44.  *
  45.  * @author Poli Andrea (apoli@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  */
  49. public class AccordiCooperazioneCore extends ControlStationCore {

  50.     public AccordiCooperazioneCore() throws Exception {
  51.         super();
  52.     }
  53.     public AccordiCooperazioneCore(ControlStationCore core) throws Exception {
  54.         super(core);
  55.     }

  56.     public ValidazioneResult validazione(AccordoCooperazione ac,SoggettiCore soggettiCore) throws DriverRegistroServiziException {
  57.         String nomeMetodo = "validazione";
  58.         try {
  59.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(ac.getSoggettoReferente().getTipo());
  60.             IProtocolFactory<?> protocol = ProtocolFactoryManager.getInstance().getProtocolFactoryByName(protocollo);
  61.             return protocol.createValidazioneAccordi().valida(ac);
  62.         }catch (Exception e) {
  63.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  64.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  65.         }
  66.     }
  67.    
  68.     public long getIdAccordoCoopeazione(IDAccordoCooperazione idAccordo) throws DriverRegistroServiziException {
  69.         Connection con = null;
  70.         String nomeMetodo = "getIdAccordoCoopeazione";
  71.         try {
  72.             // prendo una connessione
  73.             con = ControlStationCore.dbM.getConnection();
  74.             return DBUtils.getIdAccordoCooperazione(idAccordo, con, this.tipoDB);
  75.         } catch (Exception e) {
  76.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  77.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  78.         } finally {
  79.             ControlStationCore.dbM.releaseConnection(con);
  80.         }
  81.     }
  82.    
  83.     public List<IDSoggetto> accordiCoopPartecipantiList(long idAccordo,ISearch ricerca) throws DriverRegistroServiziException {
  84.         Connection con = null;
  85.         String nomeMetodo = "accordiCoopPartecipantiList";
  86.         DriverControlStationDB driver = null;

  87.         try {
  88.             // prendo una connessione
  89.             con = ControlStationCore.dbM.getConnection();
  90.             // istanzio il driver
  91.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  92.             return driver.getDriverRegistroServiziDB().accordiCoopPartecipantiList(idAccordo,ricerca);
  93.         } catch (DriverRegistroServiziException e) {
  94.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  95.             throw e;
  96.         } catch (Exception e) {
  97.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  98.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  99.         } finally {
  100.             ControlStationCore.dbM.releaseConnection(con);
  101.         }
  102.     }
  103.    
  104.     public void validaStatoAccordoCooperazione(AccordoCooperazione ac) throws DriverRegistroServiziException,ValidazioneStatoPackageException{
  105.         Connection con = null;
  106.         String nomeMetodo = "validaStatoAccordoCooperazione";
  107.         DriverRegistroServiziDB driver = null;

  108.         try {
  109.             // prendo una connessione
  110.             con = ControlStationCore.dbM.getConnection();
  111.             // istanzio il driver
  112.             driver = new DriverRegistroServiziDB(con, ControlStationCore.log, this.tipoDB);

  113.             driver.validaStatoAccordoCooperazione(ac);
  114.            
  115.         } catch (ValidazioneStatoPackageException e) {
  116.             ControlStationCore.logError("[ControlStationCore::" + nomeMetodo + "] ValidazioneStatoPackageException :" + e.getMessage(), e);
  117.             throw e;
  118.         }  catch (DriverRegistroServiziException e) {
  119.             ControlStationCore.logError("[ControlStationCore::" + nomeMetodo + "] DriverRegistroServiziException :" + e.getMessage(), e);
  120.             throw e;
  121.         } catch (Exception e) {
  122.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  123.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  124.         } finally {
  125.             ControlStationCore.dbM.releaseConnection(con);
  126.         }
  127.     }
  128.    
  129.     public List<Documento> accordiCoopAllegatiList(long idAccordo, ISearch ricerca) throws DriverRegistroServiziException {
  130.         Connection con = null;
  131.         String nomeMetodo = "accordiCoopAllegatiList";
  132.         DriverControlStationDB driver = null;

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

  138.             return driver.getDriverRegistroServiziDB().accordiCoopAllegatiList(idAccordo, ricerca);
  139.         } catch (Exception e) {
  140.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  141.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  142.         } finally {
  143.             ControlStationCore.dbM.releaseConnection(con);
  144.         }
  145.     }
  146.    
  147.     public boolean isAccordoCooperazioneInUso(AccordoCooperazione ac, Map<ErrorsHandlerCostant, List<String>> whereIsInUso, boolean normalizeObjectIds) throws DriverRegistroServiziException {
  148.         Connection con = null;
  149.         String nomeMetodo = "isAccordoCooperazioneInUso";
  150.         DriverControlStationDB driver = null;

  151.         try {
  152.             // prendo una connessione
  153.             con = ControlStationCore.dbM.getConnection();
  154.             // istanzio il driver
  155.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  156.             return driver.isAccordoCooperazioneInUso(ac, whereIsInUso, normalizeObjectIds);
  157.         } catch (Exception e) {
  158.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  159.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  160.         } finally {
  161.             ControlStationCore.dbM.releaseConnection(con);
  162.         }
  163.     }

  164.    
  165.    
  166.     public boolean existsAccordoCooperazione(IDAccordoCooperazione idAccordo) throws DriverRegistroServiziException {
  167.         Connection con = null;
  168.         String nomeMetodo = "existsAccordoCooperazione";
  169.         DriverControlStationDB driver = null;

  170.         try {
  171.             // prendo una connessione
  172.             con = ControlStationCore.dbM.getConnection();
  173.             // istanzio il driver
  174.             driver = new DriverControlStationDB(con, null, this.tipoDB);
  175.             return driver.getDriverRegistroServiziDB().existsAccordoCooperazione(idAccordo);
  176.         } catch (Exception e) {
  177.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  178.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  179.         } finally {
  180.             ControlStationCore.dbM.releaseConnection(con);
  181.         }
  182.     }

  183.     public IDAccordoCooperazione getIdAccordoCooperazione(long idAccordo)
  184.             throws DriverRegistroServiziException,
  185.             DriverRegistroServiziNotFound {
  186.         Connection con = null;
  187.         String nomeMetodo = "getIdAccordoCooperazione";
  188.         DriverControlStationDB driver = null;

  189.         try {
  190.             // prendo una connessione
  191.             con = ControlStationCore.dbM.getConnection();
  192.             // istanzio il driver
  193.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  194.             return driver.getDriverRegistroServiziDB().getIdAccordoCooperazione(idAccordo);

  195.         } catch (Exception e) {
  196.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  197.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  198.         } finally {
  199.             ControlStationCore.dbM.releaseConnection(con);
  200.         }
  201.     }
  202.    
  203.     public AccordoCooperazione getAccordoCooperazione(IDAccordoCooperazione idAccordo)
  204.             throws DriverRegistroServiziException,
  205.             DriverRegistroServiziNotFound {
  206.         Connection con = null;
  207.         String nomeMetodo = "getAccordoCooperazione(id)";
  208.         DriverControlStationDB driver = null;

  209.         try {
  210.             // prendo una connessione
  211.             con = ControlStationCore.dbM.getConnection();
  212.             // istanzio il driver
  213.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  214.             return driver.getDriverRegistroServiziDB().getAccordoCooperazione(idAccordo);

  215.         } catch (Exception e) {
  216.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  217.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  218.         } finally {
  219.             ControlStationCore.dbM.releaseConnection(con);
  220.         }
  221.     }

  222.     public AccordoCooperazione getAccordoCooperazione(IDAccordoCooperazione idAccordo,boolean deepRead) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  223.         Connection con = null;
  224.         String nomeMetodo = "getAccordoCooperazione(id,deepRead)";
  225.         DriverControlStationDB driver = null;

  226.         try {
  227.             // prendo una connessione
  228.             con = ControlStationCore.dbM.getConnection();
  229.             // istanzio il driver
  230.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  231.             return driver.getDriverRegistroServiziDB().getAccordoCooperazione(idAccordo,deepRead);
  232.         } catch (DriverRegistroServiziNotFound e) {
  233.             ControlStationCore.logDebug(getPrefixError(nomeMetodo,  e), e);
  234.             throw e;
  235.         } catch (DriverRegistroServiziException e) {
  236.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  237.             throw e;
  238.         } catch (Exception e) {
  239.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  240.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  241.         } finally {
  242.             ControlStationCore.dbM.releaseConnection(con);
  243.         }
  244.     }

  245.     public AccordoCooperazione getAccordoCooperazione(long idAccordo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  246.         Connection con = null;
  247.         String nomeMetodo = "getAccordoCooperazione";
  248.         DriverControlStationDB driver = null;

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

  254.             return driver.getDriverRegistroServiziDB().getAccordoCooperazione(idAccordo);
  255.         } catch (DriverRegistroServiziNotFound e) {
  256.             ControlStationCore.logDebug(getPrefixError(nomeMetodo,  e), e);
  257.             throw e;
  258.         } catch (DriverRegistroServiziException e) {
  259.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  260.             throw e;
  261.         } catch (Exception e) {
  262.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  263.             throw new DriverRegistroServiziException("[RegservCore::" + nomeMetodo + "] Error :" + e.getMessage(), e);
  264.         } finally {
  265.             ControlStationCore.dbM.releaseConnection(con);
  266.         }
  267.     }

  268.     public List<IDAccordoCooperazione> getAllIdAccordiCooperazione(
  269.             FiltroRicercaAccordi filtroRicerca)
  270.             throws DriverRegistroServiziException,
  271.             DriverRegistroServiziNotFound {
  272.         Connection con = null;
  273.         String nomeMetodo = "getAccordoCooperazione";
  274.         DriverControlStationDB driver = null;

  275.         try {
  276.             // prendo una connessione
  277.             con = ControlStationCore.dbM.getConnection();
  278.             // istanzio il driver
  279.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  280.             return driver.getDriverRegistroServiziDB().getAllIdAccordiCooperazione(filtroRicerca);

  281.         } catch (DriverRegistroServiziNotFound e) {
  282.             ControlStationCore.logDebug(getPrefixError(nomeMetodo,  e),e);
  283.             throw e;
  284.         }catch (Exception e) {
  285.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  286.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e),e);
  287.         } finally {
  288.             ControlStationCore.dbM.releaseConnection(con);
  289.         }
  290.     }
  291.    
  292.     public List<AccordoCooperazione> accordiCoopWithSoggettoPartecipante(IDSoggetto idSoggetto) throws DriverRegistroServiziException {
  293.         Connection con = null;
  294.         String nomeMetodo = "accordiCoopWithSoggettoPartecipante";
  295.         DriverRegistroServiziDB driver = null;
  296.            
  297.         try {
  298.             // prendo una connessione
  299.             con = ControlStationCore.dbM.getConnection();
  300.             // istanzio il driver
  301.             driver = new DriverRegistroServiziDB(con, ControlStationCore.log, this.tipoDB);
  302.        
  303.             return driver.accordiCoopWithSoggettoPartecipante(idSoggetto);
  304.         } catch (DriverRegistroServiziException e) {
  305.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  306.             throw e;
  307.         } catch (Exception e) {
  308.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  309.             throw new DriverRegistroServiziException(getPrefixError(nomeMetodo,  e), e);
  310.         } finally {
  311.             ControlStationCore.dbM.releaseConnection(con);
  312.         }
  313.     }
  314. }