ArchiveAccordoServizioParteComune.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.IDAccordo;
  22. import org.openspcoop2.core.id.IDSoggetto;
  23. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  24. import org.openspcoop2.core.registry.IdSoggetto;
  25. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  26. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  35.     public static String buildKey(String tipoSoggetto,String nomeSoggetto,String nomeAccordo,Integer versione) 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(nomeAccordo==null){
  44.             throw new ProtocolException("nomeAccordo non fornito");
  45.         }
  46.         if(versione==null){
  47.             throw new ProtocolException("versione non fornita");
  48.         }
  49.        
  50.         StringBuilder bf = new StringBuilder();
  51.         bf.append("AccordoServizioParteComune_");
  52.         bf.append(tipoSoggetto);
  53.         bf.append("/");
  54.         bf.append(nomeSoggetto);
  55.         bf.append("_");
  56.         bf.append(nomeAccordo);
  57.         bf.append("_");
  58.         bf.append(versione);
  59.         return bf.toString();
  60.     }
  61.    
  62.     @Override
  63.     public String key() throws ProtocolException {
  64.         String tipoSoggetto = "-";
  65.         String nomeSoggetto = "-";
  66.         String nomeAccordo = this.accordoServizioParteComune.getNome();
  67.         Integer versione = null;
  68.         if(this.accordoServizioParteComune.getSoggettoReferente()!=null){
  69.             if(this.accordoServizioParteComune.getSoggettoReferente().getTipo()!=null){
  70.                 tipoSoggetto = this.accordoServizioParteComune.getSoggettoReferente().getTipo();
  71.             }
  72.             if(this.accordoServizioParteComune.getSoggettoReferente().getNome()!=null){
  73.                 nomeSoggetto = this.accordoServizioParteComune.getSoggettoReferente().getNome();
  74.             }
  75.         }
  76.         if(this.accordoServizioParteComune.getVersione()!=null){
  77.             versione = this.accordoServizioParteComune.getVersione();
  78.         }
  79.         return ArchiveAccordoServizioParteComune.buildKey(tipoSoggetto, nomeSoggetto,
  80.                 nomeAccordo,versione);
  81.     }
  82.    
  83.    
  84.    
  85.     protected IDSoggetto idSoggettoReferente;
  86.     protected IDAccordo idAccordoServizioParteComune;
  87.     protected AccordoServizioParteComune accordoServizioParteComune;
  88.    
  89.     private ArchiveIdCorrelazione idCorrelazione; // permette di correlare più oggetti tra di loro
  90.        
  91.    
  92.    
  93.     public ArchiveAccordoServizioParteComune(IDSoggetto idSoggettoProprietario, AccordoServizioParteComune accordoServizioParteComune, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  94.         this(injectProprietario(idSoggettoProprietario, accordoServizioParteComune),idCorrelazione, false);
  95.     }
  96.     public ArchiveAccordoServizioParteComune(IDSoggetto idSoggettoProprietario, AccordoServizioParteComune accordoServizioParteComune, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  97.         this(injectProprietario(idSoggettoProprietario, accordoServizioParteComune),idCorrelazione, informationMissingManagementEnabled);
  98.     }
  99.     public ArchiveAccordoServizioParteComune(AccordoServizioParteComune accordoServizioParteComune, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  100.         this(accordoServizioParteComune,idCorrelazione,false);
  101.     }  
  102.     public ArchiveAccordoServizioParteComune(AccordoServizioParteComune accordoServizioParteComune, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  103.         this.update(accordoServizioParteComune, informationMissingManagementEnabled);
  104.         this.idCorrelazione = idCorrelazione;
  105.     }
  106.     private static AccordoServizioParteComune injectProprietario(IDSoggetto idSoggettoProprietario, AccordoServizioParteComune accordoServizioParteComune) throws ProtocolException{
  107.         if(accordoServizioParteComune==null){
  108.             throw new ProtocolException("AccordoServizioParteComune non fornito");
  109.         }
  110.         if(idSoggettoProprietario==null){
  111.             throw new ProtocolException("idSoggettoProprietario non fornito");
  112.         }
  113.         if(idSoggettoProprietario.getTipo()==null){
  114.             throw new ProtocolException("idSoggettoProprietario.tipo non definito");
  115.         }
  116.         if(idSoggettoProprietario.getNome()==null){
  117.             throw new ProtocolException("idSoggettoProprietario.nome non definito");
  118.         }
  119.         IdSoggetto soggettoReferente = new IdSoggetto();
  120.         soggettoReferente.setTipo(idSoggettoProprietario.getTipo());
  121.         soggettoReferente.setNome(idSoggettoProprietario.getNome());
  122.         accordoServizioParteComune.setSoggettoReferente(soggettoReferente);
  123.         return accordoServizioParteComune;
  124.     }
  125.    
  126.    
  127.    
  128.     public void update() throws ProtocolException{
  129.         this.update(this.accordoServizioParteComune, false);
  130.     }
  131.     public void update(AccordoServizioParteComune accordoServizioParteComune) throws ProtocolException{
  132.         this.update(accordoServizioParteComune, false);
  133.     }
  134.     public void update(AccordoServizioParteComune accordoServizioParteComune, boolean informationMissingManagementEnabled) throws ProtocolException{
  135.        
  136.         if(accordoServizioParteComune==null){
  137.             throw new ProtocolException("AccordoServizioParteComune non fornito");
  138.         }
  139.         if(accordoServizioParteComune.getNome()==null){
  140.             throw new ProtocolException("AccordoServizioParteComune.nome non definito");
  141.         }
  142.         this.accordoServizioParteComune = accordoServizioParteComune;
  143.        
  144.         if(informationMissingManagementEnabled==false){
  145.             if(accordoServizioParteComune.getVersione()==null){
  146.                 throw new ProtocolException("AccordoServizioParteComune.versione non definito");
  147.             }
  148.             if(accordoServizioParteComune.getSoggettoReferente()==null){
  149.                 throw new ProtocolException("AccordoServizioParteComune.soggettoReferente non definito");
  150.             }
  151.             if(accordoServizioParteComune.getSoggettoReferente().getTipo()==null){
  152.                 throw new ProtocolException("AccordoServizioParteComune.soggettoReferente.tipo non definito");
  153.             }
  154.             if(accordoServizioParteComune.getSoggettoReferente().getNome()==null){
  155.                 throw new ProtocolException("AccordoServizioParteComune.soggettoReferente.nome non definito");
  156.             }
  157.            
  158.             this.idSoggettoReferente =
  159.                     new IDSoggetto(accordoServizioParteComune.getSoggettoReferente().getTipo(),
  160.                             accordoServizioParteComune.getSoggettoReferente().getNome());
  161.            
  162.             try{
  163.                 this.idAccordoServizioParteComune = IDAccordoFactory.getInstance().getIDAccordoFromAccordo(accordoServizioParteComune);
  164.             }catch(Exception e){
  165.                 throw new ProtocolException(e.getMessage(),e);
  166.             }
  167.         }
  168.     }
  169.    
  170.    
  171.     public IDSoggetto getIdSoggettoReferente() {
  172.         return this.idSoggettoReferente;
  173.     }
  174.     public IDAccordo getIdAccordoServizioParteComune() {
  175.         return this.idAccordoServizioParteComune;
  176.     }
  177.     public AccordoServizioParteComune getAccordoServizioParteComune() {
  178.         return this.accordoServizioParteComune;
  179.     }
  180.    
  181.     public ArchiveIdCorrelazione getIdCorrelazione() {
  182.         return this.idCorrelazione;
  183.     }
  184. }