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. /**
  33.  * ProtocolPropertiesUtils
  34.  *
  35.  * @author Poli Andrea (apoli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class ProtocolUtils {

  40.     // UTILITIES

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