FiltroDuplicati.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.engine.driver;

  21. import org.openspcoop2.protocol.sdk.Busta;
  22. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  23. import org.openspcoop2.protocol.sdk.ProtocolException;

  24. /**
  25.  * Classe per la gestione dei filtro duplicati
  26.  *
  27.  * @author Andrea Poli (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */

  31. public class FiltroDuplicati implements IFiltroDuplicati {

  32.     private History historyBuste;
  33.     private RepositoryBuste repositoryBuste;
  34.     private boolean gestioneStateless;
  35.     private long repositoryIntervalloScadenzaMessaggi;
  36.    
  37.     @Override
  38.     public void init(Object context) throws ProtocolException{
  39.     }
  40.    

  41.     @Override
  42.     public boolean releaseRuntimeResourceBeforeCheck() {
  43.         return false;
  44.     }
  45.    
  46.     @Override
  47.     public boolean isDuplicata(IProtocolFactory<?> protocolFactory, String id) throws ProtocolException{
  48.         return this.historyBuste.bustaRicevutaPrecedentemente(id);
  49.     }
  50.    
  51.     @Override
  52.     public void incrementaNumeroDuplicati(IProtocolFactory<?> protocolFactory, String id) throws ProtocolException{
  53.         this.repositoryBuste.aggiornaDuplicatiIntoInBox(id);
  54.     }
  55.    
  56.     @Override
  57.     public void registraBusta(IProtocolFactory<?> protocolFactory, Busta busta) throws ProtocolException{
  58.         if( this.gestioneStateless ){
  59.             // La busta puo' non esistere
  60.             if(this.repositoryBuste.isRegistrataIntoInBox(busta.getID())==false){
  61.                 this.repositoryBuste.registraBustaIntoInboxForHistory(busta, this.repositoryIntervalloScadenzaMessaggi);
  62.             }
  63.         }
  64.         else{
  65.             // se siamo in stateless l'history e' gia stato registrato sopra
  66.             this.historyBuste.registraBustaRicevuta(busta.getID());
  67.         }
  68.     }

  69.     public void setHistoryBuste(History historyBuste) {
  70.         this.historyBuste = historyBuste;
  71.     }

  72.     public void setRepositoryBuste(RepositoryBuste repository) {
  73.         this.repositoryBuste = repository;
  74.     }

  75.     public void setGestioneStateless(boolean stateless) {
  76.         this.gestioneStateless = stateless;
  77.     }

  78.     public void setRepositoryIntervalloScadenzaMessaggi(
  79.             long repositoryIntervalloScadenzaMessaggi) {
  80.         this.repositoryIntervalloScadenzaMessaggi = repositoryIntervalloScadenzaMessaggi;
  81.     }
  82.    
  83. }