ProtocolUtils.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.utils;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.constants.CostantiLabel;
  24. import org.openspcoop2.core.registry.driver.FiltroRicercaProtocolPropertyRegistry;
  25. import org.openspcoop2.protocol.sdk.properties.AbstractProperty;
  26. import org.openspcoop2.protocol.sdk.properties.BooleanProperty;
  27. import org.openspcoop2.protocol.sdk.properties.NumberProperty;
  28. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  29. import org.openspcoop2.protocol.sdk.properties.StringProperty;
  30. import org.openspcoop2.utils.Map;
  31. import org.openspcoop2.utils.MapKey;
  32. import org.openspcoop2.utils.UtilsRuntimeException;

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

  41.     // UTILITIES

  42.     public static MapKey<String> protocolToMapKey(String protocollo){
  43.         if(CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo)) {
  44.             return CostantiLabel.TRASPARENTE_PROTOCOL_MAP_KEY;
  45.         }
  46.         else if(CostantiLabel.MODIPA_PROTOCOL_NAME.equals(protocollo)) {
  47.             return CostantiLabel.MODIPA_PROTOCOL_MAP_KEY;
  48.         }
  49.         else if(CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo)) {
  50.             return CostantiLabel.SPCOOP_PROTOCOL_MAP_KEY;
  51.         }
  52.         else if(CostantiLabel.AS4_PROTOCOL_NAME.equals(protocollo)) {
  53.             return CostantiLabel.AS4_PROTOCOL_MAP_KEY;
  54.         }
  55.         else if(CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo)) {
  56.             return CostantiLabel.SDI_PROTOCOL_MAP_KEY;
  57.         }
  58.         else if(CostantiLabel.NO_PROTOCOL_NAME.equals(protocollo)) {
  59.             return CostantiLabel.NO_PROTOCOL_MAP_KEY;
  60.         }
  61.         else {
  62.             return Map.newMapKey(protocollo);
  63.         }
  64.     }
  65.    
  66.     public static List<String> orderProtocolli(List<String> protocolliDispondibili){
  67.         List<String> l = new ArrayList<>();
  68.        
  69.         List<String> newL = new ArrayList<>();
  70.         for (String protocollo : protocolliDispondibili) {
  71.             newL.add(protocollo);
  72.         }
  73.        
  74.         // trasparente
  75.         for (int i = 0; i < newL.size(); i++) {
  76.             String protocollo = newL.get(i);
  77.             if(CostantiLabel.TRASPARENTE_PROTOCOL_NAME.equals(protocollo)) {
  78.                 l.add(newL.remove(i));
  79.                 break;
  80.             }
  81.         }
  82.        
  83.         // modipa
  84.         for (int i = 0; i < newL.size(); i++) {
  85.             String protocollo = newL.get(i);
  86.             if(CostantiLabel.MODIPA_PROTOCOL_NAME.equals(protocollo)) {
  87.                 l.add(newL.remove(i));
  88.                 break;
  89.             }
  90.         }
  91.        
  92.         // spcoop
  93.         for (int i = 0; i < newL.size(); i++) {
  94.             String protocollo = newL.get(i);
  95.             if(CostantiLabel.SPCOOP_PROTOCOL_NAME.equals(protocollo)) {
  96.                 l.add(newL.remove(i));
  97.                 break;
  98.             }
  99.         }
  100.        
  101.         // edelivery
  102.         for (int i = 0; i < newL.size(); i++) {
  103.             String protocollo = newL.get(i);
  104.             if(CostantiLabel.AS4_PROTOCOL_NAME.equals(protocollo)) {
  105.                 l.add(newL.remove(i));
  106.                 break;
  107.             }
  108.         }
  109.        
  110.         // fatturazione
  111.         for (int i = 0; i < newL.size(); i++) {
  112.             String protocollo = newL.get(i);
  113.             if(CostantiLabel.SDI_PROTOCOL_NAME.equals(protocollo)) {
  114.                 l.add(newL.remove(i));
  115.                 break;
  116.             }
  117.         }
  118.        
  119.         // altri
  120.         for (int i = 0; i < newL.size(); i++) {
  121.             String protocollo = newL.get(i);
  122.             l.add(protocollo);
  123.         }
  124.        
  125.         return l;
  126.     }
  127.    
  128.     public static List<FiltroRicercaProtocolPropertyRegistry> convert(ProtocolProperties protocolProperties){
  129.         List<FiltroRicercaProtocolPropertyRegistry> list = null;
  130.         if(protocolProperties!=null && protocolProperties.sizeProperties()>0){
  131.             list = new ArrayList<>();
  132.             for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  133.                 FiltroRicercaProtocolPropertyRegistry fpp = new FiltroRicercaProtocolPropertyRegistry();
  134.                 AbstractProperty<?> p = protocolProperties.getProperty(i);
  135.                 fpp.setName(p.getId());
  136.                 if(p instanceof StringProperty){
  137.                     StringProperty sp = (StringProperty) p;
  138.                     if(sp.getValue()!=null && !"".equals(sp.getValue())) {
  139.                         fpp.setValueAsString(sp.getValue());
  140.                         fpp.setSearchWithLike(sp.getSearchWithLike());
  141.                     }
  142.                 }
  143.                 else if(p instanceof NumberProperty){
  144.                     NumberProperty np = (NumberProperty) p;
  145.                     fpp.setValueAsLong(np.getValue());
  146.                 }
  147.                 else if(p instanceof BooleanProperty){
  148.                     BooleanProperty bp = (BooleanProperty) p;
  149.                     fpp.setValueAsBoolean(bp.getValue());
  150.                 }
  151.                 else{
  152.                     throw new UtilsRuntimeException("Tipo di Filtro ["+p.getClass().getName()+"] non supportato");
  153.                 }
  154.                 list.add(fpp);
  155.             }
  156.         }
  157.         return list;
  158.     }
  159.    
  160. }