UtentiCore.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.utenti;

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

  23. import org.openspcoop2.core.commons.ISearch;
  24. import org.openspcoop2.core.id.IDServizio;
  25. import org.openspcoop2.core.id.IDSoggetto;
  26. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  27. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationDB;
  28. import org.openspcoop2.web.lib.users.DriverUsersDBException;
  29. import org.openspcoop2.web.lib.users.dao.User;
  30. import org.openspcoop2.web.lib.users.dao.UserObjects;

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

  39.     public UtentiCore() throws Exception {
  40.         super();
  41.     }
  42.     public UtentiCore(ControlStationCore core) throws Exception {
  43.         super(core);
  44.     }
  45.    
  46.    
  47.     public boolean existsUser(String login) throws DriverUsersDBException {
  48.         Connection con = null;
  49.         String nomeMetodo = "existsUser";
  50.         DriverControlStationDB driver = null;

  51.         try {
  52.             // prendo una connessione
  53.             con = ControlStationCore.dbM.getConnection();
  54.             // istanzio il driver
  55.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  56.             return driver.getDriverUsersDB().existsUser(login);

  57.         } catch (Exception e) {
  58.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  59.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  60.         } finally {
  61.             ControlStationCore.dbM.releaseConnection(con);
  62.         }

  63.     }

  64.     public List<String> getUsersWithType(String permesso) throws DriverUsersDBException {
  65.         Connection con = null;
  66.         String nomeMetodo = "getUsersWithType";
  67.         DriverControlStationDB driver = null;

  68.         try {
  69.             // prendo una connessione
  70.             con = ControlStationCore.dbM.getConnection();
  71.             // istanzio il driver
  72.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  73.             return driver.getDriverUsersDB().getUsersByPermesso(permesso);

  74.         } catch (Exception e) {
  75.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  76.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  77.         } finally {
  78.             ControlStationCore.dbM.releaseConnection(con);
  79.         }
  80.     }
  81.    
  82.     public User getUser(String login) throws DriverUsersDBException {
  83.         return getUser(login,true);
  84.     }
  85.     public User getUser(String login,boolean logError) throws DriverUsersDBException {
  86.         Connection con = null;
  87.         String nomeMetodo = "getUser";
  88.         DriverControlStationDB driver = null;

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

  94.             return driver.getDriverUsersDB().getUser(login);

  95.         } catch (Exception e) {
  96.             if(logError)
  97.                 ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  98.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  99.         } finally {
  100.             ControlStationCore.dbM.releaseConnection(con);
  101.         }

  102.     }
  103.    
  104.     public User getUser(long id) throws DriverUsersDBException {
  105.         Connection con = null;
  106.         String nomeMetodo = "getUser";
  107.         DriverControlStationDB driver = null;

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

  113.             return driver.getDriverUsersDB().getUser(id);

  114.         } catch (Exception e) {
  115.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  116.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  117.         } finally {
  118.             ControlStationCore.dbM.releaseConnection(con);
  119.         }

  120.     }

  121.     public List<User> userList(ISearch ricerca) throws DriverUsersDBException {
  122.         Connection con = null;
  123.         String nomeMetodo = "userList";
  124.         DriverControlStationDB driver = null;

  125.         try {
  126.             // prendo una connessione
  127.             con = ControlStationCore.dbM.getConnection();
  128.             // istanzio il driver
  129.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  130.             return driver.getDriverUsersDB().userList(ricerca);

  131.         } catch (Exception e) {
  132.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  133.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  134.         } finally {
  135.             ControlStationCore.dbM.releaseConnection(con);
  136.         }
  137.     }
  138.    
  139.     public List<String> getUsersByProtocolloSupportato(String protocollo) throws DriverUsersDBException {
  140.         return getUsersByProtocolloSupportato(protocollo, false);
  141.     }
  142.    
  143.     public List<String> getUsersByProtocolloSupportato(String protocollo, boolean esclusiUtentiConSoloPermessoUtente) throws DriverUsersDBException {
  144.         Connection con = null;
  145.         String nomeMetodo = "getUsersByProtocolloSupportato";
  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.getDriverUsersDB().getUsersByProtocolloSupportato(protocollo,esclusiUtentiConSoloPermessoUtente);

  153.         } catch (Exception e) {
  154.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  155.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  156.         } finally {
  157.             ControlStationCore.dbM.releaseConnection(con);
  158.         }
  159.     }
  160.    
  161.     public List<IDServizio> utentiServiziList(String login, ISearch ricerca) throws DriverUsersDBException {
  162.         Connection con = null;
  163.         String nomeMetodo = "utentiServiziList";
  164.         DriverControlStationDB driver = null;

  165.         try {
  166.             // prendo una connessione
  167.             con = ControlStationCore.dbM.getConnection();
  168.             // istanzio il driver
  169.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  170.             return driver.getDriverUsersDB().utentiServiziList(login,ricerca);

  171.         } catch (Exception e) {
  172.             ControlStationCore.logError("[ControlStationCore::" + nomeMetodo + "] Exception :" + e.getMessage(), e);
  173.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  174.         } finally {
  175.             ControlStationCore.dbM.releaseConnection(con);
  176.         }

  177.     }
  178.    
  179.     public List<IDSoggetto> utentiSoggettiList(String login, ISearch ricerca) throws DriverUsersDBException {
  180.         Connection con = null;
  181.         String nomeMetodo = "utentiSoggettiList";
  182.         DriverControlStationDB driver = null;

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

  188.             return driver.getDriverUsersDB().utentiSoggettiList(login,ricerca);

  189.         } catch (Exception e) {
  190.             ControlStationCore.logError("[ControlStationCore::" + nomeMetodo + "] Exception :" + e.getMessage(), e);
  191.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  192.         } finally {
  193.             ControlStationCore.dbM.releaseConnection(con);
  194.         }

  195.     }
  196.    
  197.     public void salvaModalitaUserPddConsole(String login,String protocollo) throws DriverUsersDBException {
  198.         Connection con = null;
  199.         String nomeMetodo = "salvaModalitaUserPddConsole";
  200.         DriverControlStationDB driver = null;

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

  206.             driver.getDriverUsersDB().saveProtocolloUtilizzatoPddConsole(login, protocollo);

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

  213.     }
  214.    
  215.     public void salvaSoggettoOperativoUserPddConsole(String login,String soggetto) throws DriverUsersDBException {
  216.         Connection con = null;
  217.         String nomeMetodo = "salvaSoggettoOperativoUserPddConsole";
  218.         DriverControlStationDB driver = null;

  219.         try {
  220.             // prendo una connessione
  221.             con = ControlStationCore.dbM.getConnection();
  222.             // istanzio il driver
  223.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  224.             driver.getDriverUsersDB().saveSoggettoUtilizzatoPddConsole(login, soggetto);

  225.         } catch (Exception e) {
  226.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  227.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  228.         } finally {
  229.             ControlStationCore.dbM.releaseConnection(con);
  230.         }

  231.     }
  232.    
  233.     public void modificaSoggettoUtilizzatoConsole(String oldSoggetto,String newSoggetto) throws DriverUsersDBException {
  234.         Connection con = null;
  235.         String nomeMetodo = "modificaSoggettoUtilizzatoConsole";
  236.         DriverControlStationDB driver = null;

  237.         try {
  238.             // prendo una connessione
  239.             con = ControlStationCore.dbM.getConnection();
  240.             // istanzio il driver
  241.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  242.             driver.getDriverUsersDB().modificaSoggettoUtilizzatoConsole(oldSoggetto, newSoggetto);

  243.         } catch (Exception e) {
  244.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  245.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  246.         } finally {
  247.             ControlStationCore.dbM.releaseConnection(con);
  248.         }

  249.     }
  250.    
  251.     public UserObjects countUserServizi(String login) throws DriverUsersDBException {
  252.         Connection con = null;
  253.         String nomeMetodo = "countUserServizi";
  254.         DriverControlStationDB driver = null;

  255.         try {
  256.             // prendo una connessione
  257.             con = ControlStationCore.dbM.getConnection();
  258.             // istanzio il driver
  259.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  260.             return driver.getDriverUsersDB().countUserServizi(login);

  261.         } catch (Exception e) {
  262.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  263.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  264.         } finally {
  265.             ControlStationCore.dbM.releaseConnection(con);
  266.         }

  267.     }
  268.    
  269.     public UserObjects countUserCooperazione(String login) throws DriverUsersDBException {
  270.         Connection con = null;
  271.         String nomeMetodo = "countUserCooperazione";
  272.         DriverControlStationDB driver = null;

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

  278.             return driver.getDriverUsersDB().countUserCooperazione(login);

  279.         } catch (Exception e) {
  280.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  281.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  282.         } finally {
  283.             ControlStationCore.dbM.releaseConnection(con);
  284.         }

  285.     }
  286.    
  287.     public UserObjects updateUserServizi(String oldUser, String newUser) throws DriverUsersDBException {
  288.         Connection con = null;
  289.         String nomeMetodo = "updateUserServizi";
  290.         DriverControlStationDB driver = null;

  291.         try {
  292.             // prendo una connessione
  293.             con = ControlStationCore.dbM.getConnection();
  294.             // istanzio il driver
  295.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  296.             return driver.getDriverUsersDB().updateUserServizi(oldUser, newUser);

  297.         } catch (Exception e) {
  298.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  299.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  300.         } finally {
  301.             ControlStationCore.dbM.releaseConnection(con);
  302.         }

  303.     }
  304.    
  305.     public UserObjects updateUserCooperazione(String oldUser, String newUser) throws DriverUsersDBException {
  306.         Connection con = null;
  307.         String nomeMetodo = "updateUserCooperazione";
  308.         DriverControlStationDB driver = null;

  309.         try {
  310.             // prendo una connessione
  311.             con = ControlStationCore.dbM.getConnection();
  312.             // istanzio il driver
  313.             driver = new DriverControlStationDB(con, null, this.tipoDB);

  314.             return driver.getDriverUsersDB().updateUserCooperazione(oldUser, newUser);

  315.         } catch (Exception e) {
  316.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  317.             throw new DriverUsersDBException(getPrefixError(nomeMetodo,  e),e);
  318.         } finally {
  319.             ControlStationCore.dbM.releaseConnection(con);
  320.         }

  321.     }
  322. }