ServiceIdentificationReader.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.basic.registry;

  21. import org.openspcoop2.core.config.PortaApplicativa;
  22. import org.openspcoop2.core.config.PortaDelegata;
  23. import org.openspcoop2.core.id.IDPortaApplicativa;
  24. import org.openspcoop2.core.id.IDPortaDelegata;
  25. import org.openspcoop2.core.id.IDServizio;
  26. import org.openspcoop2.core.id.IDSoggetto;
  27. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  28. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  29. import org.openspcoop2.protocol.sdk.constants.CodiceErroreIntegrazione;
  30. import org.openspcoop2.protocol.sdk.constants.ErroreIntegrazione;
  31. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  32. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;
  33. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  34. import org.openspcoop2.protocol.sdk.registry.IServiceIdentificationReader;
  35. import org.openspcoop2.protocol.sdk.registry.RegistryNotFound;
  36. import org.openspcoop2.utils.transport.TransportRequestContext;
  37. import org.slf4j.Logger;

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

  46.     private IRegistryReader registryReader;
  47.     private IConfigIntegrationReader configIntegrationReader;
  48.     private IProtocolFactory<?> protocolFactory;
  49.     private Logger log;
  50.     public ServiceIdentificationReader(IRegistryReader registryReader, IConfigIntegrationReader configIntegrationReader,
  51.             IProtocolFactory<?> protocolFactory, Logger log) {
  52.         this.registryReader = registryReader;
  53.         this.configIntegrationReader = configIntegrationReader;
  54.         this.protocolFactory = protocolFactory;
  55.         this.log = log;
  56.     }
  57.    
  58.     private ErroreIntegrazione erroreIntegrazioneNotFound;
  59.    
  60.     public ErroreIntegrazione getErroreIntegrazioneNotFound() {
  61.         return this.erroreIntegrazioneNotFound;
  62.     }
  63.    
  64.     public IRegistryReader getRegistryReader() {
  65.         return this.registryReader;
  66.     }

  67.     public IConfigIntegrationReader getConfigIntegrationReader() {
  68.         return this.configIntegrationReader;
  69.     }
  70.    
  71.    
  72.     // PORTA DELEGATA
  73.    
  74.     private PortaDelegata pd;
  75.     private IDPortaDelegata idPD;
  76.    
  77.     @Override
  78.     public IDPortaDelegata findPortaDelegata(TransportRequestContext transportRequestContext, boolean portaUrlBased) throws RegistryNotFound{
  79.            
  80.         IdentificazionePortaDelegata idPD = null;
  81.         try{
  82.        
  83.             idPD = new IdentificazionePortaDelegata(transportRequestContext, this.log, portaUrlBased,
  84.                     this.registryReader, this.configIntegrationReader, this.protocolFactory);
  85.             if(idPD.process()==false){
  86.                 if(CodiceErroreIntegrazione.CODICE_401_PORTA_INESISTENTE.equals(idPD.getCodiceErrore())){
  87.                     throw new RegistryNotFound(idPD.getMessaggioErrore());
  88.                 }
  89.                 else {
  90.                     throw new Exception(idPD.getMessaggioErrore());
  91.                 }
  92.             }
  93.             this.pd = idPD.getPortaDelegata();
  94.             this.idPD = idPD.getIDPortaDelegata();
  95.            
  96.             if(this.idPD.getIdentificativiFruizione()!=null){
  97.                 if(this.idPD.getIdentificativiFruizione().getIdServizio()!=null){
  98.                     if(this.idPD.getIdentificativiFruizione().getIdServizio().getSoggettoErogatore()!=null){
  99.                         if(this.idPD.getIdentificativiFruizione().getIdServizio().getSoggettoErogatore().getCodicePorta()==null){
  100.                             this.idPD.getIdentificativiFruizione().getIdServizio().getSoggettoErogatore().setCodicePorta(
  101.                                     this.registryReader.getDominio(this.idPD.getIdentificativiFruizione().getIdServizio().getSoggettoErogatore()));
  102.                         }
  103.                     }
  104.                 }
  105.                 if(this.idPD.getIdentificativiFruizione().getSoggettoFruitore()!=null){
  106.                     if(this.idPD.getIdentificativiFruizione().getSoggettoFruitore().getCodicePorta()==null){
  107.                         this.idPD.getIdentificativiFruizione().getSoggettoFruitore().setCodicePorta(
  108.                                 this.registryReader.getDominio(this.idPD.getIdentificativiFruizione().getSoggettoFruitore()));
  109.                     }
  110.                 }
  111.             }
  112.            
  113.             return this.idPD;
  114.            
  115.         }
  116.         catch(RegistryNotFound e){
  117.             this.erroreIntegrazioneNotFound = idPD.getErroreIntegrazione();
  118.             throw e;
  119.         }
  120.         catch(Exception e){
  121.             this.log.error("findPortaDelegata error: "+e.getMessage(),e);
  122.             return null;
  123.         }

  124.     }
  125.    
  126.     @Override
  127.     public IDSoggetto convertToIDSoggettoFruitore(IDPortaDelegata idPortaDelegata) throws RegistryNotFound{
  128.        
  129.         try{
  130.             if(this.idPD!=null && this.idPD.getIdentificativiFruizione()!=null &&
  131.                     this.idPD.getIdentificativiFruizione().getSoggettoFruitore()!=null){
  132.                 return this.idPD.getIdentificativiFruizione().getSoggettoFruitore();
  133.             }
  134.            
  135.             if(this.pd==null){
  136.                 this.pd = this.configIntegrationReader.getPortaDelegata(idPortaDelegata);
  137.             }
  138.             IDSoggetto idS = new IDSoggetto(this.pd.getTipoSoggettoProprietario(), this.pd.getNomeSoggettoProprietario());
  139.             if(idS.getCodicePorta()==null){
  140.                 idS.setCodicePorta(this.registryReader.getDominio(idS));
  141.             }
  142.            
  143.             return idS;
  144.         }
  145.         catch(RegistryNotFound e){
  146.             this.erroreIntegrazioneNotFound =
  147.                     ErroriIntegrazione.ERRORE_401_PORTA_INESISTENTE.
  148.                     getErrore401_PortaInesistente(e.getMessage(),idPortaDelegata.getNome(),idPortaDelegata.getNome());
  149.             throw e;
  150.         }
  151.         catch(Exception e){
  152.             return null;
  153.         }
  154.        
  155.     }
  156.    
  157.     @Override
  158.     public IDServizio convertToIDServizio(IDPortaDelegata idPortaDelegata) throws RegistryNotFound{
  159.        
  160.         try{
  161.             if(this.idPD!=null && this.idPD.getIdentificativiFruizione()!=null &&
  162.                     this.idPD.getIdentificativiFruizione().getIdServizio()!=null){
  163.                 return this.idPD.getIdentificativiFruizione().getIdServizio();
  164.             }
  165.            
  166.             if(this.pd==null){
  167.                 this.pd = this.configIntegrationReader.getPortaDelegata(idPortaDelegata);
  168.             }
  169.             IDServizio idS = IDServizioFactory.getInstance().getIDServizioFromValues(this.pd.getServizio().getTipo(), this.pd.getServizio().getNome(),
  170.                     new IDSoggetto(this.pd.getSoggettoErogatore().getTipo(), this.pd.getSoggettoErogatore().getNome()),
  171.                     this.pd.getServizio().getVersione());          
  172.             if(idS.getSoggettoErogatore().getCodicePorta()==null){
  173.                 idS.getSoggettoErogatore().setCodicePorta(this.registryReader.getDominio(idS.getSoggettoErogatore()));
  174.             }
  175.            
  176.             return idS;
  177.         }
  178.         catch(RegistryNotFound e){
  179.             this.erroreIntegrazioneNotFound =
  180.                     ErroriIntegrazione.ERRORE_401_PORTA_INESISTENTE.
  181.                     getErrore401_PortaInesistente(e.getMessage(),idPortaDelegata.getNome(),idPortaDelegata.getNome());
  182.             throw e;
  183.         }
  184.         catch(Exception e){
  185.             return null;
  186.         }
  187.        
  188.     }
  189.    
  190.    
  191.     // PORTA APPLICATIVA
  192.    
  193.     private PortaApplicativa pa;
  194.     private IDPortaApplicativa idPA;
  195.    
  196.     @Override
  197.     public IDPortaApplicativa findPortaApplicativa(TransportRequestContext transportRequestContext, boolean portaUrlBased) throws RegistryNotFound{
  198.        
  199.         IdentificazionePortaApplicativa idPA = null;
  200.         try{
  201.            
  202.             idPA = new IdentificazionePortaApplicativa(transportRequestContext, this.log, portaUrlBased,
  203.                     this.registryReader, this.configIntegrationReader, this.protocolFactory);
  204.             if(idPA.process()==false){
  205.                 if(CodiceErroreIntegrazione.CODICE_401_PORTA_INESISTENTE.equals(idPA.getCodiceErrore())){
  206.                     throw new RegistryNotFound(idPA.getMessaggioErrore());
  207.                 }
  208.                 else {
  209.                     throw new Exception(idPA.getMessaggioErrore());
  210.                 }
  211.             }
  212.             this.pa = idPA.getPortaApplicativa();
  213.             this.idPA = idPA.getIDPortaApplicativa();
  214.            
  215.             if(this.idPA.getIdentificativiErogazione()!=null){
  216.                 if(this.idPA.getIdentificativiErogazione().getSoggettoVirtuale()!=null){
  217.                     if(this.idPA.getIdentificativiErogazione().getSoggettoVirtuale().getCodicePorta()==null){
  218.                         this.idPA.getIdentificativiErogazione().getSoggettoVirtuale().setCodicePorta(this.registryReader.getDominio(this.idPA.getIdentificativiErogazione().getSoggettoVirtuale()));
  219.                     }
  220.                 }
  221.                 if(this.idPA.getIdentificativiErogazione().getIdServizio()!=null){
  222.                     if(this.idPA.getIdentificativiErogazione().getIdServizio().getSoggettoErogatore()!=null){
  223.                         if(this.idPA.getIdentificativiErogazione().getIdServizio().getSoggettoErogatore().getCodicePorta()==null){
  224.                             this.idPA.getIdentificativiErogazione().getIdServizio().getSoggettoErogatore().setCodicePorta(
  225.                                     this.registryReader.getDominio(this.idPA.getIdentificativiErogazione().getIdServizio().getSoggettoErogatore()));
  226.                         }
  227.                     }
  228.                 }
  229.             }
  230.            
  231.             return this.idPA;
  232.            
  233.         }
  234.         catch(RegistryNotFound e){
  235.             this.erroreIntegrazioneNotFound = idPA.getErroreIntegrazione();
  236.             throw e;
  237.         }
  238.         catch(Exception e){
  239.             this.log.error("findPortaDelegata error: "+e.getMessage(),e);
  240.             return null;
  241.         }
  242.        
  243.     }
  244.    
  245.     @Override
  246.     public IDServizio convertToIDServizio(IDPortaApplicativa idPortaApplicativa) throws RegistryNotFound{
  247.        
  248.         try{
  249.             if(this.idPA!=null && this.idPA.getIdentificativiErogazione()!=null &&
  250.                     this.idPA.getIdentificativiErogazione().getIdServizio()!=null){
  251.                 return this.idPA.getIdentificativiErogazione().getIdServizio();
  252.             }
  253.            
  254.             if(this.pa==null){
  255.                 this.pa = this.configIntegrationReader.getPortaApplicativa(idPortaApplicativa);
  256.             }
  257.             IDServizio idS = IDServizioFactory.getInstance().getIDServizioFromValues(this.pa.getServizio().getTipo(), this.pa.getServizio().getNome(),
  258.                     new IDSoggetto(this.pa.getTipoSoggettoProprietario(),this.pa.getNomeSoggettoProprietario()),
  259.                     this.pa.getServizio().getVersione());      
  260.            
  261.             if(idS.getSoggettoErogatore().getCodicePorta()==null){
  262.                 idS.getSoggettoErogatore().setCodicePorta(this.registryReader.getDominio(idS.getSoggettoErogatore()));
  263.             }
  264.            
  265.             return idS;
  266.         }
  267.         catch(RegistryNotFound e){
  268.             this.erroreIntegrazioneNotFound =
  269.                     ErroriIntegrazione.ERRORE_401_PORTA_INESISTENTE.
  270.                     getErrore401_PortaInesistente(e.getMessage(),idPortaApplicativa.getNome(),idPortaApplicativa.getNome());
  271.             throw e;
  272.         }
  273.         catch(Exception e){
  274.             return null;
  275.         }
  276.        
  277.     }
  278. }