ProfiloUtils.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.utils.service.beans.utils;

  21. import java.util.EnumMap;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. import java.util.Map;

  25. import org.openspcoop2.utils.service.beans.ProfiloEnum;

  26. /**
  27.  * ProfiloUtils
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class ProfiloUtils {
  34.    
  35.     private ProfiloUtils() {}

  36.     private static final Map<ProfiloEnum,String> MAP_PROFILO_TO_PROTOCOLLO = new EnumMap<>(ProfiloEnum.class);
  37.     static {
  38.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.APIGATEWAY, "trasparente");
  39.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.MODIPA, "modipa"); // si lascia per retrocompatibilità ma si vuole utilizzare ModI
  40.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.MODI, "modipa");
  41.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.SPCOOP, "spcoop");
  42.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.FATTURAPA, "sdi");
  43.         MAP_PROFILO_TO_PROTOCOLLO.put(ProfiloEnum.EDELIVERY, "as4");
  44.     }
  45.     public static Map<ProfiloEnum, String> getMapProfiloToProtocollo() {
  46.         return MAP_PROFILO_TO_PROTOCOLLO;
  47.     }
  48.    
  49.     private static Map<String, ProfiloEnum> mapProtocolloToProfilo = null;
  50.     public static Map<String, ProfiloEnum> getMapProtocolloToProfilo() {
  51.         if(mapProtocolloToProfilo==null) {
  52.             initMapProtocolloToProfilo();
  53.         }
  54.         return mapProtocolloToProfilo;
  55.     }
  56.     private static synchronized void initMapProtocolloToProfilo() {
  57.         if(mapProtocolloToProfilo==null) {
  58.             mapProtocolloToProfilo = new HashMap<>();
  59.             Iterator<ProfiloEnum> it = MAP_PROFILO_TO_PROTOCOLLO.keySet().iterator();
  60.             while (it.hasNext()) {
  61.                 ProfiloEnum profiloEnum = it.next();
  62.                 if(ProfiloEnum.MODIPA.equals(profiloEnum)) {
  63.                     continue; // utilizzo MODI
  64.                 }
  65.                 String protocollo = MAP_PROFILO_TO_PROTOCOLLO.get(profiloEnum);
  66.                 mapProtocolloToProfilo.put(protocollo, profiloEnum);
  67.             }
  68.         }
  69.     }
  70.    
  71.     public static String toProtocollo(ProfiloEnum profiloEnum) {
  72.         return getMapProfiloToProtocollo().get(profiloEnum);
  73.     }
  74.     public static ProfiloEnum toProfilo(String protocollo) {
  75.         ProfiloEnum out = getMapProtocolloToProfilo().get(protocollo);
  76.         return ProfiloEnum.MODIPA.equals(out) ? ProfiloEnum.MODI : out;
  77.     }
  78.    
  79. }