ModIDynamicConfigurationAccordiParteComuneUtilities.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.properties;

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

  24. import org.openspcoop2.core.id.IDAccordo;
  25. import org.openspcoop2.core.id.IDPortType;
  26. import org.openspcoop2.core.id.IDPortTypeAzione;
  27. import org.openspcoop2.core.id.IDResource;
  28. import org.openspcoop2.core.id.IDSoggetto;
  29. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  30. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  31. import org.openspcoop2.core.registry.PortType;
  32. import org.openspcoop2.core.registry.Resource;
  33. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  34. import org.openspcoop2.core.registry.constants.ServiceBinding;
  35. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  36. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  37. import org.openspcoop2.protocol.engine.constants.Costanti;
  38. import org.openspcoop2.protocol.engine.utils.AzioniUtils;
  39. import org.openspcoop2.protocol.engine.utils.NamingUtils;
  40. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  41. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  42. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  43. import org.openspcoop2.protocol.sdk.ProtocolException;
  44. import org.openspcoop2.protocol.sdk.constants.ConsoleItemType;
  45. import org.openspcoop2.protocol.sdk.constants.ConsoleItemValueType;
  46. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  47. import org.openspcoop2.protocol.sdk.properties.AbstractConsoleItem;
  48. import org.openspcoop2.protocol.sdk.properties.ConsoleConfiguration;
  49. import org.openspcoop2.protocol.sdk.properties.IConsoleHelper;
  50. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  51. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesFactory;
  52. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  53. import org.openspcoop2.protocol.sdk.properties.StringConsoleItem;
  54. import org.openspcoop2.protocol.sdk.properties.StringProperty;
  55. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  56. import org.openspcoop2.protocol.sdk.registry.ProtocolFiltroRicercaAccordi;
  57. import org.openspcoop2.protocol.sdk.registry.ProtocolFiltroRicercaPortTypeAzioni;
  58. import org.openspcoop2.protocol.sdk.registry.ProtocolFiltroRicercaRisorse;
  59. import org.openspcoop2.protocol.sdk.registry.RegistryException;
  60. import org.openspcoop2.protocol.sdk.registry.RegistryNotFound;
  61. import org.openspcoop2.utils.SortedMap;
  62. import org.slf4j.Logger;

  63. /**
  64.  * ModIDynamicConfigurationAccordiParteComuneUtilities
  65.  *
  66.  * @author Poli Andrea (apoli@link.it)
  67.  * @author $Author$
  68.  * @version $Rev$, $Date$
  69.  */
  70. public class ModIDynamicConfigurationAccordiParteComuneUtilities {
  71.    
  72.     private ModIDynamicConfigurationAccordiParteComuneUtilities() {}

  73.     static void addProfiloInterazione(ModIProperties modiProperties,ConsoleConfiguration configuration, boolean rest, String httpMethod) throws ProtocolException {
  74.        
  75.         configuration.addConsoleItem(ProtocolPropertiesFactory.newSubTitleItem(ModIConsoleCostanti.MODIPA_API_PROFILO_INTERAZIONE_ID,
  76.                 ModIConsoleCostanti.MODIPA_API_PROFILO_INTERAZIONE_LABEL));
  77.        
  78.         ModIProfiliInterazioneRESTConfig config = null;
  79.         if(rest) {
  80.             config = new ModIProfiliInterazioneRESTConfig(modiProperties, httpMethod, null);
  81.         }
  82.    
  83.         StringConsoleItem profiloInterazioneItem = (StringConsoleItem)
  84.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  85.                 ConsoleItemType.SELECT,
  86.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID,
  87.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL);
  88.         boolean addBloccante = true;
  89.         boolean addNonBloccantePush = true;
  90.         boolean addNonBloccantePull = true;
  91.         if(rest) {
  92.             addBloccante = config.isCompatibileBloccante();
  93.             addNonBloccantePush = config.isCompatibileNonBloccantePush();
  94.             addNonBloccantePull = config.isCompatibileNonBloccantePull();
  95.         }
  96.         if(rest) {
  97.             profiloInterazioneItem.addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_CRUD,
  98.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_CRUD);
  99.         }
  100.         if(addBloccante) {
  101.             profiloInterazioneItem.addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_BLOCCANTE,
  102.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE);
  103.         }
  104.         if(addNonBloccantePush || addNonBloccantePull) {
  105.             profiloInterazioneItem.addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_NON_BLOCCANTE,
  106.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE);
  107.         }
  108.         profiloInterazioneItem.setDefaultValue(rest ? ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_REST_VALUE : ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE);
  109.         profiloInterazioneItem.setReloadOnChange(true);
  110.         configuration.addConsoleItem(profiloInterazioneItem);
  111.        
  112.         StringConsoleItem profiloInterazioneItemReadOnly = (StringConsoleItem)
  113.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  114.                 ConsoleItemType.HIDDEN,
  115.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID_INUSE_READONLY,
  116.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL);
  117.         configuration.addConsoleItem(profiloInterazioneItemReadOnly);
  118.        
  119.         StringConsoleItem profiloInterazioneAsincronaItem = (StringConsoleItem)
  120.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  121.                 ConsoleItemType.HIDDEN,
  122.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID,
  123.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_LABEL);
  124.         profiloInterazioneAsincronaItem.setDefaultValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_DEFAULT_VALUE);
  125.         profiloInterazioneAsincronaItem.setReloadOnChange(true);
  126.         configuration.addConsoleItem(profiloInterazioneAsincronaItem);
  127.        
  128.         StringConsoleItem profiloInterazioneAsincronaItemReadOnly = (StringConsoleItem)
  129.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  130.                 ConsoleItemType.HIDDEN,
  131.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID_INUSE_READONLY,
  132.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_LABEL);
  133.         configuration.addConsoleItem(profiloInterazioneAsincronaItemReadOnly);
  134.        
  135.         StringConsoleItem profiloInterazioneAsincronaRelazioneItem = (StringConsoleItem)
  136.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  137.                 ConsoleItemType.HIDDEN,
  138.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID,
  139.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL);
  140.         profiloInterazioneAsincronaRelazioneItem.setDefaultValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_DEFAULT_VALUE);
  141.         profiloInterazioneAsincronaRelazioneItem.setReloadOnChange(true);
  142.         configuration.addConsoleItem(profiloInterazioneAsincronaRelazioneItem);
  143.        
  144.         StringConsoleItem profiloInterazioneAsincronaRelazioneItemReadOnly = (StringConsoleItem)
  145.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  146.                 ConsoleItemType.HIDDEN,
  147.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID_INUSE_READONLY,
  148.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL);
  149.         configuration.addConsoleItem(profiloInterazioneAsincronaRelazioneItemReadOnly);
  150.        
  151.         StringConsoleItem profiloInterazioneAsincronaCorrelataApiItem = (StringConsoleItem)
  152.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  153.                 ConsoleItemType.HIDDEN,
  154.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID,
  155.                 "");
  156.         profiloInterazioneAsincronaCorrelataApiItem.setDefaultValue(ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  157.         profiloInterazioneAsincronaCorrelataApiItem.setReloadOnChange(true);
  158.         configuration.addConsoleItem(profiloInterazioneAsincronaCorrelataApiItem);
  159.        
  160.         StringConsoleItem profiloInterazioneAsincronaCorrelataServizioItem = (StringConsoleItem)
  161.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  162.                 ConsoleItemType.HIDDEN,
  163.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA_ID,
  164.                 "");
  165.         profiloInterazioneAsincronaCorrelataServizioItem.setDefaultValue(ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  166.         profiloInterazioneAsincronaCorrelataServizioItem.setReloadOnChange(true);
  167.         configuration.addConsoleItem(profiloInterazioneAsincronaCorrelataServizioItem);
  168.        
  169.         StringConsoleItem profiloInterazioneAsincronaCorrelataAzioneItem = (StringConsoleItem)
  170.                 ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  171.                 ConsoleItemType.HIDDEN,
  172.                 ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA_ID,
  173.                 "");
  174.         profiloInterazioneAsincronaCorrelataAzioneItem.setDefaultValue(ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  175.         profiloInterazioneAsincronaCorrelataAzioneItem.setReloadOnChange(true);
  176.         configuration.addConsoleItem(profiloInterazioneAsincronaCorrelataAzioneItem);
  177.        
  178.     }
  179.    
  180.     private static AccordoServizioParteComune getAccordoServizioParteComune(IRegistryReader registryReader, IDAccordo idAccordoSelected) throws RegistryException{
  181.         AccordoServizioParteComune aspc = null;
  182.         try {
  183.             aspc = registryReader.getAccordoServizioParteComune(idAccordoSelected);
  184.         }catch(RegistryNotFound notFound) {
  185.             // ignore
  186.         }
  187.         return aspc;
  188.     }
  189.     private static List<IDAccordo> findIdAccordiServizioParteComune(IRegistryReader registryReader, ProtocolFiltroRicercaAccordi filtro) throws RegistryException{
  190.         List<IDAccordo> list = null;
  191.         try {
  192.             list = registryReader.findIdAccordiServizioParteComune(filtro);
  193.         }catch(RegistryNotFound notFound) {
  194.             // ignore
  195.         }
  196.         return list;
  197.     }
  198.    
  199.     static void updateProfiloInterazione(ModIProperties modiProperties,IProtocolFactory<?> protocolFactory,Logger log,
  200.             ConsoleConfiguration consoleConfiguration, ConsoleOperationType consoleOperationType, ProtocolProperties properties,
  201.             IRegistryReader registryReader, IDAccordo idAccordo, String idPortType, String idAzione, boolean rest, String httpMethod) throws ProtocolException {
  202.        
  203.         AbstractConsoleItem<?> profiloInterazioneItem =    
  204.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  205.         AbstractConsoleItem<?> profiloInterazioneAsincronaItem =    
  206.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  207.         AbstractConsoleItem<?> profiloInterazioneAsincronaRelazioneItem =  
  208.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  209.         AbstractConsoleItem<?> profiloInterazioneAsincronaCorrelataApiItem =    
  210.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID);
  211.         AbstractConsoleItem<?> profiloInterazioneAsincronaCorrelataServizioItem =  
  212.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA_ID);
  213.         AbstractConsoleItem<?> profiloInterazioneAsincronaCorrelataAzioneItem =    
  214.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA_ID);
  215.        
  216.         ModIProfiliInterazioneRESTConfig config = null;
  217.         boolean inUse = false;
  218.         if(rest) {
  219.             Resource resource = null;
  220.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  221.                 try {
  222.                     IDResource id = new IDResource();
  223.                     id.setIdAccordo(idAccordo);
  224.                     id.setNome(idAzione);
  225.                     resource = registryReader.getResourceAccordo(id);
  226.                    
  227.                     inUse = registryReader.inUso(id);
  228.                 }catch(Exception e) {
  229.                     throw new ProtocolException(e.getMessage(), e);
  230.                 }
  231.             }
  232.             config = new ModIProfiliInterazioneRESTConfig(modiProperties, httpMethod, resource);
  233.         }
  234.         else {
  235.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  236.                 try {
  237.                     IDPortType idPT = new IDPortType();
  238.                     idPT.setIdAccordo(idAccordo);
  239.                     idPT.setNome(idPortType);
  240.                    
  241.                     IDPortTypeAzione id = new IDPortTypeAzione();
  242.                     id.setIdPortType(idPT);
  243.                     id.setNome(idAzione);
  244.                    
  245.                     inUse = registryReader.inUso(id);
  246.                 }catch(Exception e) {
  247.                     throw new ProtocolException(e.getMessage(), e);
  248.                 }
  249.             }
  250.         }
  251.        
  252.         boolean addBloccante = true;
  253.         boolean addNonBloccantePush = true;
  254.         boolean addNonBloccantePull = true;
  255.         if(rest) {
  256.             addBloccante = config.isCompatibileBloccante();
  257.             addNonBloccantePush = config.isCompatibileNonBloccantePush();
  258.             addNonBloccantePull = config.isCompatibileNonBloccantePull();
  259.         }
  260.        
  261.         boolean allHidden = true;
  262.         StringProperty profiloInterazioneItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  263.         String profiloInterazione = rest ? ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_REST_VALUE : ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE;
  264.         if(profiloInterazioneItemValue!=null && profiloInterazioneItemValue.getValue()!=null && !"".equals(profiloInterazioneItemValue.getValue())) {
  265.             profiloInterazione = profiloInterazioneItemValue.getValue();
  266.         }  
  267.        
  268.         if(!addBloccante) {
  269.             profiloInterazioneItem.removeLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_BLOCCANTE);
  270.         }
  271.         if(!addNonBloccantePush && !addNonBloccantePull) {
  272.             profiloInterazioneItem.removeLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_NON_BLOCCANTE);
  273.         }
  274.        
  275.         if(
  276.                 (
  277.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE.equals(profiloInterazione)
  278.                         &&
  279.                         !addBloccante
  280.                 )
  281.                 ||
  282.                 (
  283.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(profiloInterazione)
  284.                         &&
  285.                         !addNonBloccantePush
  286.                         &&
  287.                         !addNonBloccantePull
  288.                 )
  289.         ) {
  290.             profiloInterazione = rest ? ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_REST_VALUE : ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE;
  291.         }
  292.        
  293.         if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(profiloInterazione)) {
  294.            
  295.             allHidden = false;
  296.            
  297.             profiloInterazioneAsincronaItem.setType(ConsoleItemType.SELECT);
  298.             if(addNonBloccantePush) {
  299.                 ((StringConsoleItem)profiloInterazioneAsincronaItem).addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_LABEL_PUSH,
  300.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH);
  301.             }
  302.             if(addNonBloccantePull) {
  303.                 ((StringConsoleItem)profiloInterazioneAsincronaItem).addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_LABEL_PULL,
  304.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL);
  305.             }
  306.            
  307.             StringProperty profiloInterazioneAsincronaItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  308.             String interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_DEFAULT_VALUE;
  309.             if(profiloInterazioneAsincronaItemValue!=null && profiloInterazioneAsincronaItemValue.getValue()!=null && !"".equals(profiloInterazioneAsincronaItemValue.getValue())) {
  310.                 interazioneMode = profiloInterazioneAsincronaItemValue.getValue();
  311.                 // verifico compatibilita
  312.                 if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(interazioneMode) &&
  313.                     !addNonBloccantePush) {
  314.                     interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL;
  315.                 }
  316.                 else if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL.equals(interazioneMode) &&
  317.                     !addNonBloccantePull) {
  318.                     interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH;
  319.                 }
  320.             }      
  321.             else {
  322.                 // verifico compatibilita default
  323.                 if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(interazioneMode) &&
  324.                     !addNonBloccantePush) {
  325.                     interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL;
  326.                 }
  327.                 else if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL.equals(interazioneMode) &&
  328.                     !addNonBloccantePull) {
  329.                     interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH;
  330.                 }
  331.                 if(profiloInterazioneAsincronaItemValue!=null) {
  332.                     profiloInterazioneAsincronaItemValue.setValue(interazioneMode); // imposto il default
  333.                 }
  334.             }
  335.             boolean push = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(interazioneMode);
  336.            
  337.             boolean addRichiesta = true;
  338.             boolean addRichiestaStato = true;
  339.             boolean addRisposta = true;
  340.             if(push) {
  341.                 addRichiestaStato = false;
  342.                 if(rest) {
  343.                     addRichiesta = config.isCompatibileNonBloccantePushRequest();
  344.                     addRisposta = config.isCompatibileNonBloccantePushResponse();
  345.                 }
  346.             }
  347.             else {
  348.                 if(rest) {
  349.                     addRichiesta = config.isCompatibileNonBloccantePullRequest();
  350.                     addRichiestaStato = config.isCompatibileNonBloccantePullRequestState();
  351.                     addRisposta = config.isCompatibileNonBloccantePullResponse();
  352.                 }
  353.             }
  354.            
  355.             profiloInterazioneAsincronaRelazioneItem.setType(ConsoleItemType.SELECT);
  356.             if(addRichiesta) {
  357.                 ((StringConsoleItem)profiloInterazioneAsincronaRelazioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL_RICHIESTA,
  358.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA);
  359.             }
  360.             if(addRichiestaStato) {
  361.                 ((StringConsoleItem)profiloInterazioneAsincronaRelazioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL_RICHIESTA_STATO,
  362.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA_STATO);
  363.             }
  364.             if(addRisposta) {
  365.                 ((StringConsoleItem)profiloInterazioneAsincronaRelazioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL_RISPOSTA,
  366.                         ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA);
  367.             }
  368.            
  369.             StringProperty profiloRelazioneAsincronaItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  370.             String relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_DEFAULT_VALUE;
  371.             if(profiloRelazioneAsincronaItemValue!=null && profiloRelazioneAsincronaItemValue.getValue()!=null && !"".equals(profiloRelazioneAsincronaItemValue.getValue())) {
  372.                 relazioneMode = profiloRelazioneAsincronaItemValue.getValue();
  373.             }  
  374.             if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(relazioneMode) && !addRichiesta) {
  375.                 if(addRisposta) {
  376.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA;
  377.                 }
  378.                 else if(addRichiestaStato) {
  379.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA_STATO;
  380.                 }
  381.             }
  382.             else if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA_STATO.equals(relazioneMode) && !addRichiestaStato) {
  383.                 if(addRichiesta) {
  384.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA;
  385.                 }
  386.                 else if(addRisposta) {
  387.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA;
  388.                 }
  389.             }
  390.             else if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA.equals(relazioneMode) && !addRisposta) {
  391.                 if(addRichiesta) {
  392.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA;
  393.                 }
  394.                 else if(addRichiestaStato) {
  395.                     relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA_STATO;
  396.                 }
  397.             }
  398.            
  399.             boolean request = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(relazioneMode);        
  400.             if(request) {
  401.                 profiloInterazioneAsincronaCorrelataApiItem.setType(ConsoleItemType.HIDDEN);
  402.                 profiloInterazioneAsincronaCorrelataServizioItem.setType(ConsoleItemType.HIDDEN);
  403.                 profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.HIDDEN);
  404.             }
  405.             else {
  406.                 try {
  407.                                        
  408.                     if(push) {
  409.                         // *** PUSH ***
  410.                        
  411.                         profiloInterazioneAsincronaCorrelataApiItem.setType(ConsoleItemType.SELECT);
  412.                         ((StringConsoleItem)profiloInterazioneAsincronaCorrelataApiItem).addLabelValue(ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED,ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  413.                         profiloInterazioneAsincronaCorrelataApiItem.setLabel(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_CORRELATA_A_API_LABEL);
  414.                                                
  415.                         profiloInterazioneAsincronaCorrelataServizioItem.setType(ConsoleItemType.HIDDEN);
  416.                         profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.HIDDEN);
  417.                                                
  418.                         // listo le altre API
  419.                         ProtocolFiltroRicercaAccordi filtro = new ProtocolFiltroRicercaAccordi();
  420.                         filtro.setServiceBinding(idPortType!=null ? ServiceBinding.SOAP : ServiceBinding.REST);
  421.                         filtro.setSoggetto(new IDSoggetto(protocolFactory.createProtocolConfiguration().getTipoSoggettoDefault(), null));
  422.                         List<IDAccordo> list = findIdAccordiServizioParteComune(registryReader, filtro);
  423.                         if(list!=null && !list.isEmpty()) {
  424.                             for (IDAccordo idAccordoTrovato : list) {
  425.                                 String uri = IDAccordoFactory.getInstance().getUriFromIDAccordo(idAccordoTrovato);
  426.                                 ((StringConsoleItem)profiloInterazioneAsincronaCorrelataApiItem).addLabelValue(NamingUtils.getLabelAccordoServizioParteComune(idAccordoTrovato),uri);
  427.                             }
  428.                         }
  429.                        
  430.                         StringProperty apiValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID);
  431.                         if(apiValue!=null && apiValue.getValue()!=null && !"".equals(apiValue.getValue()) &&
  432.                                 !ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(apiValue.getValue())) {
  433.                             String uriAPI = apiValue.getValue();
  434.                             IDAccordo idAccordoSelected = IDAccordoFactory.getInstance().getIDAccordoFromUri(uriAPI);
  435.                        
  436.                             // Utility
  437.                             AccordoServizioParteSpecifica asps = new AccordoServizioParteSpecifica();
  438.                             asps.setTipoSoggettoErogatore(idAccordoSelected.getSoggettoReferente().getTipo());
  439.                             asps.setNomeSoggettoErogatore(idAccordoSelected.getSoggettoReferente().getNome());
  440.                             asps.setNome(idAccordoSelected.getNome());
  441.                             asps.setVersione(idAccordoSelected.getVersione());
  442.                             AccordoServizioParteComune aspcNormale = registryReader.getAccordoServizioParteComune(idAccordoSelected,false,false);
  443.                             AccordoServizioParteComuneSintetico aspcSelected = new AccordoServizioParteComuneSintetico(aspcNormale);
  444.                             boolean addTrattinoSelezioneNonEffettuata = true;
  445.                             boolean throwException = true;
  446.                            
  447.                             AccordoServizioParteComune aspc = getAccordoServizioParteComune(registryReader, idAccordoSelected);
  448.                            
  449.                             if(idPortType!=null) {
  450.                                 // SOAP
  451.                                 profiloInterazioneAsincronaCorrelataServizioItem.setType(ConsoleItemType.SELECT);
  452.                                 ((StringConsoleItem)profiloInterazioneAsincronaCorrelataServizioItem).addLabelValue(ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED,ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  453.                                 profiloInterazioneAsincronaCorrelataServizioItem.setLabel(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_CORRELATA_A_SERVIZIO_LABEL);
  454.                                
  455.                                 if(aspc!=null && aspc.sizePortTypeList()>0) {
  456.                                     for (PortType pt : aspc.getPortTypeList()) {
  457.                                         if(pt.getNome().equals(idPortType)) {
  458.                                             continue;
  459.                                         }
  460.                                         ((StringConsoleItem)profiloInterazioneAsincronaCorrelataServizioItem).addLabelValue(pt.getNome(), pt.getNome());
  461.                                     }
  462.                                 }
  463.                                
  464.                                 StringProperty ptValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA_ID);
  465.                                 if(ptValue!=null && ptValue.getValue()!=null && !"".equals(ptValue.getValue()) &&
  466.                                         !ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(ptValue.getValue())) {
  467.                                
  468.                                     profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.SELECT);
  469.                                     ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED,ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  470.                                     profiloInterazioneAsincronaCorrelataAzioneItem.setLabel(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_CORRELATA_A_AZIONE_LABEL);
  471.                                                                        
  472.                                     asps.setPortType(ptValue.getValue());
  473.                                                                        
  474.                                     // listo le altre azioni
  475.                                     List<String> filtraAzioniUtilizzate = new ArrayList<>();
  476.                                     filtraAzioniUtilizzate.add(idAzione);
  477.                                     Map<String,String> azioni = AzioniUtils.getAzioniConLabel(asps, aspcSelected, addTrattinoSelezioneNonEffettuata, throwException,
  478.                                             filtraAzioniUtilizzate, ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED, ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED, log);
  479.                                     if(azioni!=null && !azioni.isEmpty()) {
  480.                                         for (Map.Entry<String,String> entry : azioni.entrySet()) {
  481.                                             String azioneId = entry.getKey();
  482.                                             String tmpInterazione = AzioniUtils.getProtocolPropertyStringValue(aspc, ptValue.getValue(), azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  483.                                             if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(tmpInterazione)) {
  484.                                                 continue;
  485.                                             }
  486.                                             String tmpRuolo = AzioniUtils.getProtocolPropertyStringValue(aspc, ptValue.getValue(), azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  487.                                             if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(tmpRuolo)) {
  488.                                                 continue;
  489.                                             }
  490.                                             String tmpRelazione = AzioniUtils.getProtocolPropertyStringValue(aspc, ptValue.getValue(), azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  491.                                             if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(tmpRelazione)) {
  492.                                                 continue;
  493.                                             }
  494.                                             String azioneLabel = azioni.get(azioneId);
  495.                                             ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(azioneLabel,azioneId);
  496.                                         }
  497.                                     }
  498.                                 }
  499.                             }
  500.                             else {
  501.                                 // REST
  502.                                
  503.                                 profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.SELECT);
  504.                                 ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED,ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  505.                                 profiloInterazioneAsincronaCorrelataAzioneItem.setLabel(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_CORRELATA_A_RISORSA_LABEL);
  506.                                
  507.                                 // listo le altre azioni
  508.                                 List<String> filtraAzioniUtilizzate = new ArrayList<>();
  509.                                 filtraAzioniUtilizzate.add(idAzione);
  510.                                 Map<String,String> azioni = AzioniUtils.getAzioniConLabel(asps, aspcSelected, addTrattinoSelezioneNonEffettuata, throwException,
  511.                                         filtraAzioniUtilizzate, ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED, ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED, log);
  512.                                 if(azioni!=null && !azioni.isEmpty()) {
  513.                                     for (String azioneId : azioni.keySet()) {
  514.                                         String tmpInterazione = AzioniUtils.getProtocolPropertyStringValue(aspc, null, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  515.                                         if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(tmpInterazione)) {
  516.                                             continue;
  517.                                         }
  518.                                         String tmpRuolo = AzioniUtils.getProtocolPropertyStringValue(aspc, null, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  519.                                         if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(tmpRuolo)) {
  520.                                             continue;
  521.                                         }
  522.                                         String tmpRelazione = AzioniUtils.getProtocolPropertyStringValue(aspc, null, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  523.                                         if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(tmpRelazione)) {
  524.                                             continue;
  525.                                         }
  526.                                         String azioneLabel = azioni.get(azioneId);
  527.                                         ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(azioneLabel,azioneId);
  528.                                     }
  529.                                 }
  530.                             }
  531.                         }      
  532.                     }
  533.                     else {
  534.                         // *** PULL ***
  535.                        
  536.                         profiloInterazioneAsincronaCorrelataApiItem.setType(ConsoleItemType.HIDDEN);
  537.                         profiloInterazioneAsincronaCorrelataServizioItem.setType(ConsoleItemType.HIDDEN);
  538.                        
  539.                         profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.SELECT);
  540.                         ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED,ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  541.                         profiloInterazioneAsincronaCorrelataAzioneItem.setLabel(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_CORRELATA_A_LABEL);
  542.                        
  543.                         // Utility
  544.                         AccordoServizioParteSpecifica asps = new AccordoServizioParteSpecifica();
  545.                         asps.setTipoSoggettoErogatore(idAccordo.getSoggettoReferente().getTipo());
  546.                         asps.setNomeSoggettoErogatore(idAccordo.getSoggettoReferente().getNome());
  547.                         asps.setNome(idAccordo.getNome());
  548.                         asps.setVersione(idAccordo.getVersione());
  549.                         asps.setPortType(idPortType);
  550.                         AccordoServizioParteComune aspcNormale = registryReader.getAccordoServizioParteComune(idAccordo,false,false);
  551.                         AccordoServizioParteComuneSintetico aspc = new AccordoServizioParteComuneSintetico(aspcNormale);
  552.                         boolean addTrattinoSelezioneNonEffettuata = true;
  553.                         boolean throwException = true;
  554.                        
  555.                         // listo le altre azioni
  556.                         List<String> filtraAzioniUtilizzate = new ArrayList<>();
  557.                         filtraAzioniUtilizzate.add(idAzione);
  558.                         Map<String,String> azioni = AzioniUtils.getAzioniConLabel(asps, aspc, addTrattinoSelezioneNonEffettuata, throwException,
  559.                                 filtraAzioniUtilizzate, ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED, ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED, log);
  560.                         if(azioni!=null && !azioni.isEmpty()) {
  561.                             for (String azioneId : azioni.keySet()) {
  562.                                 String tmpInterazione = AzioniUtils.getProtocolPropertyStringValue(aspcNormale, idPortType, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  563.                                 if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(tmpInterazione)) {
  564.                                     continue;
  565.                                 }
  566.                                 String tmpRuolo = AzioniUtils.getProtocolPropertyStringValue(aspcNormale, idPortType, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  567.                                 if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL.equals(tmpRuolo)) {
  568.                                     continue;
  569.                                 }
  570.                                 String tmpRelazione = AzioniUtils.getProtocolPropertyStringValue(aspcNormale, idPortType, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  571.                                 if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(tmpRelazione)) {
  572.                                     continue;
  573.                                 }
  574.                                 String azioneLabel = azioni.get(azioneId);
  575.                                 ((StringConsoleItem)profiloInterazioneAsincronaCorrelataAzioneItem).addLabelValue(azioneLabel,azioneId);
  576.                             }
  577.                         }

  578.                     }
  579.                 }catch(Exception e) {
  580.                     throw new ProtocolException(e.getMessage(),e);
  581.                 }
  582.             }
  583.         }
  584.        
  585.         if(allHidden) {
  586.             profiloInterazioneAsincronaItem.setType(ConsoleItemType.HIDDEN);
  587.             profiloInterazioneAsincronaRelazioneItem.setType(ConsoleItemType.HIDDEN);
  588.             profiloInterazioneAsincronaCorrelataApiItem.setType(ConsoleItemType.HIDDEN);
  589.             profiloInterazioneAsincronaCorrelataServizioItem.setType(ConsoleItemType.HIDDEN);
  590.             profiloInterazioneAsincronaCorrelataAzioneItem.setType(ConsoleItemType.HIDDEN);
  591.         }
  592.         else if(inUse) {
  593.            
  594.             setLabelInUse(consoleConfiguration, properties, profiloInterazioneItem,
  595.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID,
  596.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID_INUSE_READONLY);
  597.            
  598.             setLabelInUse(consoleConfiguration, properties, profiloInterazioneAsincronaItem,
  599.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID,
  600.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID_INUSE_READONLY);
  601.            
  602.             setLabelInUse(consoleConfiguration, properties, profiloInterazioneAsincronaRelazioneItem,
  603.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID,
  604.                     ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID_INUSE_READONLY);

  605.         }
  606.        
  607.     }

  608.     static void setLabelInUse(ConsoleConfiguration consoleConfiguration, ProtocolProperties properties,
  609.             AbstractConsoleItem<?> item, String id, String idReadOnly) throws ProtocolException {
  610.         if(!ConsoleItemType.HIDDEN.equals(item.getType())){
  611.            
  612.             StringProperty itemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, id);
  613.                        
  614.             item.setType(ConsoleItemType.HIDDEN);
  615.             AbstractConsoleItem<?> itemReadOnly =  
  616.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), idReadOnly);
  617.             itemReadOnly.setType(ConsoleItemType.TEXT);
  618.             String label = null;
  619.             String labelDefault = null;
  620.             if(item instanceof StringConsoleItem) {
  621.                 StringConsoleItem sci = (StringConsoleItem) item;
  622.                 SortedMap<String> map = sci.getMapLabelValues();
  623.                 if(map!=null && !map.isEmpty()) {
  624.                     for (String l : map.keys()) {
  625.                         String v = map.get(l);
  626.                         if(v!=null && v.equals(itemValue.getValue())) {
  627.                             label = l;
  628.                         }
  629.                         if(v!=null && v.equals(item.getDefaultValue())) {
  630.                             labelDefault = l;
  631.                         }
  632.                     }
  633.                 }
  634.             }

  635.             StringProperty itemValueReadOnly = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idReadOnly);
  636.             if(label!=null) {
  637.                 itemValueReadOnly.setValue(label);
  638.             }
  639.             else {
  640.                 itemValueReadOnly.setValue(labelDefault);
  641.             }
  642.         }
  643.     }
  644.        
  645.     static void validateProfiloInterazione(ProtocolProperties properties,
  646.             String idPortType, boolean rest) throws ProtocolException {
  647.    
  648.         StringProperty profiloInterazioneItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  649.         String profiloInterazione = rest ? ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_REST_VALUE : ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE;
  650.         if(profiloInterazioneItemValue!=null && profiloInterazioneItemValue.getValue()!=null && !"".equals(profiloInterazioneItemValue.getValue())) {
  651.             profiloInterazione = profiloInterazioneItemValue.getValue();
  652.         }  
  653.         if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(profiloInterazione)) {
  654.            
  655.             StringProperty profiloInterazioneAsincronaItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  656.             String interazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_DEFAULT_VALUE;
  657.             if(profiloInterazioneAsincronaItemValue!=null && profiloInterazioneAsincronaItemValue.getValue()!=null && !"".equals(profiloInterazioneAsincronaItemValue.getValue())) {
  658.                 interazioneMode = profiloInterazioneAsincronaItemValue.getValue();
  659.             }      
  660.             boolean push = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(interazioneMode);
  661.            
  662.             StringProperty profiloRelazioneAsincronaItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  663.             String relazioneMode = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_DEFAULT_VALUE;
  664.             if(profiloRelazioneAsincronaItemValue!=null && profiloRelazioneAsincronaItemValue.getValue()!=null && !"".equals(profiloRelazioneAsincronaItemValue.getValue())) {
  665.                 relazioneMode = profiloRelazioneAsincronaItemValue.getValue();
  666.             }      
  667.             boolean request = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(relazioneMode);
  668.            
  669.             if(!request) {
  670.                
  671.                 String labelRelazione = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL_RISPOSTA;
  672.                 if(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA_STATO.equals(relazioneMode)) {
  673.                     labelRelazione = ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_LABEL_RICHIESTA_STATO;  
  674.                 }
  675.                
  676.                 if(push) {
  677.                     // *** PUSH ***
  678.                    
  679.                     String prefixPushNonBloccante = "Il profilo non bloccante 'PUSH', relazione '"+labelRelazione+"'";
  680.                    
  681.                     StringProperty apiItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID);
  682.                     if(apiItemValue==null || apiItemValue.getValue()==null || "".equals(apiItemValue.getValue()) ||
  683.                             ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(apiItemValue.getValue())) {
  684.                         throw new ProtocolException(prefixPushNonBloccante+", richiede che sia perfezionata una correlazione verso una API che implementa il servizio di risposta");
  685.                     }
  686.                    
  687.                     if(idPortType!=null) {
  688.                         StringProperty ptItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA_ID);
  689.                         if(ptItemValue==null || ptItemValue.getValue()==null || "".equals(ptItemValue.getValue()) ||
  690.                                 ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(ptItemValue.getValue())) {
  691.                             throw new ProtocolException(prefixPushNonBloccante+", richiede che sia perfezionata una correlazione verso un servizio di risposta");
  692.                         }
  693.                     }
  694.                    
  695.                     StringProperty azioneItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA_ID);
  696.                     if(azioneItemValue==null || azioneItemValue.getValue()==null || "".equals(azioneItemValue.getValue()) ||
  697.                             ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(azioneItemValue.getValue())) {
  698.                         String az = null;
  699.                         if(idPortType!=null) {
  700.                             az = "un'azione";
  701.                         }
  702.                         else {
  703.                             az = "una risorsa";
  704.                         }
  705.                         throw new ProtocolException(prefixPushNonBloccante+", richiede che sia perfezionata una correlazione verso "+az+" con relazione 'Richiesta'");
  706.                     }
  707.                 }
  708.                 else {
  709.                     // *** PULL ***
  710.                     StringProperty azioneItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA_ID);
  711.                     if(azioneItemValue==null || azioneItemValue.getValue()==null || "".equals(azioneItemValue.getValue()) ||
  712.                             ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(azioneItemValue.getValue())) {
  713.                         String az = null;
  714.                         if(idPortType!=null) {
  715.                             az = "un'azione";
  716.                         }
  717.                         else {
  718.                             az = "una risorsa";
  719.                         }
  720.                         throw new ProtocolException("Il profilo non bloccante 'PULL', relazione '"+labelRelazione+"', richiede che sia perfezionata una correlazione verso "+az+" con relazione 'Richiesta'");
  721.                     }
  722.                 }
  723.                
  724.             }
  725.         }
  726.        
  727.     }
  728.    
  729.     static void updateProfiloSicurezzaCanale(ConsoleConfiguration consoleConfiguration, ProtocolProperties properties) {
  730.                
  731.         AbstractConsoleItem<?> profiloSicurezzaCanaleItem =    
  732.                 ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_ID);
  733.         StringProperty sicurezzaCanaleItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_ID);
  734.        
  735.         String value = sicurezzaCanaleItemValue!=null ? sicurezzaCanaleItemValue.getValue() : null;
  736.         if(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC01.equals(value)) {
  737.             profiloSicurezzaCanaleItem.setNote(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC01_NOTE);
  738.         }
  739.         else if(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC02.equals(value)) {
  740.             profiloSicurezzaCanaleItem.setNote(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC02_NOTE);
  741.         }

  742.     }
  743.    
  744.     private static boolean permettiModificaNomeAccordo = true;
  745.     public static boolean isPermettiModificaNomeAccordo() {
  746.         return permettiModificaNomeAccordo;
  747.     }
  748.     public static void setPermettiModificaNomeAccordo(boolean permettiModificaNomeAccordo) {
  749.         ModIDynamicConfigurationAccordiParteComuneUtilities.permettiModificaNomeAccordo = permettiModificaNomeAccordo;
  750.     }

  751.     private static int valueOfVersione(String versioneS) {
  752.         int versione = -1;
  753.         try {
  754.             versione = Integer.valueOf(versioneS);
  755.         }catch(Exception e) {
  756.             // ignore
  757.         }
  758.         return versione;
  759.     }
  760.    
  761.     private static List<IDResource> findIdResourceAccordo(IRegistryReader registryReader,ProtocolFiltroRicercaRisorse filtro) throws RegistryException {
  762.         List<IDResource> list = null;
  763.         try {
  764.             list = registryReader.findIdResourceAccordo(filtro);
  765.         }catch(RegistryNotFound notFound) {
  766.             // ignore
  767.         }
  768.         return list;
  769.     }
  770.     private static List<IDPortTypeAzione> findIdAzionePortType(IRegistryReader registryReader,ProtocolFiltroRicercaPortTypeAzioni filtro) throws RegistryException {
  771.         List<IDPortTypeAzione> list = null;
  772.         try {
  773.             list = registryReader.findIdAzionePortType(filtro);
  774.         }catch(RegistryNotFound notFound) {
  775.             // ignore
  776.         }
  777.         return list;
  778.     }
  779.    
  780.     static void validateDynamicConfigAccordoServizioParteComune(ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper, ProtocolProperties properties,
  781.             IRegistryReader registryReader, IDAccordo id) throws ProtocolException{
  782.        
  783.         boolean rest = isApiRest(consoleOperationType, consoleHelper, registryReader, id);
  784.        
  785.         // Lascio il codice se servisse, ma è stato aggiunto la gestione sull'update dell'API
  786.         if(!permettiModificaNomeAccordo && ConsoleOperationType.CHANGE.equals(consoleOperationType) && id!=null) {
  787.             try {
  788.                 String apiGestioneParziale = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APC_API_GESTIONE_PARZIALE);
  789.                 if(Costanti.CONSOLE_VALORE_PARAMETRO_APC_API_INFORMAZIONI_GENERALI.equals(apiGestioneParziale)) {
  790.                     String nome = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APC_NOME);
  791.                     String versioneS = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APC_VERSIONE);
  792.                     int versione = valueOfVersione(versioneS);
  793.                     if(nome!=null && versione>0 &&
  794.                         (!id.getNome().equals(nome) || id.getVersione().intValue()!=versione)
  795.                         ) {
  796.                            
  797.                         AccordoServizioParteComune as = registryReader.getAccordoServizioParteComune(id);
  798.                         if(ServiceBinding.REST.equals(as.getServiceBinding())){
  799.                            
  800.                             ProtocolFiltroRicercaRisorse filtro = new ProtocolFiltroRicercaRisorse();
  801.                             ProtocolProperties protocolPropertiesResources = new ProtocolProperties();
  802.                             protocolPropertiesResources.addProperty(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID, IDAccordoFactory.getInstance().getUriFromIDAccordo(id));
  803.                             filtro.setProtocolPropertiesRisorsa(protocolPropertiesResources);
  804.                             List<IDResource> list = findIdResourceAccordo(registryReader, filtro);
  805.                             if(list!=null && !list.isEmpty()) {
  806.                                 // ne dovrebbe esistere solo una.
  807.                                 IDResource idR = list.get(0);
  808.                                 String uriAPI = NamingUtils.getLabelAccordoServizioParteComune(idR.getIdAccordo());
  809.                                 Resource resource = registryReader.getResourceAccordo(idR);
  810.                                 String labelR = NamingUtils.getLabelResource(resource);
  811.                                 throw new ProtocolException("Non è possibile modificare le informazioni generali dell'API poichè riferita dalla risorsa '"+labelR+"' dell'API '"+uriAPI+"' (Profilo non bloccante PUSH)");
  812.                             }
  813.                            
  814.                         }
  815.                         else {
  816.                        
  817.                             ProtocolFiltroRicercaPortTypeAzioni filtro = new ProtocolFiltroRicercaPortTypeAzioni();
  818.                             ProtocolProperties protocolPropertiesAzioni = new ProtocolProperties();
  819.                             protocolPropertiesAzioni.addProperty(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA_ID, IDAccordoFactory.getInstance().getUriFromIDAccordo(id));
  820.                             filtro.setProtocolPropertiesAzione(protocolPropertiesAzioni);
  821.                             List<IDPortTypeAzione> list = findIdAzionePortType(registryReader,filtro);
  822.                             if(list!=null && !list.isEmpty()) {
  823.                                 // ne dovrebbe esistere solo una.
  824.                                 IDPortTypeAzione idA = list.get(0);
  825.                                 String uriAPI = NamingUtils.getLabelAccordoServizioParteComune(idA.getIdPortType().getIdAccordo());
  826.                                 throw new ProtocolException("Non è possibile modificare le informazioni generali dell'API poichè riferita dall'azione '"+idA.getNome()+"' del Servizio '"+idA.getIdPortType().getNome()+"' nell'API '"+uriAPI+"' (Profilo non bloccante PUSH)");
  827.                             }
  828.                            
  829.                         }
  830.                     }
  831.                 }
  832.             }catch(Exception e) {
  833.                 throw new ProtocolException(e.getMessage(),e);
  834.             }
  835.            
  836.         }
  837.        
  838.         ModIDynamicConfigurationAccordiParteComuneSicurezzaMessaggioUtilities.validateProfiloSicurezzaMessaggio(properties, rest);
  839.     }
  840.    
  841.     static boolean isApiRest(ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper,
  842.             IRegistryReader registryReader, IDAccordo id) throws ProtocolException {
  843.         boolean rest = true;
  844.         AccordoServizioParteComune aspc = null;
  845.         if(ConsoleOperationType.CHANGE.equals(consoleOperationType) && id!=null) {
  846.             try {
  847.                 aspc = registryReader.getAccordoServizioParteComune(id, false, false);
  848.             }catch(RegistryNotFound notFound) {
  849.                 // ignore
  850.             }
  851.             catch(Exception e) {
  852.                 throw new ProtocolException(e.getMessage(),e);
  853.             }
  854.         }
  855.         if(aspc!=null) {
  856.             rest = ServiceBinding.REST.equals(aspc.getServiceBinding());
  857.         }
  858.         else {
  859.             try {
  860.                 String serviceBinding = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SERVICE_BINDING);
  861.                 rest = !ServiceBinding.SOAP.name().equals(serviceBinding);
  862.             }catch(Exception e) {
  863.                 throw new ProtocolException(e.getMessage(),e);
  864.             }
  865.         }
  866.         return rest;
  867.     }
  868.    
  869.     private static IDAccordo idAccordoSignalHubPushAPI = null;
  870.     public static IDAccordo getIdAccordoSignalHubPush(IRegistryReader registryReader, ModIProperties modiProperties) throws RegistryNotFound, RegistryException, DriverRegistroServiziException, ProtocolException {
  871.         if(idAccordoSignalHubPushAPI==null) {
  872.             initIdAccordoSignalHubPush(registryReader, modiProperties);
  873.         }
  874.         return idAccordoSignalHubPushAPI;
  875.     }
  876.     private static synchronized void initIdAccordoSignalHubPush(IRegistryReader registryReader, ModIProperties modiProperties) throws RegistryNotFound, RegistryException, DriverRegistroServiziException, ProtocolException {
  877.         if(idAccordoSignalHubPushAPI==null) {
  878.             IDSoggetto idSoggetto = registryReader.getIdSoggettoDefault(Costanti.MODIPA_PROTOCOL_NAME);
  879.             idAccordoSignalHubPushAPI = IDAccordoFactory.getInstance().getIDAccordoFromValues(modiProperties.getSignalHubApiName(), idSoggetto, modiProperties.getSignalHubApiVersion());
  880.         }
  881.     }
  882.    
  883.     public static boolean isApiSignalHubPushAPI(IDAccordo idAccordo, IRegistryReader registryReader,
  884.             ModIProperties modiProperties, Logger log) {
  885.         if(idAccordo!=null) {
  886.             // è un accordo built-in che si assume esista
  887.             IDAccordo idAccordoSignalHubPushAPIreaded = null;
  888.             try {
  889.                 idAccordoSignalHubPushAPIreaded = ModIDynamicConfigurationAccordiParteComuneUtilities.getIdAccordoSignalHubPush(registryReader, modiProperties);
  890.             }catch(Exception e) {
  891.                 log.error("Lettura id accordo signalhub api push fallita: "+e.getMessage(),e);
  892.             }
  893.             return idAccordoSignalHubPushAPIreaded!=null && idAccordoSignalHubPushAPIreaded.equals(idAccordo);
  894.         }
  895.         return false;
  896.     }
  897. }