ProtocolPropertiesUtilities.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.core.registry.driver;

  21. import java.util.List;

  22. import org.openspcoop2.core.registry.AccordoCooperazione;
  23. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  24. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  25. import org.openspcoop2.core.registry.Azione;
  26. import org.openspcoop2.core.registry.Fruitore;
  27. import org.openspcoop2.core.registry.Operation;
  28. import org.openspcoop2.core.registry.PortType;
  29. import org.openspcoop2.core.registry.ProtocolProperty;
  30. import org.openspcoop2.core.registry.Resource;
  31. import org.openspcoop2.core.registry.Soggetto;

  32. /**
  33.  * ProtocolPropertiesUtilities
  34.  *
  35.  * @author Poli Andrea (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class ProtocolPropertiesUtilities {

  40.     public static boolean isMatch(Soggetto soggetto,List<FiltroRicercaProtocolPropertyRegistry> list){
  41.         return isMatch(soggetto.getProtocolPropertyList(), list);
  42.     }
  43.     public static boolean isMatch(AccordoCooperazione accordo,List<FiltroRicercaProtocolPropertyRegistry> list){
  44.         return isMatch(accordo.getProtocolPropertyList(), list);
  45.     }
  46.     public static boolean isMatch(AccordoServizioParteComune accordo,List<FiltroRicercaProtocolPropertyRegistry> list){
  47.         return isMatch(accordo.getProtocolPropertyList(), list);
  48.     }
  49.     public static boolean isMatch(PortType pt,List<FiltroRicercaProtocolPropertyRegistry> list){
  50.         return isMatch(pt.getProtocolPropertyList(), list);
  51.     }
  52.     public static boolean isMatch(Operation op,List<FiltroRicercaProtocolPropertyRegistry> list){
  53.         return isMatch(op.getProtocolPropertyList(), list);
  54.     }
  55.     public static boolean isMatch(Azione az,List<FiltroRicercaProtocolPropertyRegistry> list){
  56.         return isMatch(az.getProtocolPropertyList(), list);
  57.     }
  58.     public static boolean isMatch(Resource resource,List<FiltroRicercaProtocolPropertyRegistry> list){
  59.         return isMatch(resource.getProtocolPropertyList(), list);
  60.     }
  61.     public static boolean isMatch(AccordoServizioParteSpecifica accordo,List<FiltroRicercaProtocolPropertyRegistry> list){
  62.         return isMatch(accordo.getProtocolPropertyList(), list);
  63.     }
  64.     public static boolean isMatch(Fruitore fruitore,List<FiltroRicercaProtocolPropertyRegistry> list){
  65.         return isMatch(fruitore.getProtocolPropertyList(), list);
  66.     }
  67.     public static boolean isMatch(List<ProtocolProperty> protocolProperties ,List<FiltroRicercaProtocolPropertyRegistry> list){
  68.         if(list==null || list.isEmpty()){
  69.             return true;
  70.         }
  71.         for (int i = 0; i < list.size(); i++) {
  72.             FiltroRicercaProtocolPropertyRegistry filtro = list.get(i);
  73.            
  74.             if(filtro.getName()!=null){
  75.                 boolean found = false;
  76.                 for (ProtocolProperty pp : protocolProperties) {
  77.                     if(filtro.getName().equals(pp.getName())){
  78.                        
  79.                         // check altri valori
  80.                         if(filtro.getValueAsString()!=null){
  81.                             if(!filtro.getValueAsString().equals(pp.getValue())){
  82.                                 continue;
  83.                             }
  84.                         }
  85.                         else if(filtro.getValueAsLong()!=null){
  86.                             if(pp.getNumberValue()==null){
  87.                                 continue;
  88.                             }
  89.                             if(filtro.getValueAsLong().longValue() != pp.getNumberValue().longValue()){
  90.                                 continue;
  91.                             }
  92.                         }
  93.                         else if(filtro.getValueAsBoolean()!=null){
  94.                             if(pp.getBooleanValue()==null){
  95.                                 continue;
  96.                             }
  97.                             if(filtro.getValueAsBoolean().booleanValue() != pp.getBooleanValue().booleanValue()){
  98.                                 continue;
  99.                             }
  100.                         }
  101.                        
  102.                         found = true;
  103.                         break;
  104.                     }
  105.                 }
  106.                 if(!found){
  107.                     return false;
  108.                 }
  109.             }
  110.             else{
  111.                
  112.                 if(filtro.getValueAsString()!=null){
  113.                     boolean found = false;
  114.                     for (ProtocolProperty pp : protocolProperties) {
  115.                         if(filtro.getValueAsString().equals(pp.getValue())){
  116.                             found = true;
  117.                             break;
  118.                         }
  119.                     }
  120.                     if(!found){
  121.                         return false;
  122.                     }
  123.                 }
  124.                 else if(filtro.getValueAsLong()!=null){
  125.                     boolean found = false;
  126.                     for (ProtocolProperty pp : protocolProperties) {
  127.                         if(pp.getNumberValue()==null){
  128.                             continue;
  129.                         }
  130.                         if(filtro.getValueAsLong().longValue() == pp.getNumberValue().longValue()){
  131.                             found = true;
  132.                             break;
  133.                         }
  134.                     }
  135.                     if(!found){
  136.                         return false;
  137.                     }
  138.                 }
  139.                 else if(filtro.getValueAsBoolean()!=null){
  140.                     boolean found = false;
  141.                     for (ProtocolProperty pp : protocolProperties) {
  142.                         if(pp.getBooleanValue()==null){
  143.                             continue;
  144.                         }
  145.                         if(filtro.getValueAsBoolean().booleanValue() == pp.getBooleanValue().booleanValue()){
  146.                             found = true;
  147.                             break;
  148.                         }
  149.                     }
  150.                     if(!found){
  151.                         return false;
  152.                     }
  153.                 }
  154.                
  155.             }
  156.            
  157.         }
  158.        
  159.         return true;
  160.     }

  161.    
  162. }