ArchiveActivePolicy.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.controllo_traffico.constants.RuoloPolicy;
  22. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  31.     public static String buildKey(RuoloPolicy ruoloPorta, String nomePorta, String aliasPolicy) throws ProtocolException{
  32.        
  33.         if(aliasPolicy==null){
  34.             throw new ProtocolException("aliasPolicy non fornito");
  35.         }
  36.        
  37.         StringBuilder bf = new StringBuilder();
  38.         bf.append("ControlloTraffico_ActivePolicy_");
  39.         bf.append(aliasPolicy);
  40.         if(ruoloPorta!=null && nomePorta!=null) {
  41.             bf.append("#");
  42.             bf.append(ruoloPorta.toString());
  43.             bf.append("_");
  44.             bf.append(nomePorta);
  45.         }
  46.         return bf.toString();
  47.     }
  48.    
  49.     @Override
  50.     public String key() throws ProtocolException {
  51.         return ArchiveActivePolicy.buildKey(this.ruoloPorta, this.nomePorta, this.aliasPolicy);
  52.     }
  53.    
  54.     @Override
  55.     public int position() throws ProtocolException {
  56.         return this.posizione;
  57.     }
  58.    
  59.    
  60.     private RuoloPolicy ruoloPorta;
  61.     private String nomePorta;
  62.     private String aliasPolicy;
  63.     private org.openspcoop2.core.controllo_traffico.AttivazionePolicy policy;
  64.     private boolean policyGlobale;
  65.    
  66.     private int posizione;
  67.    
  68.     private ArchiveIdCorrelazione idCorrelazione; // permette di correlare più oggetti tra di loro

  69.     public ArchiveActivePolicy(org.openspcoop2.core.controllo_traffico.AttivazionePolicy policy, ArchiveIdCorrelazione idCorrelazione) throws ProtocolException{
  70.        
  71.         if(policy==null){
  72.             throw new ProtocolException("Policy non fornito");
  73.         }
  74.         if(policy.getAlias()==null){
  75.             throw new ProtocolException("Policy.alias non definito");
  76.         }
  77.         this.aliasPolicy = policy.getAlias();
  78.         if(policy!=null && policy.getFiltro()!=null) {
  79.             this.ruoloPorta = policy.getFiltro().getRuoloPorta();
  80.             this.nomePorta = policy.getFiltro().getNomePorta();
  81.         }
  82.         this.policy = policy;
  83.        
  84.         this.posizione = policy.getPosizione();
  85.        
  86.         this.policyGlobale = policy.getFiltro()==null || policy.getFiltro().getNomePorta()==null || "".equals(policy.getFiltro().getNomePorta());
  87.                
  88.         this.idCorrelazione = idCorrelazione;
  89.        
  90.     }
  91.    
  92.    
  93.     public String getAliasPolicy() {
  94.         return this.aliasPolicy;
  95.     }
  96.     public RuoloPolicy getRuoloPorta() {
  97.         return this.ruoloPorta;
  98.     }
  99.     public String getNomePorta() {
  100.         return this.nomePorta;
  101.     }
  102.     public org.openspcoop2.core.controllo_traffico.AttivazionePolicy getPolicy() {
  103.         return this.policy;
  104.     }
  105.    
  106.     public boolean isPolicyGlobale() {
  107.         return this.policyGlobale;
  108.     }
  109.    
  110.     public ArchiveIdCorrelazione getIdCorrelazione() {
  111.         return this.idCorrelazione;
  112.     }

  113. }