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.HashMap;
  22. import java.util.Iterator;
  23. import java.util.Map;

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

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

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