RemoteStoreConfigMultiTenantUtils.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.certificate.remote;

  21. import java.util.HashMap;
  22. import java.util.Map;

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


  33.     protected static String getMultitenant(Map<String, String> thisParam, String tenant,
  34.             String cloned){
  35.         if(thisParam!=null && !thisParam.isEmpty()) {
  36.             String newValue = thisParam.get(tenant);
  37.             if(newValue!=null) {
  38.                 return newValue;
  39.             }
  40.         }
  41.         return cloned;
  42.     }
  43.     protected static Map<String, String> getMultitenant(Map<String, Map<String, String>> thisParam, String tenant,
  44.             Map<String, String> cloned){
  45.         if(thisParam!=null && !thisParam.isEmpty()) {
  46.             Map<String, String> thisMap = thisParam.get(tenant);
  47.             return getMultitenant(thisMap, cloned);
  48.         }
  49.         return cloned;
  50.     }
  51.     private static Map<String, String> getMultitenant(Map<String, String> thisParam, Map<String, String> cloned){
  52.         if(thisParam!=null && !thisParam.isEmpty()) {
  53.             for (Map.Entry<String,String> entry : thisParam.entrySet()) {
  54.                 if(entry.getKey()!=null && entry.getValue()!=null) {
  55.                     if(cloned==null) {
  56.                         cloned=new HashMap<>();
  57.                     }
  58.                     cloned.put(entry.getKey(), entry.getValue());
  59.                 }
  60.             }
  61.         }
  62.         return cloned;
  63.     }
  64.    
  65.     protected static Map<String, String> newMapInstance(Map<String, String> thisParam){
  66.         HashMap<String, String> cloned = null;
  67.         if(thisParam!=null) {
  68.             cloned = new HashMap<>();
  69.             if(!thisParam.isEmpty()) {
  70.                 for (Map.Entry<String,String> entry : thisParam.entrySet()) {
  71.                     if(entry.getKey()!=null && entry.getValue()!=null) {
  72.                         cloned.put(entry.getKey()+"", entry.getValue()+"");
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.         return cloned;
  78.     }
  79.     protected static Map<String, Map<String, String>> newMultiMapInstance(Map<String, Map<String, String>> thisParam){
  80.         Map<String, Map<String, String>> cloned = null;
  81.         if(thisParam!=null) {
  82.             cloned = new HashMap<>();
  83.             setMultiMapInstanceEngine(thisParam, cloned);
  84.         }
  85.         return cloned;
  86.     }
  87.     private static void setMultiMapInstanceEngine(Map<String, Map<String, String>> thisParam, Map<String, Map<String, String>> cloned){
  88.         if(!thisParam.isEmpty()) {
  89.             for (Map.Entry<String,Map<String, String>> entry : thisParam.entrySet()) {
  90.                 if(entry.getKey()!=null && entry.getValue()!=null) {
  91.                     Map<String, String> mValue = newMapInstance(entry.getValue());
  92.                     if(mValue!=null) {
  93.                         cloned.put(entry.getKey()+"", mValue);
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.     }
  99.    
  100. }