ArchiveAccordoCooperazione.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 java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.id.IDAccordoCooperazione;
  24. import org.openspcoop2.core.id.IDSoggetto;
  25. import org.openspcoop2.core.registry.AccordoCooperazione;
  26. import org.openspcoop2.core.registry.IdSoggetto;
  27. import org.openspcoop2.core.registry.driver.IDAccordoCooperazioneFactory;
  28. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  37.     public static String buildKey(String tipoSoggetto,String nomeSoggetto,String nomeAccordo,Integer versione) throws ProtocolException{
  38.        
  39.         if(tipoSoggetto==null){
  40.             throw new ProtocolException("tipoSoggetto non fornito");
  41.         }
  42.         if(nomeSoggetto==null){
  43.             throw new ProtocolException("nomeSoggetto non fornito");
  44.         }
  45.         if(nomeAccordo==null){
  46.             throw new ProtocolException("nomeAccordo non fornito");
  47.         }
  48.         if(versione==null){
  49.             throw new ProtocolException("versione non fornita");
  50.         }
  51.        
  52.         StringBuilder bf = new StringBuilder();
  53.         bf.append("AccordoCooperazione_");
  54.         bf.append(tipoSoggetto);
  55.         bf.append("/");
  56.         bf.append(nomeSoggetto);
  57.         bf.append("_");
  58.         bf.append(nomeAccordo);
  59.         bf.append("_");
  60.         bf.append(versione);
  61.         return bf.toString();
  62.     }
  63.    
  64.     @Override
  65.     public String key() throws ProtocolException {
  66.         String tipoSoggetto = "-";
  67.         String nomeSoggetto = "-";
  68.         String nomeAccordo = this.accordoCooperazione.getNome();
  69.         Integer versione = null;
  70.         if(this.accordoCooperazione.getSoggettoReferente()!=null){
  71.             if(this.accordoCooperazione.getSoggettoReferente().getTipo()!=null){
  72.                 tipoSoggetto = this.accordoCooperazione.getSoggettoReferente().getTipo();
  73.             }
  74.             if(this.accordoCooperazione.getSoggettoReferente().getNome()!=null){
  75.                 nomeSoggetto = this.accordoCooperazione.getSoggettoReferente().getNome();
  76.             }
  77.         }
  78.         if(this.accordoCooperazione.getVersione()!=null){
  79.             versione = this.accordoCooperazione.getVersione();
  80.         }
  81.         return ArchiveAccordoCooperazione.buildKey(tipoSoggetto, nomeSoggetto,
  82.                 nomeAccordo,versione);
  83.     }
  84.    
  85.    
  86.     private IDSoggetto idSoggettoReferente;
  87.     private IDAccordoCooperazione idAccordoCooperazione;
  88.     private List<IDSoggetto> idSoggettiPartecipanti = new ArrayList<IDSoggetto>();
  89.     private AccordoCooperazione accordoCooperazione;
  90.    
  91.     private ArchiveIdCorrelazione idCorrelazione; // permette di correlare più oggetti tra di loro
  92.    
  93.    
  94.     public ArchiveAccordoCooperazione(IDSoggetto idSoggettoProprietario, AccordoCooperazione accordoCooperazione, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  95.         this(injectProprietario(idSoggettoProprietario, accordoCooperazione), idCorrelazione, false);
  96.     }
  97.     public ArchiveAccordoCooperazione(IDSoggetto idSoggettoProprietario, AccordoCooperazione accordoCooperazione, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  98.         this(injectProprietario(idSoggettoProprietario, accordoCooperazione), idCorrelazione, informationMissingManagementEnabled);
  99.     }
  100.     public ArchiveAccordoCooperazione(AccordoCooperazione accordoCooperazione, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  101.         this(accordoCooperazione,idCorrelazione,false);
  102.     }  
  103.     public ArchiveAccordoCooperazione(AccordoCooperazione accordoCooperazione, ArchiveIdCorrelazione idCorrelazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  104.         this.update(accordoCooperazione, informationMissingManagementEnabled);
  105.         this.idCorrelazione = idCorrelazione;
  106.     }
  107.     private static AccordoCooperazione injectProprietario(IDSoggetto idSoggettoProprietario, AccordoCooperazione accordoCooperazione) throws ProtocolException{
  108.         if(accordoCooperazione==null){
  109.             throw new ProtocolException("AccordoCooperazione non fornito");
  110.         }
  111.         if(idSoggettoProprietario==null){
  112.             throw new ProtocolException("idSoggettoProprietario non fornito");
  113.         }
  114.         if(idSoggettoProprietario.getTipo()==null){
  115.             throw new ProtocolException("idSoggettoProprietario.tipo non definito");
  116.         }
  117.         if(idSoggettoProprietario.getNome()==null){
  118.             throw new ProtocolException("idSoggettoProprietario.nome non definito");
  119.         }
  120.         IdSoggetto soggettoReferente = new IdSoggetto();
  121.         soggettoReferente.setTipo(idSoggettoProprietario.getTipo());
  122.         soggettoReferente.setNome(idSoggettoProprietario.getNome());
  123.         accordoCooperazione.setSoggettoReferente(soggettoReferente);
  124.         return accordoCooperazione;
  125.     }

  126.    
  127.    
  128.     public void update() throws ProtocolException{
  129.         this.update(this.accordoCooperazione, false);
  130.     }
  131.     public void update(AccordoCooperazione accordoCooperazione) throws ProtocolException{
  132.         this.update(accordoCooperazione, false);
  133.     }
  134.     public void update(AccordoCooperazione accordoCooperazione, boolean informationMissingManagementEnabled) throws ProtocolException{
  135.        
  136.         if(accordoCooperazione==null){
  137.             throw new ProtocolException("AccordoCooperazione non fornito");
  138.         }
  139.         if(accordoCooperazione.getNome()==null){
  140.             throw new ProtocolException("AccordoCooperazione.nome non definito");
  141.         }
  142.         this.accordoCooperazione = accordoCooperazione;
  143.        
  144.         if(informationMissingManagementEnabled==false){
  145.             if(accordoCooperazione.getVersione()==null){
  146.                 throw new ProtocolException("AccordoCooperazione.versione non definito");
  147.             }
  148.             if(accordoCooperazione.getSoggettoReferente()==null){
  149.                 throw new ProtocolException("AccordoCooperazione.soggettoReferente non definito");
  150.             }
  151.             if(accordoCooperazione.getSoggettoReferente().getTipo()==null){
  152.                 throw new ProtocolException("AccordoCooperazione.soggettoReferente.tipo non definito");
  153.             }
  154.             if(accordoCooperazione.getSoggettoReferente().getNome()==null){
  155.                 throw new ProtocolException("AccordoCooperazione.soggettoReferente.nome non definito");
  156.             }
  157.        
  158.             this.idSoggettoReferente =
  159.                     new IDSoggetto(accordoCooperazione.getSoggettoReferente().getTipo(),
  160.                             accordoCooperazione.getSoggettoReferente().getNome());
  161.            
  162.             try{
  163.                 this.idAccordoCooperazione = IDAccordoCooperazioneFactory.getInstance().getIDAccordoFromAccordo(accordoCooperazione);
  164.             }catch(Exception e){
  165.                 throw new ProtocolException(e.getMessage(),e);
  166.             }
  167.            
  168.             // Questo controllo non ci vuole. Altrimenti non e' possibile esportare un accordo che non possiede soggetti partecipanti
  169.             // Comunque il controllo viene effettuato quando si cerca di portare un accordo allo stato finale.
  170. //          if(accordoCooperazione.getElencoPartecipanti()==null){
  171. //              throw new ProtocolException("AccordoCooperazione.elencoPartecipanti non definito");
  172. //          }
  173.             if(accordoCooperazione.getElencoPartecipanti()!=null){
  174.                 for (int i = 0; i < accordoCooperazione.getElencoPartecipanti().sizeSoggettoPartecipanteList(); i++) {
  175.                     IdSoggetto partecipante = accordoCooperazione.getElencoPartecipanti().getSoggettoPartecipante(i);
  176.                     if(partecipante==null){
  177.                         throw new ProtocolException("AccordoCooperazione.elencoPartecipanti["+i+"] non definito");
  178.                     }
  179.                     if(partecipante.getTipo()==null){
  180.                         throw new ProtocolException("AccordoCooperazione.elencoPartecipanti["+i+"].tipo non definito");
  181.                     }
  182.                     if(partecipante.getNome()==null){
  183.                         throw new ProtocolException("AccordoCooperazione.elencoPartecipanti["+i+"].nome non definito");
  184.                     }
  185.                     IDSoggetto idSoggettoPartecipante = new IDSoggetto(partecipante.getTipo(), partecipante.getNome());
  186.                     this.idSoggettiPartecipanti.add(idSoggettoPartecipante);
  187.                 }
  188.             }
  189.         }
  190.     }
  191.    
  192.    
  193.     public IDSoggetto getIdSoggettoReferente() {
  194.         return this.idSoggettoReferente;
  195.     }
  196.     public IDAccordoCooperazione getIdAccordoCooperazione() {
  197.         return this.idAccordoCooperazione;
  198.     }
  199.     public List<IDSoggetto> getIdSoggettiPartecipanti() {
  200.         return this.idSoggettiPartecipanti;
  201.     }
  202.     public AccordoCooperazione getAccordoCooperazione() {
  203.         return this.accordoCooperazione;
  204.     }
  205.    
  206.     public ArchiveIdCorrelazione getIdCorrelazione() {
  207.         return this.idCorrelazione;
  208.     }

  209. }