ModISignalHubParamConfig.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.modipa.config;

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

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.protocol.sdk.ProtocolException;

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

  34.     public static final String PROPERTY_NOME = "nome";
  35.     public static final String PROPERTY_LABEL = "label";
  36.     public static final String PROPERTY_REQUIRED = "required";
  37.     public static final String PROPERTY_STRING_TYPE = "stringType";
  38.     public static final String PROPERTY_REGEXP = "regexp";
  39.     public static final String PROPERTY_ENUM = "enum";
  40.     public static final String PROPERTY_MIN_LENGTH = "minLength";
  41.     public static final String PROPERTY_MAX_LENGTH = "maxLength";
  42.     public static final String PROPERTY_INFO = "info";
  43.     public static final String PROPERTY_DEFAULT_RULE = "rule";
  44.     public static final String PROPERTY_DEFAULT_RULE_INFO = "rule.info";
  45.    
  46.     private ModISignalHubParamConfig() {}
  47.     ModISignalHubParamConfig(String prefix, String propertyId, Properties p) throws ProtocolException {
  48.        
  49.         this.propertyId = propertyId;
  50.        
  51.         this.nome = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_NOME, true);
  52.         this.label = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_LABEL, true);
  53.         this.required = ModISignalHubConfig.getBooleanProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_REQUIRED, true, true);
  54.         this.stringType = ModISignalHubConfig.getBooleanProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_STRING_TYPE, true, true);
  55.        
  56.         this.regexp = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_REGEXP, false);
  57.        
  58.         String tmp = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_ENUM, false);
  59.         if(tmp!=null && StringUtils.isNotEmpty(tmp)) {
  60.             this.values = new ArrayList<>();
  61.             setList(tmp, this.values);
  62.         }
  63.        
  64.         this.minLength = ModISignalHubConfig.getIntProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_MIN_LENGTH, false, -1);
  65.         this.maxLength = ModISignalHubConfig.getIntProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_MAX_LENGTH, false, -1);
  66.        
  67.         this.info = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_INFO, true);
  68.        
  69.         tmp = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_DEFAULT_RULE, true);
  70.         this.rules = new ArrayList<>();
  71.         setList(tmp, this.rules);
  72.            
  73.         tmp = ModISignalHubConfig.getProperty(prefix, p, ModISignalHubConfig.PROPERTY_PARAMS+"."+propertyId+"."+PROPERTY_DEFAULT_RULE_INFO, true);
  74.         this.rulesInfo = new ArrayList<>();
  75.         setList(tmp, this.rulesInfo);

  76.     }
  77.    
  78.     private static void setList(String v, List<String> list) {
  79.         String [] split = v.split(",");
  80.         if(split!=null && split.length>0) {
  81.             for (String s : split) {
  82.                 if(s!=null) {
  83.                     s = s.trim();
  84.                     if(StringUtils.isNotEmpty(s)) {
  85.                         list.add(s);
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91.        
  92.     private String propertyId;

  93.     private String nome;
  94.     private String label;
  95.     private boolean required;
  96.     private boolean stringType;
  97.     private String regexp;
  98.     private List<String> values;
  99.     private int minLength;
  100.     private int maxLength;
  101.     private String info;
  102.     private List<String> rules;
  103.     private List<String> rulesInfo;
  104.    
  105.     public ModISignalHubParamConfig copyNewInstance() {
  106.         ModISignalHubParamConfig newInstance = new ModISignalHubParamConfig();
  107.         newInstance.propertyId = this.propertyId;
  108.         newInstance.nome = this.nome;
  109.         newInstance.label = this.label;
  110.         newInstance.required = this.required;
  111.         newInstance.stringType = this.stringType;
  112.         newInstance.regexp = this.regexp;
  113.        
  114.         newInstance.values = new ArrayList<>();
  115.         if(this.values!=null && !this.values.isEmpty()) {
  116.             newInstance.values.addAll(this.values);
  117.         }
  118.        
  119.         newInstance.minLength = this.minLength;
  120.         newInstance.maxLength = this.maxLength;
  121.        
  122.         newInstance.info = this.info;
  123.        
  124.         newInstance.rules = new ArrayList<>();
  125.         if(this.rules!=null && !this.rules.isEmpty()) {
  126.             newInstance.rules.addAll(this.rules);
  127.         }
  128.        
  129.         newInstance.rulesInfo = new ArrayList<>();
  130.         if(this.rulesInfo!=null && !this.rulesInfo.isEmpty()) {
  131.             newInstance.rulesInfo.addAll(this.rulesInfo);
  132.         }
  133.        
  134.         return newInstance;
  135.     }
  136.    
  137.     public String getPropertyId() {
  138.         return this.propertyId;
  139.     }

  140.     public String getNome() {
  141.         return this.nome;
  142.     }
  143.    
  144.     public String getLabel() {
  145.         return this.label;
  146.     }

  147.     public boolean isRequired() {
  148.         return this.required;
  149.     }

  150.     public boolean isStringType() {
  151.         return this.stringType;
  152.     }

  153.     public String getRegexp() {
  154.         return this.regexp;
  155.     }
  156.    
  157.     public List<String> getValues() {
  158.         return this.values;
  159.     }
  160.    
  161.     public int getMinLength() {
  162.         return this.minLength;
  163.     }
  164.     public int getMaxLength() {
  165.         return this.maxLength;
  166.     }
  167.    
  168.     public String getInfo() {
  169.         return this.info;
  170.     }

  171.     public List<String> getRules() {
  172.         return this.rules;
  173.     }
  174.     public void setRules(List<String> rules) {
  175.         this.rules = rules;
  176.     }
  177.    
  178.     public List<String> getRulesInfo() {
  179.         return this.rulesInfo;
  180.     }
  181.     public void setRulesInfo(List<String> rulesInfo) {
  182.         this.rulesInfo = rulesInfo;
  183.     }
  184. }