ArchiveSoggetto.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.id.IDSoggetto;
  22. import org.openspcoop2.protocol.sdk.ProtocolException;

  23. /**
  24.  * ArchiveSoggetto
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class ArchiveSoggetto implements IArchiveObject {

  31.     public static String buildKey(String tipoSoggetto,String nomeSoggetto) throws ProtocolException{
  32.        
  33.         if(tipoSoggetto==null){
  34.             throw new ProtocolException("tipoSoggetto non fornito");
  35.         }
  36.         if(nomeSoggetto==null){
  37.             throw new ProtocolException("nomeSoggetto non fornito");
  38.         }
  39.        
  40.         StringBuilder bf = new StringBuilder();
  41.         bf.append("Soggetto_");
  42.         bf.append(tipoSoggetto);
  43.         bf.append("/");
  44.         bf.append(nomeSoggetto);
  45.         return bf.toString();
  46.     }
  47.    
  48.     @Override
  49.     public String key() throws ProtocolException {
  50.         return ArchiveSoggetto.buildKey(this.idSoggetto.getTipo(), this.idSoggetto.getNome());
  51.     }
  52.    
  53.    
  54.    
  55.     private IDSoggetto idSoggetto;
  56.     private org.openspcoop2.core.registry.Soggetto soggettoRegistro;
  57.     private org.openspcoop2.core.config.Soggetto soggettoConfigurazione;
  58.    
  59.     private ArchiveIdCorrelazione idCorrelazione; // permette di correlare più oggetti tra di loro
  60.    
  61.     public ArchiveSoggetto(org.openspcoop2.core.registry.Soggetto soggettoRegistro, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  62.        
  63.         if(soggettoRegistro==null){
  64.             throw new ProtocolException("SoggettoRegistro non fornito");
  65.         }
  66.         if(soggettoRegistro.getNome()==null){
  67.             throw new ProtocolException("SoggettoRegistro.nome non definito");
  68.         }
  69.         if(soggettoRegistro.getTipo()==null){
  70.             throw new ProtocolException("SoggettoRegistro.tipo non definito");
  71.         }
  72.         this.soggettoRegistro = soggettoRegistro;
  73.    
  74.         this.idSoggetto = new IDSoggetto(soggettoRegistro.getTipo(), soggettoRegistro.getNome());
  75.        
  76.         this.idCorrelazione = idCorrelazione;
  77.        
  78.     }
  79.     public ArchiveSoggetto(org.openspcoop2.core.config.Soggetto soggettoConfigurazione, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  80.        
  81.         if(soggettoConfigurazione==null){
  82.             throw new ProtocolException("SoggettoConfigurazione non fornito");
  83.         }
  84.         if(soggettoConfigurazione.getNome()==null){
  85.             throw new ProtocolException("SoggettoConfigurazione.nome non definito");
  86.         }
  87.         if(soggettoConfigurazione.getTipo()==null){
  88.             throw new ProtocolException("SoggettoConfigurazione.tipo non definito");
  89.         }
  90.         this.soggettoConfigurazione = soggettoConfigurazione;
  91.        
  92.         this.idSoggetto = new IDSoggetto(soggettoConfigurazione.getTipo(), soggettoConfigurazione.getNome());
  93.        
  94.         this.idCorrelazione = idCorrelazione;
  95.        
  96.     }
  97.     public ArchiveSoggetto(org.openspcoop2.core.config.Soggetto soggettoConfigurazione,
  98.             org.openspcoop2.core.registry.Soggetto soggettoRegistro, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  99.        
  100.         if(soggettoRegistro==null){
  101.             throw new ProtocolException("SoggettoRegistro non fornito");
  102.         }
  103.         if(soggettoRegistro.getNome()==null){
  104.             throw new ProtocolException("SoggettoRegistro.nome non definito");
  105.         }
  106.         if(soggettoRegistro.getTipo()==null){
  107.             throw new ProtocolException("SoggettoRegistro.tipo non definito");
  108.         }
  109.         this.soggettoRegistro = soggettoRegistro;
  110.    
  111.         if(soggettoConfigurazione==null){
  112.             throw new ProtocolException("SoggettoConfigurazione non fornito");
  113.         }
  114.         if(soggettoConfigurazione.getNome()==null){
  115.             throw new ProtocolException("SoggettoConfigurazione.nome non definito");
  116.         }
  117.         if(soggettoRegistro.getNome().equals(soggettoConfigurazione.getNome())==false){
  118.             throw new ProtocolException("SoggettoRegistro.nome e SoggettoConfigurazione.nome devono coincidere");
  119.         }
  120.         if(soggettoConfigurazione.getTipo()==null){
  121.             throw new ProtocolException("SoggettoConfigurazione.tipo non definito");
  122.         }
  123.         if(soggettoRegistro.getTipo().equals(soggettoConfigurazione.getTipo())==false){
  124.             throw new ProtocolException("SoggettoRegistro.tipo e SoggettoConfigurazione.tipo devono coincidere");
  125.         }
  126.         this.soggettoConfigurazione = soggettoConfigurazione;
  127.        
  128.         this.idSoggetto = new IDSoggetto(soggettoRegistro.getTipo(), soggettoRegistro.getNome());
  129.        
  130.         this.idCorrelazione = idCorrelazione;
  131.        
  132.     }
  133.    
  134.    
  135.     public IDSoggetto getIdSoggetto() {
  136.         return this.idSoggetto;
  137.     }
  138.     public org.openspcoop2.core.registry.Soggetto getSoggettoRegistro() {
  139.         return this.soggettoRegistro;
  140.     }
  141.     public org.openspcoop2.core.config.Soggetto getSoggettoConfigurazione() {
  142.         return this.soggettoConfigurazione;
  143.     }
  144.    
  145.     public ArchiveIdCorrelazione getIdCorrelazione() {
  146.         return this.idCorrelazione;
  147.     }
  148. }