ProtocolPropertiesUtilities.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.web.ctrlstat.servlet.protocol_properties;

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

  24. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  25. import org.openspcoop2.core.registry.ProtocolProperty;
  26. import org.openspcoop2.protocol.sdk.ProtocolException;
  27. import org.openspcoop2.protocol.sdk.constants.ConsoleInterfaceType;
  28. import org.openspcoop2.protocol.sdk.constants.ConsoleItemType;
  29. import org.openspcoop2.protocol.sdk.constants.ConsoleItemValueType;
  30. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  31. import org.openspcoop2.protocol.sdk.properties.AbstractConsoleItem;
  32. import org.openspcoop2.protocol.sdk.properties.BaseConsoleItem;
  33. import org.openspcoop2.protocol.sdk.properties.BinaryConsoleItem;
  34. import org.openspcoop2.protocol.sdk.properties.BooleanConsoleItem;
  35. import org.openspcoop2.protocol.sdk.properties.NumberConsoleItem;
  36. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  37. import org.openspcoop2.protocol.sdk.properties.StringConsoleItem;
  38. import org.openspcoop2.protocol.sdk.properties.SubtitleConsoleItem;
  39. import org.openspcoop2.protocol.sdk.properties.TitleConsoleItem;
  40. import org.openspcoop2.utils.SortedMap;
  41. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  42. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneUtilities;
  43. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  44. import org.openspcoop2.web.lib.mvc.DataElement;
  45. import org.openspcoop2.web.lib.mvc.DataElement.STATO_APERTURA_SEZIONI;
  46. import org.openspcoop2.web.lib.mvc.DataElementInfo;
  47. import org.openspcoop2.web.lib.mvc.DataElementType;
  48. import org.openspcoop2.web.lib.mvc.Parameter;


  49. /**
  50.  * ProtocolPropertiesUtilities
  51.  *
  52.  * @author Pintori Giuliano (pintori@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class ProtocolPropertiesUtilities {
  57.    
  58.     private ProtocolPropertiesUtilities() {}


  59.     public static ConsoleInterfaceType getTipoInterfaccia(ConsoleHelper consoleHelper){
  60.         if(consoleHelper.isModalitaStandard()) {
  61.             return ConsoleInterfaceType.STANDARD;
  62.         }
  63.         if(consoleHelper.isModalitaCompleta()) {
  64.             return ConsoleInterfaceType.COMPLETA;
  65.         }
  66.         return ConsoleInterfaceType.AVANZATA;
  67.     }

  68.     private static String getPrefixErrorItemConClasse(AbstractConsoleItem<?> abItem) {
  69.         return "Item con classe ["+abItem.getClass()+"] ";
  70.     }
  71.     private static String getPrefixErrorItemConClasse(BaseConsoleItem item) {
  72.         return "Item con classe ["+item.getClass()+"] ";
  73.     }
  74.    
  75.    
  76.     public static List<DataElement> itemToDataElement(List<DataElement> dati ,
  77.             ConsoleHelper consoleHelper,
  78.             BaseConsoleItem item, Object defaultItemValue,
  79.             ConsoleOperationType consoleOperationType,
  80.             Properties binaryChangeProperties, ProtocolProperty protocolProperty, int size) throws ProtocolException {
  81.         return itemToDataElementEngine(dati, consoleHelper,
  82.                 item, defaultItemValue,
  83.                 consoleOperationType,
  84.                 binaryChangeProperties,
  85.                 protocolProperty!=null ? protocolProperty.getId() : null,
  86.                 protocolProperty!=null ? protocolProperty.getFile() : null,
  87.                 size,
  88.                 protocolProperty!=null && (protocolProperty.getByteFile()!=null));
  89.     }
  90.     public static List<DataElement> itemToDataElement(List<DataElement> dati ,
  91.             ConsoleHelper consoleHelper,
  92.             BaseConsoleItem item, Object defaultItemValue,
  93.             ConsoleOperationType consoleOperationType,
  94.             Properties binaryChangeProperties, org.openspcoop2.core.config.ProtocolProperty protocolProperty, int size) throws ProtocolException {
  95.         return itemToDataElementEngine(dati, consoleHelper,
  96.                 item, defaultItemValue,
  97.                 consoleOperationType,
  98.                 binaryChangeProperties,
  99.                 protocolProperty!=null ? protocolProperty.getId() : null,
  100.                 protocolProperty!=null ? protocolProperty.getFile() : null,
  101.                 size,
  102.                 protocolProperty!=null && (protocolProperty.getByteFile()!=null));
  103.     }
  104.     private static List<DataElement> itemToDataElementEngine(List<DataElement> dati ,
  105.             ConsoleHelper consoleHelper,
  106.             BaseConsoleItem item, Object defaultItemValue,
  107.             ConsoleOperationType consoleOperationType,
  108.             Properties binaryChangeProperties,
  109.             Long protocolPropertyId, String protocolPropertyFile, int size,
  110.             boolean contentSaved) throws ProtocolException {
  111.         if(item == null)
  112.             return dati;

  113.         // tipi con valore
  114.         if(item instanceof AbstractConsoleItem<?>){
  115.             AbstractConsoleItem<?> abItem = (AbstractConsoleItem<?>) item;
  116.             switch (abItem.getType()) {
  117.             case CHECKBOX:
  118.                 getCheckbox(dati,abItem, defaultItemValue, size);
  119.                 break;
  120.             case LOCK:
  121.                 getText(dati, consoleHelper,abItem, size, DataElementType.LOCK);
  122.                 break;
  123.             case LOCK_HIDDEN:
  124.                 getHidden(dati, consoleHelper, abItem, size);
  125.                 break;
  126.             case CRYPT:
  127.                 getText(dati, consoleHelper,abItem, size, DataElementType.CRYPT);
  128.                 break;
  129.             case FILE:
  130.                 getFile(dati, consoleHelper, abItem, size, consoleOperationType,binaryChangeProperties, protocolPropertyId, protocolPropertyFile, contentSaved);
  131.                 break;
  132.             case HIDDEN:
  133.                 getHidden(dati, consoleHelper, abItem, size);
  134.                 break;
  135.             case SELECT:
  136.                 getSelect(dati,abItem, defaultItemValue, size);
  137.                 break;
  138.             case MULTI_SELECT:
  139.                 getMultiSelect(dati,abItem, defaultItemValue, size);
  140.                 break;
  141.             case TEXT:
  142.                 getText(dati, consoleHelper,abItem, size, DataElementType.TEXT);
  143.                 break;
  144.             case TEXT_AREA:
  145.                 getText(dati, consoleHelper,abItem, size, DataElementType.TEXT_AREA);
  146.                 break;
  147.             case TEXT_AREA_NO_EDIT:
  148.                 getText(dati, consoleHelper,abItem, size, DataElementType.TEXT_AREA_NO_EDIT);
  149.                 break;
  150.             case TEXT_EDIT:
  151.                 getText(dati, consoleHelper,abItem, size, DataElementType.TEXT_EDIT);
  152.                 break;
  153.             case TAGS:
  154.                 getText(dati, consoleHelper,abItem, size, DataElementType.TEXT_EDIT);
  155.                 dati.get(dati.size()-1).enableTags();
  156.                 break;
  157.             case NUMBER:
  158.                 getText(dati, consoleHelper,abItem, size, DataElementType.NUMBER);
  159.                 break;
  160.             default:
  161.                 throw new ProtocolException(getPrefixErrorItemConClasse(abItem)+"identificato come tipo AbstractConsoleItem ma con Type: ["+abItem.getType()+"] di tipo titolo o note");
  162.             }
  163.         } else {
  164.             // titoli e note
  165.             switch (item.getType()) {
  166.             case NOTE:
  167.                 getTitle(dati,item, size,DataElementType.NOTE);
  168.                 break;
  169.             case SUBTITLE:
  170.                 getTitle(dati,item, size,DataElementType.SUBTITLE);
  171.                 break;
  172.             case TITLE:
  173.                 getTitle(dati,item, size,DataElementType.TITLE);
  174.                 break;
  175.             case HIDDEN:
  176.                 getHidden(dati, consoleHelper, item, size);
  177.                 break;
  178.             default:
  179.                 throw new ProtocolException(getPrefixErrorItemConClasse(item)+"non identificato come tipo AbstractConsoleItem ma con Type: ["+item.getType()+"] non di tipo titolo o note");
  180.             }
  181.         }

  182.         return dati;
  183.     }
  184.    
  185.     public static List<DataElement> itemToDataElementAsHidden(List<DataElement> dati ,ConsoleHelper consoleHelper, BaseConsoleItem item, Object defaultItemValue,
  186.             ConsoleOperationType consoleOperationType,
  187.             Properties binaryChangeProperties, ProtocolProperty protocolProperty, int size) throws ProtocolException {
  188.        
  189.         if(defaultItemValue!=null || consoleOperationType!=null || binaryChangeProperties!=null || protocolProperty!=null) {
  190.             // nop
  191.         }
  192.        
  193.         if(item == null)
  194.             return dati;

  195.         // tipi con valore
  196.         if(item instanceof AbstractConsoleItem<?>){
  197.             AbstractConsoleItem<?> abItem = (AbstractConsoleItem<?>) item;
  198.             switch (abItem.getType()) {
  199.             case CHECKBOX:
  200.             case LOCK:
  201.             case LOCK_HIDDEN:
  202.             case CRYPT:
  203.             case FILE:
  204.             case HIDDEN:
  205.             case SELECT:
  206.             case MULTI_SELECT:
  207.             case TEXT:
  208.             case TEXT_AREA:
  209.             case TEXT_AREA_NO_EDIT:
  210.             case TEXT_EDIT:
  211.             case TAGS:
  212.             case NUMBER:
  213.                 getHidden(dati, consoleHelper, abItem, size);
  214.                 break;
  215.             default:
  216.                 throw new ProtocolException(getPrefixErrorItemConClasse(abItem)+"identificato come tipo AbstractConsoleItem ma con Type: ["+abItem.getType()+"] di tipo titolo o note");
  217.             }
  218.         } else {
  219.             // titoli e note non vengono aggiunti lascio il controllo dei tipi per sicurezza
  220.             switch (item.getType()) {
  221.             case NOTE:
  222.             case SUBTITLE:
  223.             case TITLE:
  224.             case HIDDEN:
  225.                 break;
  226.             default:
  227.                 throw new ProtocolException(getPrefixErrorItemConClasse(item)+"non identificato come tipo AbstractConsoleItem ma con Type: ["+item.getType()+"] non di tipo titolo o note");
  228.             }
  229.         }

  230.         return dati;
  231.     }

  232.     public static List<DataElement> getTitle(List<DataElement> dati ,BaseConsoleItem item, int size, DataElementType type) {
  233.         DataElement de = new DataElement();
  234.         de.setName(item.getId());
  235.         de.setType(type);
  236.         de.setLabel(item.getLabel());
  237.         de.setSize(size);
  238.         de.setValue("");

  239.         if(ConsoleItemType.TITLE.equals(item.getType()) && item instanceof TitleConsoleItem) {
  240.             TitleConsoleItem titleItem = (TitleConsoleItem) item;
  241.             if(titleItem.isCloseable()) {
  242.                 de.setStatoAperturaSezioni(STATO_APERTURA_SEZIONI.CHIUSO);
  243.             }
  244.         }
  245.         else if(ConsoleItemType.SUBTITLE.equals(item.getType()) && item instanceof SubtitleConsoleItem) {
  246.             SubtitleConsoleItem subItem = (SubtitleConsoleItem) item;
  247.             if(subItem.isCloseable()) {
  248.                 de.setStatoAperturaSezioni(STATO_APERTURA_SEZIONI.CHIUSO);
  249.             }
  250.         }
  251.        
  252.        
  253.         dati.add(de);

  254.         return dati;
  255.     }

  256.     private static String getPrefixMessageErrorConsoleItemType(ConsoleItemValueType consoleItemValueType) {
  257.         return "Item con consoleItemType ["+consoleItemValueType+"] ";
  258.     }
  259.    
  260.     public static List<DataElement> getText(List<DataElement> dati ,ConsoleHelper consoleHelper, AbstractConsoleItem<?> item, int size, DataElementType type) throws ProtocolException {
  261.         DataElement de = new DataElement();
  262.         de.setName(item.getId());
  263.         if(DataElementType.LOCK.equals(type)) {
  264.             // imposto il tipo insieme al valore
  265.         }
  266.         else {
  267.             de.setType(type);
  268.         }
  269.         de.setRequired(item.isRequired());
  270.         de.setLabel(item.getLabel());
  271.         de.setLabelRight(item.getLabelRight());
  272.         if(item.isReloadOnChange()) {
  273.             if(item.isReloadOnHttpPost()) {
  274.                 de.setPostBack_viaPOST(true);
  275.             }
  276.             else {
  277.                 de.setPostBack(true);
  278.             }
  279.         }
  280.         de.setNote(item.getNote());
  281.         de.setSize(size);
  282.         addDataElementInfo(item, de);
  283.        
  284.         ConsoleItemValueType consoleItemValueType = ProtocolPropertiesUtils.getConsoleItemValueType(item);

  285.         setTextValue(consoleItemValueType, consoleHelper, item, de, type);
  286.        
  287.         if(item.getDefaultValueForCloseableSection() instanceof String) {
  288.             String s = (String) item.getDefaultValueForCloseableSection();
  289.             de.setValoreDefault(s);
  290.         }      

  291.         dati.add(de);

  292.         return dati;
  293.     }
  294.     private static void setTextValue(ConsoleItemValueType consoleItemValueType,ConsoleHelper consoleHelper,AbstractConsoleItem<?> item,DataElement de, DataElementType type) throws ProtocolException {
  295.         String value = null;
  296.         switch(consoleItemValueType){
  297.         case BOOLEAN:
  298.             BooleanConsoleItem booleanItem = (BooleanConsoleItem) item;
  299.             value = booleanItem.getDefaultValue() != null ? booleanItem.getDefaultValue() + "" : "";
  300.             break;
  301.         case NUMBER:
  302.             NumberConsoleItem numberItem = (NumberConsoleItem) item;
  303.             value = numberItem.getDefaultValue() != null ? numberItem.getDefaultValue() + "" : "";
  304.             if(DataElementType.NUMBER.equals(type)) {
  305.                 de.setMinValue((int)numberItem.getMin());
  306.                 de.setMaxValue((int)numberItem.getMax());
  307.             }
  308.             break;
  309.         case STRING:
  310.             StringConsoleItem stringItem = (StringConsoleItem) item;
  311.             value = stringItem.getDefaultValue() != null ? stringItem.getDefaultValue() : "";
  312.             if(stringItem.getRows()!=null) {
  313.                 de.setRows(stringItem.getRows());
  314.             }
  315.             break;
  316.         case BINARY: // NOP
  317.             value = "Prova Binary";
  318.             break;
  319.         default:
  320.             throw new ProtocolException(getPrefixMessageErrorConsoleItemType(consoleItemValueType)+"non puo' essere visualizzato come un "+type);
  321.         }
  322.        
  323.         if(DataElementType.LOCK.equals(type)) {
  324.             // imposto il tipo insieme al valore
  325.             try {
  326.                 consoleHelper.getCore().getLockUtilities().lock(de, value);
  327.             }catch(Exception e) {
  328.                 throw new ProtocolException(e.getMessage(),e);
  329.             }
  330.         }
  331.         else {
  332.             de.setValue(value);
  333.         }

  334.     }

  335.     public static List<DataElement> getFile(List<DataElement> dati ,
  336.             ConsoleHelper consoleHelper,
  337.             AbstractConsoleItem<?> item, int size, ConsoleOperationType consoleOperationType,
  338.             Properties binaryChangeProperties,
  339.             Long protocolPropertyId, String protocolPropertyFile,
  340.             boolean contentSaved) {
  341.        
  342.         if(consoleHelper!=null) {
  343.             // nop
  344.         }
  345.        
  346.         DataElement de = new DataElement();
  347.         DataElement de2 =null ;
  348.         List<DataElement> df = null;
  349.         de.setName(item.getId());

  350.         /**String nameRechange = ProtocolPropertiesCostanti.PARAMETER_FILENAME_RECHANGE_PREFIX + item.getId();
  351.         String nameRechangeParamTmp = consoleHelper.getParameter(nameRechange);
  352.         boolean isNameRechange = "true".equals(nameRechangeParamTmp);
  353.        
  354.         org.openspcoop2.protocol.sdk.properties.BinaryConsoleItem bci = null;
  355.         String fileName = null;
  356.         if(item!=null && item instanceof org.openspcoop2.protocol.sdk.properties.BinaryConsoleItem) {
  357.             bci = (org.openspcoop2.protocol.sdk.properties.BinaryConsoleItem) item;
  358.             fileName = bci.getFileName();
  359.         }
  360.         if(!consoleOperationType.equals(ConsoleOperationType.ADD) && fileName==null) {
  361.             // aggiungo riferimento per dopo
  362.             DataElement deChange = new DataElement();
  363.             deChange.setName(nameRechange);
  364.             deChange.setValue("true");
  365.             deChange.setType(DataElementType.HIDDEN);
  366.             dati.add(deChange);
  367.         }*/
  368.        
  369.         /**boolean addDE = true;*/
  370.        
  371.         if(consoleOperationType.equals(ConsoleOperationType.ADD) || !contentSaved){
  372.             BinaryConsoleItem binaryItem = (BinaryConsoleItem) item;

  373.             BinaryParameter bp = new BinaryParameter();
  374.             bp.setName(binaryItem.getId());
  375.             bp.setFilename(binaryItem.getFileName());
  376.             bp.setId(binaryItem.getFileId());

  377.             de = bp.getFileDataElement(item.getLabel(), "", size);
  378.             de.setRequired(item.isRequired());
  379.             /**         de.setPostBack(item.isReloadOnChange()); */
  380.             df = bp.getFileNameDataElement();
  381.             de2 = bp.getFileIdDataElement();
  382.         } else {
  383.            
  384.             /**if(fileName==null || isNameRechange) {
  385.                 addDE = false;
  386.             }*/
  387.            
  388.             de.setType(DataElementType.LINK);
  389.             String idItem = protocolPropertyId != null ? protocolPropertyId + "" : "";
  390.             String idProprietario = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_ID_PROPRIETARIO);
  391.             String urlChange= binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_URL_ORIGINALE_CHANGE);
  392.             String tipoProprietario = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_PROPRIETARIO);
  393.             String nomeProprietario = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_NOME_PROPRIETARIO);
  394.             String parentProprietario = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_NOME_PARENT_PROPRIETARIO);
  395.             if(parentProprietario == null)
  396.                 parentProprietario = "";
  397.             String protocollo = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_PROTOCOLLO);
  398.             String tipoAccordo = binaryChangeProperties.getProperty(ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_ACCORDO);
  399.             if(tipoAccordo == null)
  400.                 tipoAccordo = "";

  401.             de.setUrl(ProtocolPropertiesCostanti.SERVLET_NAME_BINARY_PROPERTY_CHANGE,
  402.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_ID,idItem),
  403.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_NOME,item.getId()),
  404.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_ID_PROPRIETARIO,idProprietario),
  405.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_PROPRIETARIO,tipoProprietario),
  406.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_NOME_PROPRIETARIO,nomeProprietario),
  407.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_NOME_PARENT_PROPRIETARIO,parentProprietario),
  408.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_PROTOCOLLO,protocollo),
  409.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_ACCORDO, tipoAccordo),
  410.                     new Parameter(ProtocolPropertiesCostanti.PARAMETRO_PP_URL_ORIGINALE_CHANGE,urlChange));
  411.             // CHANGE Label del link
  412.             de.setValue(item.getLabel());

  413.             if(protocolPropertyFile != null){
  414.                 de2 = new DataElement();
  415.                 de2.setName(ProtocolPropertiesCostanti.PARAMETER_FILENAME_PREFIX + item.getId());
  416.                 de2.setValue(protocolPropertyFile);
  417.                 de2.setType(DataElementType.HIDDEN);

  418.             }
  419.         }

  420.         /**if(addDE) {*/
  421.         dati.add(de);
  422.         /**}*/
  423.        
  424.         if(df != null)
  425.             dati.addAll(df);

  426.         if(de2 != null)
  427.             dati.add(de2);

  428.         return dati;
  429.     }

  430.     private static void addDataElementInfo(AbstractConsoleItem<?> item, DataElement de) {
  431.         if(item.getInfo()!=null) {
  432.             DataElementInfo dInfo = new DataElementInfo(item.getInfo().getHeaderFinestraModale());
  433.             dInfo.setHeaderBody(item.getInfo().getHeaderBody());
  434.             if(item.getInfo().getListBody()!=null && !item.getInfo().getListBody().isEmpty()) {
  435.                 dInfo.setListBody(item.getInfo().getListBody());
  436.             }
  437.             de.setInfo(dInfo);
  438.         }
  439.     }
  440.    
  441.     private static Boolean getSelectedValue(BooleanConsoleItem booleanItem, Object defaultItemValue) {
  442.         Boolean selectedBooleanValue = null;
  443.         if(booleanItem.getDefaultValue() != null) {
  444.             selectedBooleanValue = booleanItem.getDefaultValue();
  445.         }
  446.         else if(defaultItemValue instanceof Boolean) {
  447.             selectedBooleanValue = (Boolean) defaultItemValue;
  448.         }
  449.         else {
  450.             selectedBooleanValue = false;
  451.         }
  452.         return selectedBooleanValue;
  453.     }
  454.     private static String getSelectedValue(NumberConsoleItem numberItem, Object defaultItemValue) {
  455.         String selectedNumberValue = null;
  456.         if(numberItem.getDefaultValue()!=null) {
  457.             selectedNumberValue = numberItem.getDefaultValue() + "";
  458.         }
  459.         else if(defaultItemValue instanceof Long) {
  460.             selectedNumberValue = (defaultItemValue) + "";
  461.         }
  462.         else if(defaultItemValue instanceof Integer) {
  463.             selectedNumberValue = (defaultItemValue) + "";
  464.         }
  465.         else {
  466.             selectedNumberValue = null;
  467.         }
  468.         return selectedNumberValue;
  469.     }
  470.     private static String getSelectedValue(StringConsoleItem stringItem, Object defaultItemValue) {
  471.         String selectedStringValue = null;
  472.         if(stringItem.getDefaultValue()!=null) {
  473.             selectedStringValue = stringItem.getDefaultValue();
  474.         }
  475.         else if(defaultItemValue instanceof String) {
  476.             selectedStringValue = ((String) defaultItemValue);
  477.         }
  478.         else {
  479.             selectedStringValue = null;
  480.         }
  481.         return selectedStringValue;
  482.     }
  483.    
  484.     public static List<DataElement> getCheckbox(List<DataElement> dati ,AbstractConsoleItem<?> item, Object defaultItemValue, int size) throws ProtocolException{
  485.         DataElement de = new DataElement();
  486.         de.setName(item.getId());
  487.         de.setType(DataElementType.CHECKBOX);
  488.         de.setRequired(item.isRequired());
  489.         de.setLabel(item.getLabel());
  490.         de.setLabelRight(item.getLabelRight());
  491.         if(item.isReloadOnChange()) {
  492.             if(item.isReloadOnHttpPost()) {
  493.                 de.setPostBack_viaPOST(true);
  494.             }
  495.             else {
  496.                 de.setPostBack(true);
  497.             }
  498.         }
  499.         de.setNote(item.getNote());
  500.         de.setSize(size);
  501.         addDataElementInfo(item, de);

  502.         ConsoleItemValueType consoleItemValueType = ProtocolPropertiesUtils.getConsoleItemValueType(item);

  503.         switch(consoleItemValueType){
  504.         case BOOLEAN:
  505.             BooleanConsoleItem booleanItem = (BooleanConsoleItem) item;
  506.             Boolean selectedBooleanValue = getSelectedValue(booleanItem, defaultItemValue);
  507.             de.setSelected(selectedBooleanValue);
  508.             break;
  509.         case NUMBER:
  510.             NumberConsoleItem numberItem = (NumberConsoleItem) item;
  511.             String selectedNumberValue = getSelectedValue(numberItem, defaultItemValue);
  512.             de.setSelected(selectedNumberValue);
  513.             break;
  514.         case STRING:
  515.             StringConsoleItem stringItem = (StringConsoleItem) item;
  516.             String selectedStringValue = getSelectedValue(stringItem, defaultItemValue);
  517.             de.setSelected(selectedStringValue);
  518.             break;
  519.         case BINARY: // non supportato
  520.         default:
  521.             throw new ProtocolException(getPrefixMessageErrorConsoleItemType(consoleItemValueType)+"non puo' essere visualizzato come una CheckBox");
  522.         }
  523.        
  524.         if(item.getDefaultValueForCloseableSection() instanceof Boolean) {
  525.             boolean b = (Boolean) item.getDefaultValueForCloseableSection();
  526.             de.setValoreDefaultCheckbox(b);
  527.         }

  528.         dati.add(de);

  529.         return dati;
  530.     }

  531.     public static List<DataElement> getHidden(List<DataElement> dati, ConsoleHelper consoleHelper, AbstractConsoleItem<?> item, int size) throws ProtocolException {
  532.         DataElement de = new DataElement();
  533.         de.setName(item.getId());
  534.         de.setType(DataElementType.HIDDEN);
  535.         de.setRequired(item.isRequired());
  536.         de.setLabel(item.getLabel());
  537.         de.setLabelRight(item.getLabelRight());
  538.         if(item.isReloadOnChange()) {
  539.             if(item.isReloadOnHttpPost()) {
  540.                 de.setPostBack_viaPOST(true);
  541.             }
  542.             else {
  543.                 de.setPostBack(true);
  544.             }
  545.         }
  546.         de.setNote(item.getNote());
  547.         de.setSize(size);
  548.         /**addDataElementInfo(item, de);*/

  549.         ConsoleItemValueType consoleItemValueType = ProtocolPropertiesUtils.getConsoleItemValueType(item);

  550.         setHiddenValue(consoleItemValueType, consoleHelper, item, de);

  551.         dati.add(de);

  552.         return dati;
  553.     }
  554.     private static void setHiddenValue(ConsoleItemValueType consoleItemValueType,ConsoleHelper consoleHelper,AbstractConsoleItem<?> item,DataElement de) throws ProtocolException {
  555.        
  556.         String value = null;
  557.         switch(consoleItemValueType){
  558.         case BOOLEAN:
  559.             BooleanConsoleItem booleanItem = (BooleanConsoleItem) item;
  560.             value = booleanItem.getDefaultValue() != null ? booleanItem.getDefaultValue() + "" : "";
  561.             break;
  562.         case NUMBER:
  563.             NumberConsoleItem numberItem = (NumberConsoleItem) item;
  564.             value = numberItem.getDefaultValue() != null ? numberItem.getDefaultValue() + "" : "";
  565.             break;
  566.         case STRING:
  567.             StringConsoleItem stringItem = (StringConsoleItem) item;
  568.             value = stringItem.getDefaultValue() != null ? stringItem.getDefaultValue() + "" : "";
  569.             break;
  570.         case BINARY: // NOP
  571.             value = "";
  572.             break;
  573.         default:
  574.             throw new ProtocolException(getPrefixMessageErrorConsoleItemType(consoleItemValueType)+"non puo' essere visualizzato come una Hidden");
  575.         }
  576.        
  577.         if(item.isLockedType()) {
  578.             // imposto il tipo insieme al valore
  579.             try {
  580.                 consoleHelper.getCore().getLockUtilities().lockHidden(de, value);
  581.             }catch(Exception e) {
  582.                 throw new ProtocolException(e.getMessage(),e);
  583.             }
  584.         }
  585.         else {
  586.             de.setValue(value);
  587.         }

  588.     }
  589.    
  590.     public static List<DataElement> getHidden(List<DataElement> dati, ConsoleHelper consoleHelper ,BaseConsoleItem item, int size) {
  591.         DataElement de = new DataElement();
  592.         de.setName(item.getId());
  593.         de.setType(DataElementType.HIDDEN);
  594.         de.setLabel(item.getLabel());
  595.         de.setSize(size);
  596.         dati.add(de);

  597.         return dati;
  598.     }

  599.     public static List<DataElement> getSelect(List<DataElement> dati ,AbstractConsoleItem<?> item, Object defaultItemValue, int size) throws ProtocolException {
  600.         DataElement de = new DataElement();
  601.         de.setName(item.getId());
  602.         de.setType(DataElementType.SELECT);
  603.         de.setRequired(item.isRequired());
  604.         de.setLabel(item.getLabel());
  605.         de.setLabelRight(item.getLabelRight());
  606.         if(item.isReloadOnChange()) {
  607.             if(item.isReloadOnHttpPost()) {
  608.                 de.setPostBack_viaPOST(true);
  609.             }
  610.             else {
  611.                 de.setPostBack(true);
  612.             }
  613.         }
  614.         de.setNote(item.getNote());
  615.         de.setSize(size);
  616.         addDataElementInfo(item, de);

  617.         ConsoleItemValueType consoleItemValueType = ProtocolPropertiesUtils.getConsoleItemValueType(item);

  618.         List<String> values = new ArrayList<>();
  619.         List<String> labels = new ArrayList<>();

  620.         switch(consoleItemValueType){
  621.         case BOOLEAN:
  622.             BooleanConsoleItem booleanItem = (BooleanConsoleItem) item;
  623.             Boolean selectedBooleanValue = getSelectedValue(booleanItem, defaultItemValue);
  624.             de.setSelected(selectedBooleanValue);

  625.             SortedMap<Boolean> booleanMapLabelValues = booleanItem.getMapLabelValues();
  626.             for (String key : booleanMapLabelValues.keys()) {
  627.                 labels.add(key);
  628.                 values.add(booleanMapLabelValues.get(key)+ "");
  629.             }
  630.             break;
  631.         case NUMBER:
  632.             NumberConsoleItem numberItem = (NumberConsoleItem) item;
  633.             String selectedNumberValue = getSelectedValue(numberItem, defaultItemValue);
  634.             de.setSelected(selectedNumberValue);

  635.             SortedMap<Long> numberMapLabelValues = numberItem.getMapLabelValues();
  636.             for (String key : numberMapLabelValues.keys()) {
  637.                 labels.add(key);
  638.                 values.add(numberMapLabelValues.get(key)+ "");
  639.             }
  640.             break;
  641.         case STRING:
  642.             StringConsoleItem stringItem = (StringConsoleItem) item;
  643.             String selectedStringValue = getSelectedValue(stringItem, defaultItemValue);
  644.             de.setSelected(selectedStringValue);

  645.             SortedMap<String> stringMapLabelValues = stringItem.getMapLabelValues();
  646.             for (String key : stringMapLabelValues.keys()) {
  647.                 labels.add(key);
  648.                 values.add(stringMapLabelValues.get(key)+ "");
  649.             }
  650.             break;
  651.         case BINARY: // non supportato
  652.         default:
  653.             throw new ProtocolException(getPrefixMessageErrorConsoleItemType(consoleItemValueType)+"non puo' essere visualizzato come una Select List");
  654.         }

  655.         de.setValues(values);
  656.         de.setLabels(labels);

  657.         if(item.getDefaultValueForCloseableSection() instanceof String) {
  658.             String s = (String) item.getDefaultValueForCloseableSection();
  659.             de.setValoreDefaultSelect(s);
  660.         }
  661.        
  662.         dati.add(de);

  663.         return dati;
  664.     }
  665.    
  666.     public static List<DataElement> getMultiSelect(List<DataElement> dati ,AbstractConsoleItem<?> item, Object defaultItemValue, int size) throws ProtocolException {
  667.         DataElement de = new DataElement();
  668.         de.setName(item.getId());
  669.         de.setType(DataElementType.MULTI_SELECT);
  670.         de.setRequired(item.isRequired());
  671.         de.setLabel(item.getLabel());
  672.         de.setLabelRight(item.getLabelRight());
  673.         if(item.isReloadOnChange()) {
  674.             if(item.isReloadOnHttpPost()) {
  675.                 de.setPostBack_viaPOST(true);
  676.             }
  677.             else {
  678.                 de.setPostBack(true);
  679.             }
  680.         }
  681.         de.setNote(item.getNote());
  682.         de.setSize(size);
  683.         addDataElementInfo(item, de);

  684.         ConsoleItemValueType consoleItemValueType = ProtocolPropertiesUtils.getConsoleItemValueType(item);

  685.         setValuesLabelsMultiSelect(consoleItemValueType, item, defaultItemValue, de);
  686.        
  687.         if(item.getDefaultValueForCloseableSection() instanceof String) {
  688.             String s = (String) item.getDefaultValueForCloseableSection();
  689.             de.setValoreDefaultMultiSelect(new String [] {s});
  690.         }
  691.        
  692.         dati.add(de);

  693.         return dati;
  694.     }
  695.     private static void setValuesLabelsMultiSelect(ConsoleItemValueType consoleItemValueType, AbstractConsoleItem<?> item, Object defaultItemValue, DataElement de) throws ProtocolException {
  696.         List<String> values = new ArrayList<>();
  697.         List<String> labels = new ArrayList<>();

  698.         switch(consoleItemValueType){
  699.         case STRING:
  700.             StringConsoleItem stringItem = (StringConsoleItem) item;
  701.             String selectedStringValue = getSelectedValue(stringItem, defaultItemValue);
  702.             if(selectedStringValue!=null) {
  703.                 if(selectedStringValue.contains(",")) {
  704.                     de.setSelezionati(selectedStringValue.split(","));
  705.                 }
  706.                 else {
  707.                     de.setSelezionati(new String[] {selectedStringValue});
  708.                 }
  709.             }
  710.             if(stringItem.getRows()!=null) {
  711.                 de.setRows(stringItem.getRows());
  712.             }
  713.            
  714.             SortedMap<String> stringMapLabelValues = stringItem.getMapLabelValues();
  715.             for (String key : stringMapLabelValues.keys()) {
  716.                 labels.add(key);
  717.                 values.add(stringMapLabelValues.get(key)+ "");
  718.             }
  719.             break;
  720.        
  721.         case BINARY:
  722.         case BOOLEAN:
  723.         case NUMBER:
  724.         default:
  725.             throw new ProtocolException(getPrefixMessageErrorConsoleItemType(consoleItemValueType)+"non puo' essere visualizzato come una Multi-Select List");
  726.         }

  727.         de.setValues(values);
  728.         de.setLabels(labels);
  729.     }

  730.     public static String getLabelTipoProprietario(ProprietariProtocolProperty tipoProprietario, String tipoAccordo) {
  731.         if(tipoProprietario != null){
  732.             switch (tipoProprietario) {
  733.             case ACCORDO_COOPERAZIONE:
  734.                 return ProtocolPropertiesCostanti.LABEL_AC;
  735.             case ACCORDO_SERVIZIO_PARTE_COMUNE:
  736.                 return AccordiServizioParteComuneUtilities.getTerminologiaAccordoServizio(tipoAccordo);
  737.             case ACCORDO_SERVIZIO_PARTE_SPECIFICA:
  738.                 return ProtocolPropertiesCostanti.LABEL_APS;
  739.             case AZIONE_ACCORDO:
  740.                 return ProtocolPropertiesCostanti.LABEL_AZIONE_ACCORDO;
  741.             case FRUITORE:
  742.                 return ProtocolPropertiesCostanti.LABEL_FRUITORE;
  743.             case OPERATION:
  744.                 return ProtocolPropertiesCostanti.LABEL_OPERATION;
  745.             case PORT_TYPE:
  746.                 return ProtocolPropertiesCostanti.LABEL_PORT_TYPE;
  747.             case RESOURCE:
  748.                 return ProtocolPropertiesCostanti.LABEL_RESOURCE;
  749.             case SOGGETTO:
  750.                 return ProtocolPropertiesCostanti.LABEL_SOGGETTO;
  751.             case SERVIZIO_APPLICATIVO:
  752.                 return ProtocolPropertiesCostanti.LABEL_SERVIZIO_APPLICATIVO;
  753.             }
  754.         }
  755.         return null;
  756.     }

  757.     public static String getValueParametroTipoProprietarioAccordoServizio(String tipo){
  758.         if(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE.equals(tipo)){
  759.             return ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_PROPRIETARIO_VALUE_ACCORDO_SERVIZIO_PARTE_COMUNE;
  760.         }
  761.         else{
  762.             return ProtocolPropertiesCostanti.PARAMETRO_PP_TIPO_PROPRIETARIO_VALUE_ACCORDO_SERVIZIO_COMPOSTO;
  763.         }
  764.     }
  765. }