ArchivePortaDelegata.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.sdk.archive;

  21. import org.openspcoop2.core.config.PortaDelegata;
  22. import org.openspcoop2.core.id.IDPortaDelegata;
  23. import org.openspcoop2.core.id.IDSoggetto;
  24. import org.openspcoop2.core.id.IdentificativiFruizione;
  25. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  26. import org.openspcoop2.protocol.sdk.ProtocolException;

  27. /**
  28.  * ArchivePortaDelegata
  29.  *
  30.  * @author Poli Andrea (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class ArchivePortaDelegata implements IArchiveObject {

  35.     public static String buildKey(String tipoSoggetto,String nomeSoggetto,String nomePorta) throws ProtocolException{
  36.        
  37.         if(tipoSoggetto==null){
  38.             throw new ProtocolException("tipoSoggetto non fornito");
  39.         }
  40.         if(nomeSoggetto==null){
  41.             throw new ProtocolException("nomeSoggetto non fornito");
  42.         }
  43.         if(nomePorta==null){
  44.             throw new ProtocolException("nomePorta non fornito");
  45.         }
  46.        
  47.         StringBuilder bf = new StringBuilder();
  48.         bf.append("PortaDelegata_");
  49.         bf.append(tipoSoggetto);
  50.         bf.append("/");
  51.         bf.append(nomeSoggetto);
  52.         bf.append("_");
  53.         bf.append(nomePorta);
  54.         return bf.toString();
  55.     }
  56.    
  57.     @Override
  58.     public String key() throws ProtocolException {
  59.         return ArchivePortaDelegata.buildKey(this.idSoggettoProprietario.getTipo(), this.idSoggettoProprietario.getNome(),
  60.                     this.idPortaDelegata.getNome());
  61.     }
  62.    
  63.    

  64.     private IDSoggetto idSoggettoProprietario;
  65.     private IDPortaDelegata idPortaDelegata;
  66.     private PortaDelegata portaDelegata;
  67.    
  68.     private ArchiveIdCorrelazione idCorrelazione; // permette di correlare più oggetti tra di loro
  69.    
  70.    
  71.    
  72.     public ArchivePortaDelegata(IDSoggetto idSoggettoProprietario, PortaDelegata portaDelegata, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  73.         this(injectProprietario(idSoggettoProprietario, portaDelegata),idCorrelazione, false);
  74.     }
  75.     public ArchivePortaDelegata(IDSoggetto idSoggettoProprietario, PortaDelegata portaDelegata, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  76.         this(injectProprietario(idSoggettoProprietario, portaDelegata), idCorrelazione, informationMissingManagementEnabled);
  77.     }
  78.     public ArchivePortaDelegata(PortaDelegata portaDelegata, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  79.         this(portaDelegata,idCorrelazione,false);
  80.     }  
  81.     public ArchivePortaDelegata(PortaDelegata portaDelegata, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  82.         this.update(portaDelegata, informationMissingManagementEnabled);
  83.         this.idCorrelazione = idCorrelazione;
  84.     }
  85.     private static PortaDelegata injectProprietario(IDSoggetto idSoggettoProprietario, PortaDelegata portaDelegata) throws ProtocolException{
  86.         if(portaDelegata==null){
  87.             throw new ProtocolException("PortaDelegata non fornita");
  88.         }
  89.         if(idSoggettoProprietario==null){
  90.             throw new ProtocolException("idSoggettoProprietario non fornito");
  91.         }
  92.         if(idSoggettoProprietario.getTipo()==null){
  93.             throw new ProtocolException("idSoggettoProprietario.tipo non definito");
  94.         }
  95.         if(idSoggettoProprietario.getNome()==null){
  96.             throw new ProtocolException("idSoggettoProprietario.nome non definito");
  97.         }
  98.         portaDelegata.setTipoSoggettoProprietario(idSoggettoProprietario.getTipo());
  99.         portaDelegata.setNomeSoggettoProprietario(idSoggettoProprietario.getNome());
  100.         return portaDelegata;
  101.     }
  102.    
  103.    
  104.    
  105.     public void update() throws ProtocolException{
  106.         this.update(this.portaDelegata, false);
  107.     }
  108.     public void update(PortaDelegata portaDelegata) throws ProtocolException{
  109.         this.update(portaDelegata, false);
  110.     }
  111.     public void update(PortaDelegata portaDelegata, boolean informationMissingManagementEnabled) throws ProtocolException{
  112.        
  113.         if(portaDelegata==null){
  114.             throw new ProtocolException("PortaDelegata non fornita");
  115.         }
  116.         if(portaDelegata.getNome()==null){
  117.             throw new ProtocolException("PortaDelegata.nome non definito");
  118.         }
  119.         this.portaDelegata = portaDelegata;
  120.        
  121.         if(informationMissingManagementEnabled==false){
  122.        
  123.             if(this.portaDelegata.getTipoSoggettoProprietario()==null){
  124.                 throw new ProtocolException("PortaDelegata.tipoSoggettoProprietario non definito");
  125.             }
  126.             if(this.portaDelegata.getNomeSoggettoProprietario()==null){
  127.                 throw new ProtocolException("PortaDelegata.nomeSoggettoProprietario non definito");
  128.             }
  129.             this.idSoggettoProprietario =
  130.                     new IDSoggetto(this.portaDelegata.getTipoSoggettoProprietario(),
  131.                             this.portaDelegata.getNomeSoggettoProprietario());
  132.            
  133.             this.idPortaDelegata = new IDPortaDelegata();
  134.             this.idPortaDelegata.setNome(this.portaDelegata.getNome());
  135.            
  136.             IdentificativiFruizione identificativiFruizione = new IdentificativiFruizione();
  137.             identificativiFruizione.setSoggettoFruitore(this.idSoggettoProprietario);

  138.             String tipoSoggettoErogatore = null;
  139.             String nomeSoggettoErogatore = null;
  140.             if(this.portaDelegata.getSoggettoErogatore()==null) {
  141.                 throw new ProtocolException("PortaDelegata.soggettoErogatore non definito");
  142.             }
  143.             if(this.portaDelegata.getSoggettoErogatore().getTipo()==null) {
  144.                 throw new ProtocolException("PortaDelegata.soggettoErogatore.tipo non definito");
  145.             }
  146.             tipoSoggettoErogatore = this.portaDelegata.getSoggettoErogatore().getTipo();
  147.             if(this.portaDelegata.getSoggettoErogatore().getNome()==null) {
  148.                 throw new ProtocolException("PortaDelegata.soggettoErogatore.nome non definito");
  149.             }
  150.             nomeSoggettoErogatore = this.portaDelegata.getSoggettoErogatore().getNome();

  151.             String tipoServizio = null;
  152.             String nomeServizio = null;
  153.             Integer versioneServizio = null;
  154.             if(this.portaDelegata.getServizio()==null) {
  155.                 throw new ProtocolException("PortaDelegata.servizio non definito");
  156.             }
  157.             if(this.portaDelegata.getServizio().getTipo()==null) {
  158.                 throw new ProtocolException("PortaDelegata.servizio.tipo non definito");
  159.             }
  160.             tipoServizio = this.portaDelegata.getServizio().getTipo();
  161.             if(this.portaDelegata.getServizio().getNome()==null) {
  162.                 throw new ProtocolException("PortaDelegata.servizio.nome non definito");
  163.             }
  164.             nomeServizio = this.portaDelegata.getServizio().getNome();
  165.             if(this.portaDelegata.getServizio().getVersione()==null) {
  166.                 throw new ProtocolException("PortaDelegata.servizio.versione non definito");
  167.             }
  168.             versioneServizio = this.portaDelegata.getServizio().getVersione();
  169.            
  170.             try {
  171.                 identificativiFruizione.setIdServizio(IDServizioFactory.getInstance().getIDServizioFromValues(tipoServizio, nomeServizio,
  172.                         tipoSoggettoErogatore, nomeSoggettoErogatore, versioneServizio));
  173.             }catch(Exception e) {
  174.                 throw new ProtocolException("PortaDelegata.idServizio non definito");
  175.             }
  176.             this.idPortaDelegata.setIdentificativiFruizione(identificativiFruizione);
  177.            
  178.         }
  179.     }
  180.    
  181.    
  182.    
  183.    
  184.    
  185.    
  186.     public IDSoggetto getIdSoggettoProprietario() {
  187.         return this.idSoggettoProprietario;
  188.     }
  189.     public IDPortaDelegata getIdPortaDelegata() {
  190.         return this.idPortaDelegata;
  191.     }
  192.     public PortaDelegata getPortaDelegata() {
  193.         return this.portaDelegata;
  194.     }
  195.    
  196.     public ArchiveIdCorrelazione getIdCorrelazione() {
  197.         return this.idCorrelazione;
  198.     }
  199. }