RegistryReaderInUso.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.registry;

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

  25. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  26. import org.openspcoop2.core.id.IDAccordo;
  27. import org.openspcoop2.core.id.IDPortType;
  28. import org.openspcoop2.core.id.IDPortTypeAzione;
  29. import org.openspcoop2.core.id.IDResource;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.core.registry.driver.IDriverRegistroServiziGet;
  32. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  33. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  34. import org.openspcoop2.protocol.sdk.registry.IRegistryReaderInUso;
  35. import org.openspcoop2.protocol.sdk.registry.RegistryException;
  36. import org.slf4j.Logger;

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

  45.     private IDriverRegistroServiziGet driverRegistroServiziGET;
  46.     @SuppressWarnings("unused")
  47.     private Logger log;
  48.    
  49.     public RegistryReaderInUso() {}
  50.    
  51.     @Override
  52.     public void init(IDriverRegistroServiziGet driverRegistroServizi, Logger log) {
  53.         this.driverRegistroServiziGET = driverRegistroServizi;
  54.         this.log = log;
  55.     }
  56.    
  57.    
  58.    
  59.     // SOGGETTI
  60.    
  61.     @Override
  62.     public boolean inUso(IDSoggetto idSoggetto, boolean verificaRuoli) throws RegistryException{
  63.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  64.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  65.             Connection connection = null;
  66.             try {
  67.                 connection = driverDB.getConnection("inUso(IDSoggetto)");
  68.                
  69.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  70.                
  71.                 boolean normalizeObjectIds = true;
  72.                 return DBOggettiInUsoUtils.isSoggettoRegistryInUso(connection, driverDB.getTipoDB(), idSoggetto, true, whereIsInUso, normalizeObjectIds, verificaRuoli);
  73.                
  74.             }
  75.             catch(Exception e) {
  76.                 throw new RegistryException(e.getMessage(),e);
  77.             }
  78.             finally {
  79.                 driverDB.releaseConnection(connection);
  80.             }
  81.         }
  82.         else {
  83.             throw new RuntimeException("Not Implemented");
  84.         }
  85.     }
  86.     @Override
  87.     public String getDettagliInUso(IDSoggetto idSoggetto, boolean verificaRuoli) throws RegistryException{
  88.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  89.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  90.             Connection connection = null;
  91.             try {
  92.                 connection = driverDB.getConnection("getDettagliInUso(IDSoggetto)");
  93.                
  94.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  95.                
  96.                 boolean normalizeObjectIds = true;
  97.                 boolean inUso = DBOggettiInUsoUtils.isSoggettoRegistryInUso(connection, driverDB.getTipoDB(), idSoggetto, true, whereIsInUso, normalizeObjectIds, verificaRuoli);
  98.                 if(inUso) {
  99.                     return DBOggettiInUsoUtils.toString(idSoggetto , whereIsInUso, false, "\n", normalizeObjectIds);
  100.                 }
  101.                 else {
  102.                     return null;
  103.                 }
  104.             }
  105.             catch(Exception e) {
  106.                 throw new RegistryException(e.getMessage(),e);
  107.             }
  108.             finally {
  109.                 driverDB.releaseConnection(connection);
  110.             }
  111.         }
  112.         else {
  113.             throw new RuntimeException("Not Implemented");
  114.         }
  115.     }
  116.    
  117.    
  118.     // ACCORDI PARTE COMUNE
  119.    
  120.     @Override
  121.     public boolean inUso(IDAccordo idAccordo) throws RegistryException{
  122.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  123.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  124.             Connection connection = null;
  125.             try {
  126.                 connection = driverDB.getConnection("inUso(IDAccordo)");
  127.                
  128.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  129.                
  130.                 boolean normalizeObjectIds = true;
  131.                 return DBOggettiInUsoUtils.isAccordoServizioParteComuneInUso(connection, driverDB.getTipoDB(), idAccordo, whereIsInUso, normalizeObjectIds);
  132.                
  133.             }
  134.             catch(Exception e) {
  135.                 throw new RegistryException(e.getMessage(),e);
  136.             }
  137.             finally {
  138.                 driverDB.releaseConnection(connection);
  139.             }
  140.         }
  141.         else {
  142.             throw new RuntimeException("Not Implemented");
  143.         }
  144.     }
  145.     @Override
  146.     public String getDettagliInUso(IDAccordo idAccordo) throws RegistryException{
  147.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  148.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  149.             Connection connection = null;
  150.             try {
  151.                 connection = driverDB.getConnection("getDettagliInUso(IDAccordo)");
  152.                
  153.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  154.                
  155.                 boolean normalizeObjectIds = true;
  156.                 boolean inUso = DBOggettiInUsoUtils.isAccordoServizioParteComuneInUso(connection, driverDB.getTipoDB(), idAccordo, whereIsInUso, normalizeObjectIds);
  157.                 if(inUso) {
  158.                     return DBOggettiInUsoUtils.toString(idAccordo , whereIsInUso, false, "\n", normalizeObjectIds);
  159.                 }
  160.                 else {
  161.                     return null;
  162.                 }
  163.             }
  164.             catch(Exception e) {
  165.                 throw new RegistryException(e.getMessage(),e);
  166.             }
  167.             finally {
  168.                 driverDB.releaseConnection(connection);
  169.             }
  170.         }
  171.         else {
  172.             throw new RuntimeException("Not Implemented");
  173.         }
  174.     }
  175.    
  176.    
  177.    
  178.     // ELEMENTI INTERNI ALL'ACCORDO PARTE COMUNE
  179.    
  180.     @Override
  181.     public boolean inUso(IDPortType id) throws RegistryException{
  182.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  183.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  184.             Connection connection = null;
  185.             try {
  186.                 connection = driverDB.getConnection("inUso(IDPortType)");
  187.                
  188.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  189.                
  190.                 boolean normalizeObjectIds = true;
  191.                 return DBOggettiInUsoUtils.isPortTypeInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  192.                
  193.             }
  194.             catch(Exception e) {
  195.                 throw new RegistryException(e.getMessage(),e);
  196.             }
  197.             finally {
  198.                 driverDB.releaseConnection(connection);
  199.             }
  200.         }
  201.         else {
  202.             throw new RuntimeException("Not Implemented");
  203.         }
  204.     }
  205.     @Override
  206.     public String getDettagliInUso(IDPortType id) throws RegistryException{
  207.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  208.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  209.             Connection connection = null;
  210.             try {
  211.                 connection = driverDB.getConnection("getDettagliInUso(IDPortType)");
  212.                
  213.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  214.                
  215.                 boolean normalizeObjectIds = true;
  216.                 boolean inUso = DBOggettiInUsoUtils.isPortTypeInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  217.                 if(inUso) {
  218.                     return DBOggettiInUsoUtils.toString(id , whereIsInUso, false, "\n", "");
  219.                 }
  220.                 else {
  221.                     return null;
  222.                 }
  223.             }
  224.             catch(Exception e) {
  225.                 throw new RegistryException(e.getMessage(),e);
  226.             }
  227.             finally {
  228.                 driverDB.releaseConnection(connection);
  229.             }
  230.         }
  231.         else {
  232.             throw new RuntimeException("Not Implemented");
  233.         }
  234.     }
  235.    
  236.    
  237.     @Override
  238.     public boolean inUso(IDPortTypeAzione id) throws RegistryException{
  239.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  240.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  241.             Connection connection = null;
  242.             try {
  243.                 connection = driverDB.getConnection("inUso(IDPortTypeAzione)");
  244.                
  245.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  246.                
  247.                 boolean normalizeObjectIds = true;
  248.                 return DBOggettiInUsoUtils.isOperazioneInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  249.                
  250.             }
  251.             catch(Exception e) {
  252.                 throw new RegistryException(e.getMessage(),e);
  253.             }
  254.             finally {
  255.                 driverDB.releaseConnection(connection);
  256.             }
  257.         }
  258.         else {
  259.             throw new RuntimeException("Not Implemented");
  260.         }
  261.     }
  262.     @Override
  263.     public String getDettagliInUso(IDPortTypeAzione id) throws RegistryException{
  264.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  265.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  266.             Connection connection = null;
  267.             try {
  268.                 connection = driverDB.getConnection("getDettagliInUso(IDPortTypeAzione)");
  269.                
  270.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  271.                
  272.                 boolean normalizeObjectIds = true;
  273.                 boolean inUso = DBOggettiInUsoUtils.isOperazioneInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  274.                 if(inUso) {
  275.                     return DBOggettiInUsoUtils.toString(id , whereIsInUso, false, "\n", "");
  276.                 }
  277.                 else {
  278.                     return null;
  279.                 }
  280.             }
  281.             catch(Exception e) {
  282.                 throw new RegistryException(e.getMessage(),e);
  283.             }
  284.             finally {
  285.                 driverDB.releaseConnection(connection);
  286.             }
  287.         }
  288.         else {
  289.             throw new RuntimeException("Not Implemented");
  290.         }
  291.     }
  292.    
  293.    
  294.     @Override
  295.     public boolean inUso(IDResource id) throws RegistryException{
  296.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  297.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  298.             Connection connection = null;
  299.             try {
  300.                 connection = driverDB.getConnection("inUso(IDResource)");
  301.                
  302.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  303.                
  304.                 boolean normalizeObjectIds = true;
  305.                 return DBOggettiInUsoUtils.isRisorsaInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  306.                
  307.             }
  308.             catch(Exception e) {
  309.                 throw new RegistryException(e.getMessage(),e);
  310.             }
  311.             finally {
  312.                 driverDB.releaseConnection(connection);
  313.             }
  314.         }
  315.         else {
  316.             throw new RuntimeException("Not Implemented");
  317.         }
  318.     }
  319.     @Override
  320.     public String getDettagliInUso(IDResource id) throws RegistryException{
  321.         if(this.driverRegistroServiziGET instanceof DriverRegistroServiziDB) {
  322.             DriverRegistroServiziDB driverDB = (DriverRegistroServiziDB) this.driverRegistroServiziGET;
  323.             Connection connection = null;
  324.             try {
  325.                 connection = driverDB.getConnection("getDettagliInUso(IDResource)");
  326.                
  327.                 Map<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  328.                
  329.                 boolean normalizeObjectIds = true;
  330.                 boolean inUso = DBOggettiInUsoUtils.isRisorsaInUso(connection, driverDB.getTipoDB(), id, whereIsInUso, normalizeObjectIds);
  331.                 if(inUso) {
  332.                    
  333.                     String methodPath = null; // prefix non aggiunto
  334.                    
  335.                     return DBOggettiInUsoUtils.toString(id , methodPath, whereIsInUso, false, "\n", "");
  336.                 }
  337.                 else {
  338.                     return null;
  339.                 }
  340.             }
  341.             catch(Exception e) {
  342.                 throw new RegistryException(e.getMessage(),e);
  343.             }
  344.             finally {
  345.                 driverDB.releaseConnection(connection);
  346.             }
  347.         }
  348.         else {
  349.             throw new RuntimeException("Not Implemented");
  350.         }
  351.     }

  352. }