ProtocolPropertiesUtils.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.sdk.properties;

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

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.core.id.IDSoggetto;
  26. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  27. import org.openspcoop2.core.registry.Fruitore;
  28. import org.openspcoop2.core.registry.ProtocolProperty;
  29. import org.openspcoop2.core.tracciamento.Proprieta;
  30. import org.openspcoop2.protocol.sdk.ProtocolException;
  31. import org.openspcoop2.protocol.sdk.constants.ConsoleItemValueType;
  32. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  33. import org.openspcoop2.utils.BooleanNullable;

  34. /**
  35.  * ProtocolPropertiesUtils
  36.  *
  37.  * @author Poli Andrea (apoli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class ProtocolPropertiesUtils {

  42.     public static void setDefaultValue(List<BaseConsoleItem> consoleItems, AbstractProperty<?> property) throws ProtocolException{
  43.         if(property ==null)
  44.             return;

  45.         for (BaseConsoleItem consoleItem : consoleItems) {
  46.             if(consoleItem.getId().equals(property.getId()))
  47.                 setDefaultValue(consoleItem, property);
  48.         }
  49.     }

  50.     public static void setDefaultValue(List<BaseConsoleItem> consoleItems, ProtocolProperty property){
  51.         if(property ==null)
  52.             return;

  53.         for (BaseConsoleItem consoleItem : consoleItems) {
  54.             if(consoleItem.getId().equals(property.getName()) && consoleItem instanceof AbstractConsoleItem<?>){
  55.                 if(consoleItem instanceof StringConsoleItem){
  56.                     ((StringConsoleItem) consoleItem).setDefaultValue(property.getValue());
  57.                 }
  58.                 else if(consoleItem instanceof NumberConsoleItem){
  59.                     Long numberValue = property.getNumberValue();
  60.                     ((NumberConsoleItem) consoleItem).setDefaultValue(numberValue);
  61.                 }
  62.                 else if(consoleItem instanceof BinaryConsoleItem){
  63.                     byte[] byteFile = property.getByteFile();
  64.                     ((BinaryConsoleItem) consoleItem).setFileName(property.getFile());
  65.                     ((BinaryConsoleItem) consoleItem).setDefaultValue(byteFile);
  66.                 }else if(consoleItem instanceof BooleanConsoleItem){
  67.                     Boolean booleanValue = property.getBooleanValue();
  68.                     ((BooleanConsoleItem) consoleItem).setDefaultValue(booleanValue);
  69.                 }

  70.             }
  71.         }
  72.     }
  73.    
  74.     public static List<String> getListFromMultiSelectValue(String value) {
  75.         List<String> l = new ArrayList<>();
  76.         if(value.contains(",")) {
  77.             l = Arrays.asList(value.split(","));
  78.         }
  79.         else {
  80.             l.add(value);
  81.         }
  82.         return l;
  83.     }
  84.    
  85.     public static String getValueMultiSelect(String []list) {
  86.         return getValueMultiSelect(Arrays.asList(list));
  87.     }
  88.     public static String getValueMultiSelect(List<String> list) {
  89.         StringBuilder bf = new StringBuilder();
  90.         for (String s : list) {
  91.             if(bf.length()>0) {
  92.                 bf.append(",");
  93.             }
  94.             bf.append(s);
  95.         }
  96.         return bf.toString();
  97.     }
  98.     public static void setDefaultValueMultiSelect(List<String> list, StringConsoleItem item) {
  99.         item.setDefaultValue(getValueMultiSelect(list));
  100.     }
  101.    

  102.     public static BaseConsoleItem getBaseConsoleItem(List<BaseConsoleItem> consoleItems, AbstractProperty<?> property){
  103.         if(property ==null)
  104.             return null;

  105.         String propertyId = property.getId();
  106.         return getBaseConsoleItem(consoleItems, propertyId);
  107.     }

  108.     public static BaseConsoleItem getBaseConsoleItem(List<BaseConsoleItem> consoleItems, String propertyId){
  109.         if(propertyId ==null)
  110.             return null;

  111.         for (BaseConsoleItem consoleItem : consoleItems) {
  112.             if(consoleItem.getId().equals(propertyId))
  113.                 return consoleItem;
  114.         }
  115.         return null;
  116.     }

  117.     public static AbstractConsoleItem<?> getAbstractConsoleItem(List<BaseConsoleItem> consoleItems, AbstractProperty<?> property){
  118.         if(property ==null)
  119.             return null;

  120.         String propertyId = property.getId();
  121.         return getAbstractConsoleItem(consoleItems, propertyId);
  122.     }

  123.     public static AbstractConsoleItem<?> getAbstractConsoleItem(List<BaseConsoleItem> consoleItems, ProtocolProperty property){
  124.         if(property ==null)
  125.             return null;

  126.         String propertyId = property.getName();
  127.         return getAbstractConsoleItem(consoleItems, propertyId);
  128.     }

  129.     public static AbstractConsoleItem<?> getAbstractConsoleItem(List<BaseConsoleItem> consoleItems, String propertyId){
  130.         if(propertyId ==null)
  131.             return null;

  132.         for (BaseConsoleItem consoleItem : consoleItems) {
  133.             if(consoleItem.getId().equals(propertyId) && consoleItem instanceof AbstractConsoleItem<?>)
  134.                 return (AbstractConsoleItem<?>) consoleItem;
  135.         }
  136.         return null;
  137.     }

  138.     public static AbstractProperty<?> getAbstractPropertyById(ProtocolProperties protocolProperties, String propertyId){
  139.         if(propertyId ==null)
  140.             return null;

  141.         for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  142.             AbstractProperty<?> property = protocolProperties.getProperty(i);

  143.             if(property.getId().equals(propertyId))
  144.                 return property;
  145.         }

  146.         return null;
  147.     }

  148.     public static void setDefaultValue(BaseConsoleItem item, AbstractProperty<?> property) throws ProtocolException{
  149.         Object defaultValue = null;
  150.         try{
  151.             if(item instanceof AbstractConsoleItem<?> && property != null){
  152.                 defaultValue = property.getValue();
  153.                 if(item instanceof StringConsoleItem){
  154.                     StringProperty sp = (StringProperty) property;
  155.                     ((StringConsoleItem) item).setDefaultValue(sp.getValue());
  156.                 }
  157.                 else if(item instanceof NumberConsoleItem){
  158.                     NumberProperty np = (NumberProperty) property;
  159.                     ((NumberConsoleItem) item).setDefaultValue(np.getValue());
  160.                 }
  161.                 else if(item instanceof BinaryConsoleItem){
  162.                     BinaryProperty bp = (BinaryProperty) property;
  163.                     ((BinaryConsoleItem) item).setFileId(bp.getFileId());
  164.                     ((BinaryConsoleItem) item).setFileName(bp.getFileName());
  165.                     ((BinaryConsoleItem) item).setDefaultValue(bp.getValue());
  166.                 }else if(item instanceof BooleanConsoleItem){
  167.                     BooleanProperty bolP = (BooleanProperty) property;
  168.                     ((BooleanConsoleItem) item).setDefaultValue(bolP.getValue());
  169.                 }
  170.             }
  171.         }catch(Exception e){
  172.             String defaultValueClassName = defaultValue != null ?  defaultValue.getClass().getName() : "Default Value Null";
  173.             throw new ProtocolException("Impossibile assegnare un valore di tipo ["+defaultValueClassName+"] all'item ["+item.getId()+"]");
  174.         }
  175.     }
  176.     public static ConsoleItemValueType getConsoleItemValueType(BaseConsoleItem item){
  177.         if(item instanceof AbstractConsoleItem<?>){
  178.             if(item instanceof StringConsoleItem){
  179.                 return ConsoleItemValueType.STRING;
  180.             }
  181.             else if(item instanceof NumberConsoleItem){
  182.                 return ConsoleItemValueType.NUMBER;
  183.             }
  184.             else if(item instanceof BooleanConsoleItem){
  185.                 return ConsoleItemValueType.BOOLEAN;
  186.             }
  187.             else if(item instanceof BinaryConsoleItem){
  188.                 return ConsoleItemValueType.BINARY;
  189.             }
  190.         }
  191.         return null;
  192.     }


  193.     public static List<ProtocolProperty> toProtocolPropertiesRegistry (ProtocolProperties protocolProperties, ConsoleOperationType consoleOperationType, List<ProtocolProperty> oldProtocolPropertyList){
  194.         List<ProtocolProperty> lstProtocolProperty = new ArrayList<>();


  195.         for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  196.             AbstractProperty<?> property = protocolProperties.getProperty(i);

  197.             ProtocolProperty prop = new ProtocolProperty();

  198.             prop.setName(property.getId());
  199.             boolean add = false;

  200.             if(property instanceof StringProperty){
  201.                 StringProperty sp = (StringProperty) property;
  202.                 if(StringUtils.isNotEmpty(sp.getValue())) {
  203.                     prop.setValue(sp.getValue());
  204.                 }
  205.                 /**if(StringUtils.isNotEmpty(sp.getValue()))*/
  206.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  207.                 add = true;
  208.             } else if(property instanceof NumberProperty){
  209.                 NumberProperty np = (NumberProperty) property;
  210.                 if(np.getValue() != null) {
  211.                     prop.setNumberValue(np.getValue());
  212.                 }
  213.                 /**if(np.getValue() != null)*/
  214.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  215.                 add = true;
  216.             } else if(property instanceof BinaryProperty){
  217.                 BinaryProperty bp = (BinaryProperty) property;
  218.                 if(consoleOperationType.equals(ConsoleOperationType.ADD) || bp.getValue()!=null){
  219.                     prop.setByteFile(bp.getValue());
  220.                     prop.setFile(bp.getFileName());
  221.                     if(bp.getValue() != null && bp.getValue().length > 0)
  222.                         add = true;
  223.                 }else {
  224.                     // caso change non si puo' modificare un binary quindi riporto il valore che ho trovato sul db a inizio change
  225.                     for (ProtocolProperty protocolProperty : oldProtocolPropertyList) {
  226.                         if(property.getId().equals(protocolProperty.getName())){
  227.                            
  228.                             if(bp.isClearContent()) {
  229.                                 prop.setByteFile(null);
  230.                                 prop.setFile(null);
  231.                                 add = true;
  232.                             }
  233.                             else {
  234.                                 prop.setByteFile(protocolProperty.getByteFile());
  235.                                 prop.setFile(protocolProperty.getFile());
  236.                                 if(protocolProperty.getByteFile() != null && protocolProperty.getByteFile().length > 0){
  237.                                     add = true;
  238.                                 }
  239.                             }
  240.                            
  241.                             break;
  242.                         }
  243.                     }
  244.                 }

  245.             } else if(property instanceof BooleanProperty){
  246.                 BooleanProperty bp = (BooleanProperty) property;
  247.                 prop.setBooleanValue(bp.getValue() != null ? bp.getValue() : false);
  248.                 /**if(bp.getValue() != null)*/
  249.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  250.                 add = true;
  251.             }  

  252.             if(add)
  253.                 lstProtocolProperty.add(prop);
  254.         }

  255.         return lstProtocolProperty;
  256.     }
  257.     public static List<org.openspcoop2.core.config.ProtocolProperty> toProtocolPropertiesConfig (ProtocolProperties protocolProperties, ConsoleOperationType consoleOperationType, List<org.openspcoop2.core.config.ProtocolProperty> oldProtocolPropertyList){
  258.         List<org.openspcoop2.core.config.ProtocolProperty> lstProtocolProperty = new ArrayList<>();


  259.         for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  260.             AbstractProperty<?> property = protocolProperties.getProperty(i);

  261.             org.openspcoop2.core.config.ProtocolProperty prop = new org.openspcoop2.core.config.ProtocolProperty();

  262.             prop.setName(property.getId());
  263.             boolean add = false;

  264.             if(property instanceof StringProperty){
  265.                 StringProperty sp = (StringProperty) property;
  266.                 if(StringUtils.isNotEmpty(sp.getValue())) {
  267.                     prop.setValue(sp.getValue());
  268.                 }
  269.                 /**if(StringUtils.isNotEmpty(sp.getValue()))*/
  270.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  271.                 add = true;
  272.             } else if(property instanceof NumberProperty){
  273.                 NumberProperty np = (NumberProperty) property;
  274.                 if(np.getValue() != null) {
  275.                     prop.setNumberValue(np.getValue());
  276.                 }
  277.                 /**if(np.getValue() != null)*/
  278.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  279.                 add = true;
  280.             } else if(property instanceof BinaryProperty){
  281.                 BinaryProperty bp = (BinaryProperty) property;
  282.                 if(consoleOperationType.equals(ConsoleOperationType.ADD) || bp.getValue()!=null){
  283.                     prop.setByteFile(bp.getValue());
  284.                     prop.setFile(bp.getFileName());
  285.                     if(bp.getValue() != null && bp.getValue().length > 0)
  286.                         add = true;
  287.                 }else {
  288.                     // caso change non si puo' modificare un binary quindi riporto il valore che ho trovato sul db a inizio change
  289.                     for (org.openspcoop2.core.config.ProtocolProperty protocolProperty : oldProtocolPropertyList) {
  290.                         if(property.getId().equals(protocolProperty.getName())){
  291.                            
  292.                             if(bp.isClearContent()) {
  293.                                 prop.setByteFile(null);
  294.                                 prop.setFile(null);
  295.                                 add = true;
  296.                             }
  297.                             else {
  298.                                 prop.setByteFile(protocolProperty.getByteFile());
  299.                                 prop.setFile(protocolProperty.getFile());
  300.                                 if(protocolProperty.getByteFile() != null && protocolProperty.getByteFile().length > 0){
  301.                                     add = true;
  302.                                 }
  303.                             }
  304.                            
  305.                             break;
  306.                         }
  307.                     }
  308.                 }

  309.             } else if(property instanceof BooleanProperty){
  310.                 BooleanProperty bp = (BooleanProperty) property;
  311.                 prop.setBooleanValue(bp.getValue() != null && bp.getValue());
  312.                 /**if(bp.getValue() != null)*/
  313.                 // aggiungo sempre per cercare proprieta' non valorizzate nelle search
  314.                 add = true;
  315.             }  

  316.             if(add)
  317.                 lstProtocolProperty.add(prop);
  318.         }

  319.         return lstProtocolProperty;
  320.     }

  321.     public static void mergeProtocolPropertiesRegistry (ProtocolProperties protocolProperties, List<ProtocolProperty> listaProtocolPropertiesDaDB, ConsoleOperationType consoleOperationType){
  322.        
  323.         if(consoleOperationType!=null) {
  324.             // nop
  325.         }
  326.        
  327.         for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  328.             AbstractProperty<?> property = protocolProperties.getProperty(i);

  329.             for (ProtocolProperty protocolProperty : listaProtocolPropertiesDaDB) {
  330.                 if(property.getId().equals(protocolProperty.getName())){
  331.                     if(property instanceof StringProperty){
  332.                         StringProperty sp = (StringProperty) property;
  333.                         sp.setValue(protocolProperty.getValue());
  334.                     } else if(property instanceof NumberProperty){
  335.                         NumberProperty np = (NumberProperty) property;
  336.                         np.setValue(protocolProperty.getNumberValue());
  337.                     } else if(property instanceof BinaryProperty){
  338.                         BinaryProperty bp = (BinaryProperty) property;
  339.                         bp.setValue(protocolProperty.getByteFile());
  340.                         bp.setFileName(protocolProperty.getFile());
  341.                     } else if(property instanceof BooleanProperty){
  342.                         BooleanProperty bp = (BooleanProperty) property;
  343.                         bp.setValue(protocolProperty.getBooleanValue());
  344.                     }
  345.                     break;
  346.                 }
  347.             }
  348.         }
  349.     }
  350.     public static void mergeProtocolPropertiesConfig (ProtocolProperties protocolProperties, List<org.openspcoop2.core.config.ProtocolProperty> listaProtocolPropertiesDaDB, ConsoleOperationType consoleOperationType){
  351.        
  352.         if(consoleOperationType!=null) {
  353.             // nop
  354.         }
  355.        
  356.         for (int i = 0; i < protocolProperties.sizeProperties(); i++) {
  357.             AbstractProperty<?> property = protocolProperties.getProperty(i);

  358.             for (org.openspcoop2.core.config.ProtocolProperty protocolProperty : listaProtocolPropertiesDaDB) {
  359.                 if(property.getId().equals(protocolProperty.getName())){
  360.                     if(property instanceof StringProperty){
  361.                         StringProperty sp = (StringProperty) property;
  362.                         sp.setValue(protocolProperty.getValue());
  363.                     } else if(property instanceof NumberProperty){
  364.                         NumberProperty np = (NumberProperty) property;
  365.                         np.setValue(protocolProperty.getNumberValue());
  366.                     } else if(property instanceof BinaryProperty){
  367.                         BinaryProperty bp = (BinaryProperty) property;
  368.                         bp.setValue(protocolProperty.getByteFile());
  369.                         bp.setFileName(protocolProperty.getFile());
  370.                     } else if(property instanceof BooleanProperty){
  371.                         BooleanProperty bp = (BooleanProperty) property;
  372.                         bp.setValue(protocolProperty.getBooleanValue());
  373.                     }
  374.                     break;
  375.                 }
  376.             }
  377.         }
  378.     }

  379.     public static ProtocolProperty getProtocolPropertyRegistry (String propertyId , List<ProtocolProperty> listaProtocolPropertiesDaDB){
  380.         if(listaProtocolPropertiesDaDB == null || propertyId == null)
  381.             return null;
  382.        
  383.         for (ProtocolProperty protocolProperty : listaProtocolPropertiesDaDB) {
  384.             if(propertyId.equals(protocolProperty.getName())){
  385.                 return protocolProperty;
  386.             }
  387.         }
  388.        
  389.         return null;
  390.     }
  391.     public static org.openspcoop2.core.config.ProtocolProperty getProtocolPropertyConfig (String propertyId , List<org.openspcoop2.core.config.ProtocolProperty> listaProtocolPropertiesDaDB){
  392.         if(listaProtocolPropertiesDaDB == null || propertyId == null)
  393.             return null;
  394.        
  395.         for (org.openspcoop2.core.config.ProtocolProperty protocolProperty : listaProtocolPropertiesDaDB) {
  396.             if(propertyId.equals(protocolProperty.getName())){
  397.                 return protocolProperty;
  398.             }
  399.         }
  400.        
  401.         return null;
  402.     }


  403.    
  404.    
  405.     public static String getRequiredStringValuePropertyRegistry(List<ProtocolProperty> list, String propertyName) throws ProtocolException{
  406.         String value = getStringValuePropertyRegistry(list, propertyName, true);
  407.         if(value==null){
  408.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  409.         }
  410.         return value;
  411.     }
  412.     public static String getOptionalStringValuePropertyRegistry(List<ProtocolProperty> list, String propertyName) throws ProtocolException{
  413.         String value = getStringValuePropertyRegistry(list, propertyName, false);
  414.         return value;
  415.     }
  416.     private static String getStringValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  417.        
  418.         ProtocolProperty pp = getProtocolPropertyRegistry(list, propertyName, throwNotFoundException);
  419.         if(pp!=null){
  420.             return pp.getValue();
  421.         }
  422.         if(throwNotFoundException){
  423.             throw new ProtocolException("Property ["+propertyName+"] not found");
  424.         }
  425.         else{
  426.             return null;
  427.         }
  428.        
  429.     }
  430.     public static String getRequiredStringValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  431.         String value = getStringValuePropertyConfig(list, propertyName, true);
  432.         if(value==null){
  433.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  434.         }
  435.         return value;
  436.     }
  437.     public static String getOptionalStringValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  438.         String value = getStringValuePropertyConfig(list, propertyName, false);
  439.         return value;
  440.     }
  441.     private static String getStringValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  442.        
  443.         org.openspcoop2.core.config.ProtocolProperty pp = getProtocolPropertyConfig(list, propertyName, throwNotFoundException);
  444.         if(pp!=null){
  445.             return pp.getValue();
  446.         }
  447.         if(throwNotFoundException){
  448.             throw new ProtocolException("Property ["+propertyName+"] not found");
  449.         }
  450.         else{
  451.             return null;
  452.         }
  453.        
  454.     }
  455.    
  456.     public static byte[] getRequiredBinaryValuePropertyRegistry(List<ProtocolProperty> list, String propertyName) throws ProtocolException{
  457.         byte[] value = getBinaryValuePropertyRegistry(list, propertyName, true);
  458.         if(value==null){
  459.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  460.         }
  461.         return value;
  462.     }
  463.     public static byte[] getOptionalBinaryValuePropertyRegistry(List<ProtocolProperty> list, String propertyName) throws ProtocolException{
  464.         byte[] value = getBinaryValuePropertyRegistry(list, propertyName, false);
  465.         return value;
  466.     }
  467.     private static byte[] getBinaryValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  468.        
  469.         ProtocolProperty pp = getProtocolPropertyRegistry(list, propertyName, throwNotFoundException);
  470.         if(pp!=null){
  471.             return pp.getByteFile();
  472.         }
  473.         if(throwNotFoundException){
  474.             throw new ProtocolException("Property ["+propertyName+"] not found");
  475.         }
  476.         else{
  477.             return null;
  478.         }
  479.        
  480.     }
  481.     public static byte[] getRequiredBinaryValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  482.         byte[] value = getBinaryValuePropertyConfig(list, propertyName, true);
  483.         if(value==null){
  484.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  485.         }
  486.         return value;
  487.     }
  488.     public static byte[] getOptionalBinaryValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  489.         byte[] value = getBinaryValuePropertyConfig(list, propertyName, false);
  490.         return value;
  491.     }
  492.     private static byte[] getBinaryValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  493.        
  494.         org.openspcoop2.core.config.ProtocolProperty pp = getProtocolPropertyConfig(list, propertyName, throwNotFoundException);
  495.         if(pp!=null){
  496.             return pp.getByteFile();
  497.         }
  498.         if(throwNotFoundException){
  499.             throw new ProtocolException("Property ["+propertyName+"] not found");
  500.         }
  501.         else{
  502.             return null;
  503.         }
  504.        
  505.     }
  506.    
  507.     public static BooleanNullable getOptionalBooleanValuePropertyRegistry(List<ProtocolProperty> list, String propertyName) throws ProtocolException{
  508.        
  509.         ProtocolProperty pp = getProtocolPropertyRegistry(list, propertyName, false);
  510.         if(pp!=null && pp.getBooleanValue()!=null){
  511.             return pp.getBooleanValue() ? BooleanNullable.TRUE() : BooleanNullable.FALSE();
  512.         }
  513.         return BooleanNullable.NULL();
  514.        
  515.     }
  516.     public static BooleanNullable getOptionalBooleanValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  517.        
  518.         org.openspcoop2.core.config.ProtocolProperty pp = getProtocolPropertyConfig(list, propertyName, false);
  519.         if(pp!=null && pp.getBooleanValue()!=null){
  520.             return pp.getBooleanValue() ? BooleanNullable.TRUE() : BooleanNullable.FALSE();
  521.         }
  522.         return BooleanNullable.NULL();
  523.        
  524.     }
  525.     public static boolean getBooleanValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  526.        
  527.         ProtocolProperty pp = getProtocolPropertyRegistry(list, propertyName, throwNotFoundException);
  528.         if(pp!=null){
  529.             return pp.getBooleanValue()!=null ? pp.getBooleanValue() : false;
  530.         }
  531.         if(throwNotFoundException){
  532.             throw new ProtocolException("Property ["+propertyName+"] not found");
  533.         }
  534.         else{
  535.             return false;
  536.         }
  537.        
  538.     }
  539.     public static boolean getBooleanValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  540.        
  541.         org.openspcoop2.core.config.ProtocolProperty pp = getProtocolPropertyConfig(list, propertyName, throwNotFoundException);
  542.         if(pp!=null){
  543.             return pp.getBooleanValue()!=null ? pp.getBooleanValue() : false;
  544.         }
  545.         if(throwNotFoundException){
  546.             throw new ProtocolException("Property ["+propertyName+"] not found");
  547.         }
  548.         else{
  549.             return false;
  550.         }
  551.        
  552.     }
  553.    
  554.    
  555.     public static Long getRequiredNumberValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean greatherThanZero) throws ProtocolException{
  556.         Long value = getNumberValuePropertyRegistry(list, propertyName, true, greatherThanZero);
  557.         if(value==null){
  558.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  559.         }
  560.         return value;
  561.     }
  562.     public static Long getOptionalNumberValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean greatherThanZero) throws ProtocolException{
  563.         Long value = getNumberValuePropertyRegistry(list, propertyName, false, greatherThanZero);
  564.         return value;
  565.     }
  566.     private static Long getNumberValuePropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean throwNotFoundException, boolean greatherThanZero) throws ProtocolException{
  567.        
  568.         ProtocolProperty pp = getProtocolPropertyRegistry(list, propertyName, throwNotFoundException);
  569.         if(pp!=null){
  570.             Long value = pp.getNumberValue();
  571.             if(value!=null && greatherThanZero) {
  572.                 if(value <=0) {
  573.                     throw new ProtocolException("Property ["+propertyName+"] must be greatherThanZero");
  574.                 }
  575.             }
  576.             return value;
  577.         }
  578.         if(throwNotFoundException){
  579.             throw new ProtocolException("Property ["+propertyName+"] not found");
  580.         }
  581.         else{
  582.             return null;
  583.         }
  584.        
  585.     }
  586.     public static Long getRequiredNumberValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  587.         Long value = getNumberValuePropertyConfig(list, propertyName, true);
  588.         if(value==null){
  589.             throw new ProtocolException("Property ["+propertyName+"] with null value?");
  590.         }
  591.         return value;
  592.     }
  593.     public static Long getOptionalNumberValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName) throws ProtocolException{
  594.         Long value = getNumberValuePropertyConfig(list, propertyName, false);
  595.         return value;
  596.     }
  597.     private static Long getNumberValuePropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  598.        
  599.         org.openspcoop2.core.config.ProtocolProperty pp = getProtocolPropertyConfig(list, propertyName, throwNotFoundException);
  600.         if(pp!=null){
  601.             return pp.getNumberValue();
  602.         }
  603.         if(throwNotFoundException){
  604.             throw new ProtocolException("Property ["+propertyName+"] not found");
  605.         }
  606.         else{
  607.             return null;
  608.         }
  609.        
  610.     }
  611.    
  612.    
  613.     public static ProtocolProperty getProtocolPropertyRegistry(List<ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  614.        
  615.         if(list==null || list.size()<=0){
  616.             return null;
  617.         }
  618.         for (ProtocolProperty protocolProperty : list) {
  619.             if(propertyName.equals(protocolProperty.getName())){
  620.                 return protocolProperty;
  621.             }
  622.         }
  623.        
  624.         if(throwNotFoundException){
  625.             throw new ProtocolException("Property ["+propertyName+"] not found");
  626.         }
  627.         else{
  628.             return null;
  629.         }
  630.     }
  631.     public static org.openspcoop2.core.config.ProtocolProperty getProtocolPropertyConfig(List<org.openspcoop2.core.config.ProtocolProperty> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  632.        
  633.         if(list==null || list.size()<=0){
  634.             return null;
  635.         }
  636.         for (org.openspcoop2.core.config.ProtocolProperty protocolProperty : list) {
  637.             if(propertyName.equals(protocolProperty.getName())){
  638.                 return protocolProperty;
  639.             }
  640.         }
  641.        
  642.         if(throwNotFoundException){
  643.             throw new ProtocolException("Property ["+propertyName+"] not found");
  644.         }
  645.         else{
  646.             return null;
  647.         }
  648.     }
  649.     public static Proprieta getProtocolPropertySDK(List<Proprieta> list, String propertyName, boolean throwNotFoundException) throws ProtocolException{
  650.        
  651.         if(list==null || list.size()<=0){
  652.             return null;
  653.         }
  654.         for (Proprieta protocolProperty : list) {
  655.             if(propertyName.equals(protocolProperty.getNome())){
  656.                 return protocolProperty;
  657.             }
  658.         }
  659.        
  660.         if(throwNotFoundException){
  661.             throw new ProtocolException("Property ["+propertyName+"] not found");
  662.         }
  663.         else{
  664.             return null;
  665.         }
  666.     }
  667.    
  668.     public static List<ProtocolProperty> getProtocolProperties(boolean fruizione, IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  669.         List<ProtocolProperty> listProtocolProperties = null;
  670.         Fruitore fruitore = null;
  671.         if(fruizione) {
  672.             fruitore = getFruitore(soggettoFruitore, asps);
  673.             listProtocolProperties = fruitore.getProtocolPropertyList();
  674.         }
  675.         else {
  676.             listProtocolProperties = asps.getProtocolPropertyList();
  677.         }
  678.         return listProtocolProperties;
  679.     }
  680.    
  681.     public static Fruitore getFruitore(IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  682.         if(soggettoFruitore==null) {
  683.             throw new ProtocolException("Fruitore non fornito");
  684.         }
  685.         Fruitore fruitore = null;
  686.         boolean find = false;
  687.         for (Fruitore fruitoreCheck : asps.getFruitoreList()) {
  688.             if(fruitoreCheck.getTipo().equals(soggettoFruitore.getTipo()) && fruitoreCheck.getNome().equals(soggettoFruitore.getNome())) {
  689.                 fruitore = fruitoreCheck;
  690.                 find = true;
  691.                 break;
  692.             }
  693.         }
  694.         if(!find) {
  695.             throw new ProtocolException("Fruitore '"+soggettoFruitore+"' non registrato come fruitore dell'accordo parte specifica");
  696.         }
  697.         return fruitore;
  698.     }
  699. }