PorteDelegateChange.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.pd;

  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.Collections;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;

  27. import javax.servlet.http.HttpServletRequest;
  28. import javax.servlet.http.HttpServletResponse;
  29. import javax.servlet.http.HttpSession;

  30. import org.apache.commons.lang.StringUtils;
  31. import org.apache.struts.action.Action;
  32. import org.apache.struts.action.ActionForm;
  33. import org.apache.struts.action.ActionForward;
  34. import org.apache.struts.action.ActionMapping;
  35. import org.openspcoop2.core.commons.Filtri;
  36. import org.openspcoop2.core.commons.Liste;
  37. import org.openspcoop2.core.config.CorrelazioneApplicativa;
  38. import org.openspcoop2.core.config.PortaDelegata;
  39. import org.openspcoop2.core.config.PortaDelegataAzione;
  40. import org.openspcoop2.core.config.PortaDelegataLocalForward;
  41. import org.openspcoop2.core.config.PortaDelegataServizio;
  42. import org.openspcoop2.core.config.PortaDelegataSoggettoErogatore;
  43. import org.openspcoop2.core.config.Proprieta;
  44. import org.openspcoop2.core.config.ValidazioneContenutiApplicativi;
  45. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  46. import org.openspcoop2.core.config.constants.MTOMProcessorType;
  47. import org.openspcoop2.core.config.constants.PortaDelegataAzioneIdentificazione;
  48. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  49. import org.openspcoop2.core.config.constants.StatoFunzionalitaConWarning;
  50. import org.openspcoop2.core.config.constants.TipoAutenticazione;
  51. import org.openspcoop2.core.config.constants.TipoAutenticazionePrincipal;
  52. import org.openspcoop2.core.config.constants.TipoAutorizzazione;
  53. import org.openspcoop2.core.id.IDAccordo;
  54. import org.openspcoop2.core.id.IDPortaDelegata;
  55. import org.openspcoop2.core.id.IDServizio;
  56. import org.openspcoop2.core.id.IDSoggetto;
  57. import org.openspcoop2.core.mapping.MappingFruizionePortaDelegata;
  58. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  59. import org.openspcoop2.core.registry.Fruitore;
  60. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  61. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  62. import org.openspcoop2.core.registry.driver.FiltroRicercaServizi;
  63. import org.openspcoop2.core.registry.driver.FiltroRicercaSoggetti;
  64. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  65. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  66. import org.openspcoop2.core.transazioni.utils.PropertiesSerializator;
  67. import org.openspcoop2.message.constants.ServiceBinding;
  68. import org.openspcoop2.pdd.core.CostantiPdD;
  69. import org.openspcoop2.pdd.core.autorizzazione.CostantiAutorizzazione;
  70. import org.openspcoop2.pdd.core.controllo_traffico.policy.config.PolicyConfiguration;
  71. import org.openspcoop2.pdd.core.integrazione.GruppoIntegrazione;
  72. import org.openspcoop2.pdd.core.integrazione.TipoIntegrazione;
  73. import org.openspcoop2.protocol.basic.config.SubscriptionConfiguration;
  74. import org.openspcoop2.utils.date.DateManager;
  75. import org.openspcoop2.utils.transport.TransportUtils;
  76. import org.openspcoop2.web.ctrlstat.core.AutorizzazioneUtilities;
  77. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  78. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  79. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  80. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  81. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  82. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  83. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  84. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCostanti;
  85. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaHelper;
  86. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniCostanti;
  87. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniHelper;
  88. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  89. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCostanti;
  90. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  91. import org.openspcoop2.web.lib.mvc.Costanti;
  92. import org.openspcoop2.web.lib.mvc.DataElement;
  93. import org.openspcoop2.web.lib.mvc.ForwardParams;
  94. import org.openspcoop2.web.lib.mvc.GeneralData;
  95. import org.openspcoop2.web.lib.mvc.PageData;
  96. import org.openspcoop2.web.lib.mvc.Parameter;
  97. import org.openspcoop2.web.lib.mvc.ServletUtils;
  98. import org.openspcoop2.web.lib.mvc.TipoOperazione;
  99. import org.openspcoop2.web.lib.users.dao.PermessiUtente;

  100. /**
  101.  * porteDelegateChange
  102.  *
  103.  * @author Andrea Poli (apoli@link.it)
  104.  * @author Stefano Corallo (corallo@link.it)
  105.  * @author Sandra Giangrandi (sandra@link.it)
  106.  * @author $Author$
  107.  * @version $Rev$, $Date$
  108.  *
  109.  */
  110. public final class PorteDelegateChange extends Action {

  111.     @Override
  112.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  113.         HttpSession session = request.getSession(true);

  114.         // Inizializzo PageData
  115.         PageData pd = new PageData();

  116.         GeneralHelper generalHelper = new GeneralHelper(session);

  117.         // Inizializzo GeneralData
  118.         GeneralData gd = generalHelper.initGeneralData(request);

  119.         try {
  120.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  121.             Boolean vistaErogazioni = ServletUtils.getBooleanAttributeFromSession(ErogazioniCostanti.ASPS_EROGAZIONI_ATTRIBUTO_VISTA_EROGAZIONI, session, request).getValue();
  122.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  123.             String nomePorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA);
  124.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  125.             int soggInt = Integer.parseInt(idsogg);
  126.             String descr = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_DESCRIZIONE);
  127.             String statoPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_STATO_PORTA);
  128.             String tipoSoggettoErogatore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SP);
  129.             String nomeSoggettoErogatore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SP);
  130.             String idSoggettoErogatore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SOGGETTO_ID);
  131.             String tiposervizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SERVIZIO);
  132.             String servizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO);
  133.             String versioneServizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VERSIONE_SERVIZIO);
  134.             String servid = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO_ID);
  135.             String modeaz = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_AZIONE);
  136.             String azione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AZIONE);
  137.             String azid = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AZIONE_ID);
  138.             String stateless = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_STATELESS);
  139.             String localForward = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD );
  140.             String paLocalForward = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD_PA);
  141.             String gestBody = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_BODY);
  142.             String gestManifest = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_MANIFEST);
  143.             String ricsim = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_SIMMETRICA);
  144.             String ricasim = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_ASIMMETRICA);
  145.             String scadcorr = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SCADENZA_CORRELAZIONE_APPLICATIVA);
  146.             String forceWsdlBased = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_FORCE_INTERFACE_BASED);

  147.             String messageEngine = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_MESSAGE_ENGINE);
  148.                        
  149.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  150.             if(idAsps == null)
  151.                 idAsps = "";
  152.            
  153.             BinaryParameter allegatoXacmlPolicy = porteDelegateHelper.getBinaryParameter(CostantiControlStation.PARAMETRO_DOCUMENTO_SICUREZZA_XACML_POLICY);
  154.            
  155.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  156.             if(idFruizione == null)
  157.                 idFruizione = "";
  158.            
  159.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  160.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  161.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  162.             }
  163.            
  164.             String serviceBindingS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVICE_BINDING);
  165.             ServiceBinding serviceBinding = null;
  166.             if(StringUtils.isNotEmpty(serviceBindingS))
  167.                 serviceBinding = ServiceBinding.valueOf(serviceBindingS);
  168.            
  169.             boolean datiInvocazione = ServletUtils.isCheckBoxEnabled(porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONFIGURAZIONE_DATI_INVOCAZIONE));
  170.             boolean modificaDescrizione = ServletUtils.isCheckBoxEnabled(porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONFIGURAZIONE_DESCRIZIONE));
  171.             boolean datiAltroPorta = ServletUtils.isCheckBoxEnabled(porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONFIGURAZIONE_ALTRO_PORTA));
  172.             boolean datiAltroApi = ServletUtils.isCheckBoxEnabled(porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONFIGURAZIONE_ALTRO_API));
  173.            
  174.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  175.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  176.             if(parentPD == null) {
  177.                 if(datiInvocazione) {
  178.                     parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE;
  179.                     ServletUtils.setObjectIntoSession(request, session, PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE, PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT);
  180.                 }
  181.                 else {
  182.                     parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  183.                 }
  184.             }

  185.             // check su oldNomePD
  186.             PageData pdOld =  ServletUtils.getPageDataFromSession(request, session);
  187.             String oldNomePD = pdOld.getHidden(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OLD_NOME_PD);
  188.             oldNomePD = (((oldNomePD != null) && !oldNomePD.equals("")) ? oldNomePD : nomePorta);
  189.             // Preparo il menu
  190.             porteDelegateHelper.makeMenu();

  191.             String postBackElementName = porteDelegateHelper.getPostBackElementName();
  192.             if(postBackElementName!=null && PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_AZIONE.equals(postBackElementName)) {
  193.                 // ho cambiato modalita', elimino il valore
  194.                 azione = null;
  195.             }
  196.            
  197.             // Prendo nome e tipo del soggetto
  198.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  199.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  200.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  201.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);

  202.            
  203.             IDSoggetto idSoggettoFruitore = null;
  204.             if(porteDelegateCore.isRegistroServiziLocale()){
  205.                 org.openspcoop2.core.registry.Soggetto soggetto = soggettiCore.getSoggettoRegistro(soggInt);
  206.                 idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
  207.             }else{
  208.                 org.openspcoop2.core.config.Soggetto soggetto = soggettiCore.getSoggetto(soggInt);
  209.                 idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
  210.             }

  211.             boolean usataInConfigurazioni = false;
  212.             boolean usataInConfigurazioneDefault = false;
  213.             boolean addTrattinoSelezioneNonEffettuata = false;
  214.            
  215.             String integrazioneStato = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_INTEGRAZIONE_STATO);
  216.             String integrazione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_INTEGRAZIONE);
  217.             String[] integrazioneGruppi = porteDelegateHelper.getParameterValues(CostantiControlStation.PARAMETRO_PORTE_METADATI_GRUPPO);
  218.        
  219.             List<GruppoIntegrazione> integrazioneGruppiDaVisualizzare = new ArrayList<>();  
  220.             Map<String, List<String>> integrazioneGruppiValoriDeiGruppi = new HashMap<>();
  221.             boolean isConfigurazione = false;
  222.             if(parentPD!=null) {
  223.                 isConfigurazione = (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE);
  224.             }
  225.             boolean visualizzaSezioneOpzioniAvanzate = !(porteDelegateHelper.isModalitaStandard() || (isConfigurazione && !datiAltroPorta));

  226.             // dal secondo accesso in poi il calcolo dei gruppi da visualizzare avviene leggendo i parametri dalla richiesta
  227.             if(integrazioneStato != null && visualizzaSezioneOpzioniAvanzate &&
  228.                 integrazioneStato.equals(CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_RIDEFINITO) &&
  229.                     integrazioneGruppi != null) {
  230.                 for (String gruppoSelezionato : integrazioneGruppi) {
  231.                     integrazioneGruppiDaVisualizzare.add(GruppoIntegrazione.toEnumConstant(gruppoSelezionato));
  232.                 }
  233.                
  234.                 // leggere i valori selezionati per ogni gruppo selezionato
  235.                 for (GruppoIntegrazione group : integrazioneGruppiDaVisualizzare) {
  236.                     List<String> valoriGruppoList = new ArrayList<>();
  237.                     if(group.isMulti()) {
  238.                         String[] valoriGruppo = porteDelegateHelper.getParameterValues(CostantiControlStation.PARAMETRO_PORTE_METADATI_GRUPPO_SINGOLO+group.getValue());
  239.                         if(valoriGruppo != null) {
  240.                             valoriGruppoList.addAll(Arrays.asList(valoriGruppo));
  241.                         }
  242.                     } else {
  243.                         String valoreGruppo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_METADATI_GRUPPO_SINGOLO+group.getValue());
  244.                         if(valoreGruppo != null) {
  245.                             valoriGruppoList.add(valoreGruppo);
  246.                         }
  247.                     }
  248.                    
  249.                     integrazioneGruppiValoriDeiGruppi.put(group.getValue(), valoriGruppoList);                          
  250.                 }
  251.             }
  252.            
  253.             // RateLimiting
  254.             String ctModalitaSincronizzazione = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_SINCRONIZZAZIONE);
  255.             String ctImplementazione = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_IMPLEMENTAZIONE);
  256.             String ctContatori = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_CONTATORI);
  257.             String ctTipologia = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_TIPOLOGIA);
  258.             String ctHeaderHttp = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP);
  259.             String ctHeaderHttpLimit = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_LIMIT);
  260.             String ctHeaderHttpRemaining = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_REMAINING);
  261.             String ctHeaderHttpReset = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RESET);
  262.             String ctHeaderHttpRetryAfter = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER);
  263.             String ctHeaderHttpRetryAfterBackoff = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER_BACKOFF_SECONDS);

  264.            
  265.             // Prendo la porta delegata
  266.             IDPortaDelegata idpd = new IDPortaDelegata();
  267.             idpd.setNome(oldNomePD);
  268.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idpd);
  269.            
  270.             Long idAspsLong;
  271.             if(idAsps.equals("")) {
  272.                 PortaDelegataServizio servizio2 = pde.getServizio();
  273.                 idAspsLong = servizio2.getId();
  274.             } else {
  275.                 idAspsLong = Long.parseLong(idAsps);
  276.             }
  277.            
  278.             // controllo se la porta e' usata in qualche configurazione e se e' usata nella configurazione di default
  279.             MappingFruizionePortaDelegata mappingFruizione = new MappingFruizionePortaDelegata();
  280.             mappingFruizione.setIdFruitore(idSoggettoFruitore);
  281.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idAspsLong);
  282.             IDServizio idServizioCheck = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
  283.             mappingFruizione.setIdServizio(idServizioCheck);
  284.             mappingFruizione.setIdPortaDelegata(idpd );
  285.             usataInConfigurazioni = porteDelegateCore.existsMappingFruizionePortaDelegata(mappingFruizione);
  286.            
  287.             IDPortaDelegata idPortaDelegataAssociataDefault = porteDelegateCore.getIDPortaDelegataAssociataDefault(idServizioCheck, idSoggettoFruitore);
  288.             usataInConfigurazioneDefault = (idPortaDelegataAssociataDefault != null && idPortaDelegataAssociataDefault.getNome().equals(idpd.getNome()));
  289.            
  290.             // Prendo il numero di correlazioni applicative
  291.             CorrelazioneApplicativa ca = pde.getCorrelazioneApplicativa();
  292.             int numCorrApp = 0;
  293.             if (ca != null) {
  294.                 numCorrApp = ca.sizeElementoList();
  295.             }

  296.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(idSoggettoFruitore.getTipo());
  297.             List<String> tipiSoggettiCompatibiliAccordo = soggettiCore.getTipiSoggettiGestitiProtocollo(protocollo);

  298.             // Informazioni sul numero di ServiziApplicativi, Correlazione Applicativa e stato Message-Security
  299.             int numSA =pde.sizeServizioApplicativoList();
  300.             int numRuoli = 0;
  301.             if(pde.getRuoli()!=null){
  302.                 numRuoli = pde.getRuoli().sizeRuoloList();
  303.             }
  304.             int numScope = 0;
  305.             if(pde.getScope()!=null){
  306.                 numScope = pde.getScope().sizeScopeList();
  307.             }
  308.            
  309.             int numAutenticatiToken = 0;
  310.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getServiziApplicativi()!=null){
  311.                 numAutenticatiToken = pde.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList();
  312.             }
  313.            
  314.             int numRuoliToken = 0;
  315.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getRuoli()!=null){
  316.                 numRuoliToken = pde.getAutorizzazioneToken().getRuoli().sizeRuoloList();
  317.             }
  318.            
  319.             String statoMessageSecurity  = pde.getStatoMessageSecurity() ;

  320.             // Stato MTOM
  321.             boolean isMTOMAbilitatoReq = false;
  322.             boolean isMTOMAbilitatoRes= false;
  323.             if(pde.getMtomProcessor()!= null){
  324.                 if(pde.getMtomProcessor().getRequestFlow() != null &&
  325.                     pde.getMtomProcessor().getRequestFlow().getMode() != null){
  326.                     MTOMProcessorType mode = pde.getMtomProcessor().getRequestFlow().getMode();
  327.                     if(!mode.equals(MTOMProcessorType.DISABLE))
  328.                         isMTOMAbilitatoReq = true;
  329.                 }

  330.                 if(pde.getMtomProcessor().getResponseFlow() != null &&
  331.                     pde.getMtomProcessor().getResponseFlow().getMode() != null){
  332.                     MTOMProcessorType mode = pde.getMtomProcessor().getResponseFlow().getMode();
  333.                     if(!mode.equals(MTOMProcessorType.DISABLE))
  334.                         isMTOMAbilitatoRes = true;
  335.                 }
  336.             }

  337.             String statoMessageMTOM  = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_DISABILITATO;

  338.             if(isMTOMAbilitatoReq || isMTOMAbilitatoRes)
  339.                 statoMessageMTOM  = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_ABILITATO;



  340.             int numCorrelazioneReq =0;
  341.             if(pde.getCorrelazioneApplicativa() != null)
  342.                 numCorrelazioneReq  = pde.getCorrelazioneApplicativa().sizeElementoList();

  343.             int numCorrelazioneRes =0;
  344.             if(pde.getCorrelazioneApplicativaRisposta() != null)
  345.                 numCorrelazioneRes = pde.getCorrelazioneApplicativaRisposta().sizeElementoList();

  346.             boolean riusoID = false;
  347.             if(numCorrelazioneReq>0){
  348.                 for (int i = 0; i < numCorrelazioneReq; i++) {
  349.                     if(StatoFunzionalita.ABILITATO.equals(pde.getCorrelazioneApplicativa().getElemento(i).getRiusoIdentificativo())){
  350.                         riusoID = true;
  351.                         break;
  352.                     }
  353.                 }
  354.             }
  355.            
  356.             String autenticazione = pde.getAutenticazione();
  357.             String autenticazioneCustom = null;
  358.             if (autenticazione != null &&
  359.                     !TipoAutenticazione.getValues().contains(autenticazione)) {
  360.                 autenticazioneCustom = autenticazione;
  361.                 autenticazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM;
  362.             }
  363.             String  autenticazioneOpzionale = "";
  364.             if(pde.getAutenticazioneOpzionale()!=null &&
  365.                 pde.getAutenticazioneOpzionale().equals(StatoFunzionalita.ABILITATO)) {
  366.                 autenticazioneOpzionale = Costanti.CHECK_BOX_ENABLED;
  367.             }
  368.             TipoAutenticazionePrincipal autenticazionePrincipal = porteDelegateCore.getTipoAutenticazionePrincipal(pde.getProprietaAutenticazioneList());
  369.             List<String> autenticazioneParametroList = porteDelegateCore.getParametroAutenticazione(autenticazione, pde.getProprietaAutenticazioneList());

  370.             String autorizzazione = null;
  371.             String autorizzazioneCustom = null;
  372.             String autorizzazioneAutenticati = null;
  373.             String autorizzazioneRuoli = null;
  374.             String autorizzazioneRuoliTipologia = null;
  375.             String ruoloMatch = null;
  376.             String autorizzazioneContenuti = pde.getAutorizzazioneContenuto();
  377.             String autorizzazioneContenutiProperties = null;
  378.             String autorizzazioneContenutiStato = null;
  379.            
  380.             if(autorizzazioneContenuti == null) {
  381.                 autorizzazioneContenutiStato = StatoFunzionalita.DISABILITATO.getValue();
  382.             } else if(autorizzazioneContenuti.equals(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN)) {
  383.                 autorizzazioneContenutiStato = StatoFunzionalita.ABILITATO.getValue();
  384.                 List<Proprieta> proprietaAutorizzazioneContenutoList = pde.getProprietaAutorizzazioneContenutoList();
  385.                 StringBuilder sb = new StringBuilder();
  386.                 for (Proprieta proprieta : proprietaAutorizzazioneContenutoList) {
  387.                     if(sb.length() >0)
  388.                         sb.append("\n");
  389.                    
  390.                     sb.append(proprieta.getNome()).append("=").append(proprieta.getValore());
  391.                 }                      
  392.                
  393.                 autorizzazioneContenutiProperties = sb.toString();
  394.             } else { // custom
  395.                 autorizzazioneContenutiStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_CONTROLLO_ACCESSI_AUTORIZZAZIONE_CONTENUTI_STATO_CUSTOM;
  396.             }
  397.            
  398.             if (pde.getAutorizzazione() != null &&
  399.                     !TipoAutorizzazione.getAllValues().contains(pde.getAutorizzazione())) {
  400.                 autorizzazioneCustom = pde.getAutorizzazione();
  401.                 autorizzazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM;
  402.             }
  403.             else{
  404.                 autorizzazione = AutorizzazioneUtilities.convertToStato(pde.getAutorizzazione());
  405.                 if(TipoAutorizzazione.isAuthenticationRequired(pde.getAutorizzazione()))
  406.                     autorizzazioneAutenticati = Costanti.CHECK_BOX_ENABLED;
  407.                 if(TipoAutorizzazione.isRolesRequired(pde.getAutorizzazione()))
  408.                     autorizzazioneRuoli = Costanti.CHECK_BOX_ENABLED;
  409.                 autorizzazioneRuoliTipologia = AutorizzazioneUtilities.convertToRuoloTipologia(pde.getAutorizzazione()).getValue();
  410.             }
  411.            
  412.             if(pde.getRuoli()!=null && pde.getRuoli().getMatch()!=null){
  413.                 ruoloMatch = pde.getRuoli().getMatch().getValue();
  414.             }
  415.            
  416.             String statoValidazione = null;
  417.             String tipoValidazione = null;
  418.             String applicaMTOM = "";
  419.             ValidazioneContenutiApplicativi vx = pde.getValidazioneContenutiApplicativi();
  420.             if (vx == null) {
  421.                 statoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_DISABILITATO;
  422.                 tipoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE_INTERFACE;
  423.             } else {
  424.                 if(vx.getStato()!=null)
  425.                     statoValidazione = vx.getStato().toString();
  426.                 if ((statoValidazione == null) || "".equals(statoValidazione)) {
  427.                     statoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_DISABILITATO;
  428.                 }
  429.                
  430.                 if(vx.getTipo()!=null)
  431.                     tipoValidazione = vx.getTipo().toString();
  432.                 if (tipoValidazione == null || "".equals(tipoValidazione)) {
  433.                     tipoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE_INTERFACE ;
  434.                 }
  435.                
  436.                 if(vx.getAcceptMtomMessage()!=null &&
  437.                     vx.getAcceptMtomMessage().equals(StatoFunzionalita.ABILITATO)) {
  438.                     applicaMTOM = Costanti.CHECK_BOX_ENABLED;
  439.                 }
  440.             }
  441.            
  442.             String gestioneToken = null;
  443.             String gestioneTokenPolicy = null;
  444.             String gestioneTokenOpzionale = null;
  445.             String gestioneTokenValidazioneInput = null;
  446.             String gestioneTokenIntrospection = null;
  447.             String gestioneTokenUserInfo = null;
  448.             String gestioneTokenTokenForward = null;
  449.            
  450.             String autenticazioneTokenIssuer = null;
  451.             String autenticazioneTokenClientId = null;
  452.             String autenticazioneTokenSubject = null;
  453.             String autenticazioneTokenUsername = null;
  454.             String autenticazioneTokenEMail = null;
  455.            
  456.             String autorizzazioneAutenticatiToken = null;
  457.             String autorizzazioneRuoliToken = null;
  458.             String autorizzazioneRuoliTipologiaToken = null;
  459.             String autorizzazioneRuoliMatchToken = null;
  460.            
  461.             String autorizzazioneToken = null;
  462.             String autorizzazioneTokenOptions = null;
  463.            
  464.             String identificazioneAttributiStato = null;
  465.             String [] attributeAuthoritySelezionate = null;
  466.             String attributeAuthorityAttributi = null;
  467.            
  468.             if(pde.getGestioneToken() != null) {
  469.                 gestioneTokenPolicy = pde.getGestioneToken().getPolicy();
  470.                 if(gestioneTokenPolicy == null) {
  471.                     gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  472.                     gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  473.                 } else {
  474.                     gestioneToken = StatoFunzionalita.ABILITATO.getValue();
  475.                 }
  476.                
  477.                 StatoFunzionalita tokenOpzionale = pde.getGestioneToken().getTokenOpzionale();
  478.                 if(tokenOpzionale == null) {
  479.                     gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  480.                 }else {
  481.                     gestioneTokenOpzionale = tokenOpzionale.getValue();
  482.                 }
  483.                
  484.                 StatoFunzionalitaConWarning validazione = pde.getGestioneToken().getValidazione();
  485.                 if(validazione == null) {
  486.                     gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  487.                 }else {
  488.                     gestioneTokenValidazioneInput = validazione.getValue();
  489.                 }
  490.                
  491.                 StatoFunzionalitaConWarning introspection = pde.getGestioneToken().getIntrospection();
  492.                 if(introspection == null) {
  493.                     gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  494.                 }else {
  495.                     gestioneTokenIntrospection = introspection.getValue();
  496.                 }
  497.                
  498.                 StatoFunzionalitaConWarning userinfo = pde.getGestioneToken().getUserInfo();
  499.                 if(userinfo == null) {
  500.                     gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  501.                 }else {
  502.                     gestioneTokenUserInfo = userinfo.getValue();
  503.                 }
  504.                
  505.                 StatoFunzionalita tokenForward = pde.getGestioneToken().getForward();
  506.                 if(tokenForward == null) {
  507.                     gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  508.                 }else {
  509.                     gestioneTokenTokenForward = tokenForward.getValue();
  510.                 }
  511.                
  512.                 autorizzazioneTokenOptions = pde.getGestioneToken().getOptions();
  513.                 if((autorizzazioneTokenOptions!=null && !"".equals(autorizzazioneTokenOptions))) {
  514.                     autorizzazioneToken = Costanti.CHECK_BOX_ENABLED;
  515.                 }
  516.                 else {
  517.                     autorizzazioneToken = Costanti.CHECK_BOX_DISABLED;
  518.                 }
  519.                
  520.                 if(pde.getGestioneToken().getAutenticazione() != null) {
  521.                    
  522.                     StatoFunzionalita issuer = pde.getGestioneToken().getAutenticazione().getIssuer();
  523.                     if(issuer == null) {
  524.                         autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  525.                     }else {
  526.                         autenticazioneTokenIssuer = issuer.getValue();
  527.                     }
  528.                    
  529.                     StatoFunzionalita clientId = pde.getGestioneToken().getAutenticazione().getClientId();
  530.                     if(clientId == null) {
  531.                         autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  532.                     }else {
  533.                         autenticazioneTokenClientId = clientId.getValue();
  534.                     }
  535.                    
  536.                     StatoFunzionalita subject = pde.getGestioneToken().getAutenticazione().getSubject();
  537.                     if(subject == null) {
  538.                         autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  539.                     }else {
  540.                         autenticazioneTokenSubject = subject.getValue();
  541.                     }
  542.                    
  543.                     StatoFunzionalita username = pde.getGestioneToken().getAutenticazione().getUsername();
  544.                     if(username == null) {
  545.                         autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  546.                     }else {
  547.                         autenticazioneTokenUsername = username.getValue();
  548.                     }
  549.                    
  550.                     StatoFunzionalita mailTmp = pde.getGestioneToken().getAutenticazione().getEmail();
  551.                     if(mailTmp == null) {
  552.                         autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  553.                     }else {
  554.                         autenticazioneTokenEMail = mailTmp.getValue();
  555.                     }
  556.                    
  557.                 }
  558.                 else {
  559.                     autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  560.                     autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  561.                     autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  562.                     autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  563.                     autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  564.                 }
  565.             }
  566.             else {
  567.                 gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  568.                 gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  569.                 gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  570.                
  571.                 gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  572.                 gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  573.                 gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  574.                 gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  575.                
  576.                 autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  577.                 autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  578.                 autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  579.                 autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  580.                 autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  581.             }
  582.            
  583.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null) {
  584.                 autorizzazioneAutenticatiToken = StatoFunzionalita.ABILITATO.equals(pde.getAutorizzazioneToken().getAutorizzazioneApplicativi()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  585.             }
  586.            
  587.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null) {
  588.                 autorizzazioneRuoliToken = StatoFunzionalita.ABILITATO.equals(pde.getAutorizzazioneToken().getAutorizzazioneRuoli()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  589.             }
  590.            
  591.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getTipologiaRuoli()!=null) {
  592.                 autorizzazioneRuoliTipologiaToken = pde.getAutorizzazioneToken().getTipologiaRuoli().getValue();
  593.             }
  594.            
  595.             if(pde.getAutorizzazioneToken()!=null && pde.getAutorizzazioneToken().getRuoli()!=null && pde.getAutorizzazioneToken().getRuoli().getMatch()!=null){
  596.                 autorizzazioneRuoliMatchToken = pde.getAutorizzazioneToken().getRuoli().getMatch().getValue();
  597.             }
  598.            
  599.             String autorizzazioneScope = null;
  600.             String autorizzazioneScopeMatch = null;
  601.            
  602.             if(pde.getScope() != null) {
  603.                 autorizzazioneScope =  pde.getScope().getStato().equals(StatoFunzionalita.ABILITATO) ? Costanti.CHECK_BOX_ENABLED : "";
  604.                                
  605.                 if(pde.getScope()!=null && pde.getScope().getMatch()!=null){
  606.                     autorizzazioneScopeMatch = pde.getScope().getMatch().getValue();
  607.                 }
  608.             } else {
  609.                 autorizzazioneScope = "";
  610.             }
  611.            
  612.             if(identificazioneAttributiStato==null) {
  613.                 identificazioneAttributiStato = pde.sizeAttributeAuthorityList()>0 ? StatoFunzionalita.ABILITATO.getValue() : StatoFunzionalita.DISABILITATO.getValue();
  614.                 if(pde.sizeAttributeAuthorityList()>0) {
  615.                     attributeAuthoritySelezionate = porteDelegateCore.buildAuthorityArrayString(pde.getAttributeAuthorityList());
  616.                     attributeAuthorityAttributi = porteDelegateCore.buildAttributesStringFromAuthority(pde.getAttributeAuthorityList());
  617.                 }
  618.             }
  619.            
  620.             // se ho modificato il soggetto ricalcolo il servizio e il service binding
  621.             if (postBackElementName != null) {
  622.                 if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SOGGETTO_ID)) {
  623.                     servid = null;
  624.                     serviceBinding = null;
  625.                 } else if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO_ID)) {
  626.                     serviceBinding = null;
  627.                 }
  628.             }
  629.            
  630.             List<String> tipiServizioCompatibiliAccordo = new ArrayList<>();
  631.             if(serviceBinding == null) {
  632.                 List<ServiceBinding> serviceBindingListProtocollo = apsCore.getServiceBindingListProtocollo(protocollo);
  633.                
  634.                 if(serviceBindingListProtocollo != null && !serviceBindingListProtocollo.isEmpty()) {
  635.                     for (ServiceBinding serviceBinding2 : serviceBindingListProtocollo) {
  636.                         List<String> tipiServizioCompatibiliAccordoTmp = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding2);
  637.                        
  638.                         for (String tipoTmp : tipiServizioCompatibiliAccordoTmp) {
  639.                             if(!tipiServizioCompatibiliAccordo.contains(tipoTmp))
  640.                                 tipiServizioCompatibiliAccordo.add(tipoTmp);
  641.                         }
  642.                     }
  643.                 }
  644.             } else {
  645.                 tipiServizioCompatibiliAccordo = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding);
  646.             }
  647.            
  648.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  649.            
  650.            
  651.             String nomeBreadCrumb = oldNomePD;
  652.            
  653.             if( parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  654. /**             List<MappingFruizionePortaDelegata> mappingServiziPorteAppList = apsCore.serviziFruitoriMappingList(Long.parseLong(idFruizione), idSoggettoFruitore, idServizioCheck, null);
  655. //                      
  656. //              MappingFruizionePortaDelegata mappingFruizionePortaDelegata = null;
  657. //              for (MappingFruizionePortaDelegata mappingFruizionePortaDelegataTmp : mappingServiziPorteAppList) {
  658. //                  if(mappingFruizionePortaDelegataTmp.getIdPortaDelegata().getNome().equals(oldNomePD)) {
  659. //                      mappingFruizionePortaDelegata = mappingFruizionePortaDelegataTmp;
  660. //                      break;
  661. //                  }
  662. //              }
  663. //              
  664. //              if(mappingFruizionePortaDelegata.isDefault()) {
  665. //                  nomeBreadCrumb = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MAPPING_FRUIZIONE_PD_NOME_DEFAULT;
  666. //              } else {
  667. //                  nomeBreadCrumb = mappingFruizionePortaDelegata.getNome();
  668. //              } */
  669.                
  670.                 if(datiInvocazione) {
  671.                     lstParam.remove(lstParam.size()-1);
  672.                     if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  673.                         lstParam.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_PORTE_DELEGATE_MODIFICA_DATI_INVOCAZIONE,null));
  674.                     } else {
  675.                         lstParam.add(new Parameter(AccordiServizioParteSpecificaCostanti.LABEL_APS_DATI_INVOCAZIONE_DI + porteDelegateHelper.getLabelIdServizio(asps),null));
  676.                     }
  677.                     nomeBreadCrumb=null;
  678.                 }
  679.                 else if(modificaDescrizione) {
  680.                     String labelPerPorta = null;
  681.                     if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  682.                         labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  683.                                 PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_DESCRIZIONE_DI,
  684.                                 PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_DESCRIZIONE,
  685.                                 pde);
  686.                     }
  687.                     else {
  688.                         lstParam.remove(lstParam.size()-1);
  689.                         labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_DESCRIZIONE_DI+pde.getNome();
  690.                     }              
  691.                     lstParam.add(new Parameter(labelPerPorta,  null));
  692.                     nomeBreadCrumb=null;
  693.                 }
  694.                 else if(datiAltroPorta) {
  695.                     String labelPerPorta = null;
  696.                     if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  697.                         labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  698.                                 PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_OPZIONI_AVANZATE_DI,
  699.                                 PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_OPZIONI_AVANZATE,
  700.                                 pde);
  701.                     }
  702.                     else {
  703.                         lstParam.remove(lstParam.size()-1);
  704.                         labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_OPZIONI_AVANZATE_DI+pde.getNome();
  705.                     }              
  706.                     lstParam.add(new Parameter(labelPerPorta,  null));
  707.                     nomeBreadCrumb=null;
  708.                 }
  709.                 else if(datiAltroApi) {
  710.                     lstParam.remove(lstParam.size()-1);
  711.                     if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  712.                         lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_OPZIONI_AVANZATE,null));
  713.                     } else {
  714.                         lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_OPZIONI_AVANZATE_DI + porteDelegateHelper.getLabelIdServizio(asps),null));
  715.                     }
  716.                     nomeBreadCrumb=null;
  717.                 }
  718.                 else {
  719.                     nomeBreadCrumb = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(null,null,pde);
  720.                 }
  721.             }
  722.            
  723.             if(nomeBreadCrumb!=null) {
  724.                 lstParam.add(new Parameter(nomeBreadCrumb , null));
  725.             }

  726.             // Se idhid = null, devo visualizzare la pagina per la
  727.             // modifica dati
  728.             if (porteDelegateHelper.isEditModeInProgress()) {
  729.                 // setto la barra del titolo
  730.                 ServletUtils.setPageDataTitle(pd, lstParam);

  731.                 String patternErogatore = nomeSoggettoErogatore;
  732.                 String patternServizio = servizio;
  733.                 String patternAzione = azione;

  734.                 if (descr == null) {
  735.                     descr = pde.getDescrizione();
  736.                 }
  737.                
  738.                 if(idSoggettoErogatore == null) {
  739.                     PortaDelegataSoggettoErogatore pdsse = pde.getSoggettoErogatore();
  740.                     tipoSoggettoErogatore = pdsse.getTipo();
  741.                     nomeSoggettoErogatore = pdsse.getNome();
  742.                     idSoggettoErogatore = tipoSoggettoErogatore + "/" + nomeSoggettoErogatore;
  743.                 }
  744.                
  745.                 if(servid == null) {
  746.                     PortaDelegataServizio pds = pde.getServizio();
  747.                     tiposervizio = pds.getTipo();
  748.                     servizio = pds.getNome();
  749.                     servid = pds.getTipo() + "/" + pds.getNome() + "/" + pds.getVersione().intValue();
  750.                 }
  751.                
  752.                 if (statoPorta == null) {
  753.                     statoPorta = pde.getStato()!=null ? pde.getStato().getValue() : CostantiConfigurazione.ABILITATO.getValue();
  754.                 }
  755.                 if (stateless == null &&
  756.                     pde.getStateless()!=null){
  757.                     stateless = pde.getStateless().toString();
  758.                 }
  759.                 if (localForward == null) {
  760.                     if(pde.getLocalForward()!=null && pde.getLocalForward().getStato()!=null){
  761.                         localForward = pde.getLocalForward().getStato().toString();
  762.                     }
  763.                     if (localForward == null) {
  764.                         localForward = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD_DISABILITATO;
  765.                     }
  766.                     if(pde.getLocalForward()!=null && pde.getLocalForward().getPortaApplicativa()!=null) {
  767.                         paLocalForward = pde.getLocalForward().getPortaApplicativa();
  768.                     }
  769.                 }
  770.                 if (gestBody == null) {
  771.                     String allegaBody = null;
  772.                     if(pde.getAllegaBody()!=null){
  773.                         allegaBody = pde.getAllegaBody().toString();
  774.                     }
  775.                     String scartaBody = null;
  776.                     if(pde.getScartaBody()!=null){
  777.                         scartaBody = pde.getScartaBody().toString();
  778.                     }
  779.                     if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO.equals(allegaBody) &&
  780.                             PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO.equals(scartaBody))
  781.                         gestBody = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_ALLEGA;
  782.                     else if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO.equals(allegaBody) &&
  783.                             PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO.equals(scartaBody))
  784.                         gestBody = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_SCARTA;
  785.                     else if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO.equals(allegaBody) &&
  786.                             PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO.equals(scartaBody))
  787.                         gestBody = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_NONE;
  788.                 }
  789.                 if (gestManifest == null &&
  790.                     pde.getGestioneManifest()!=null) {
  791.                     gestManifest = pde.getGestioneManifest().toString();
  792.                 }
  793.                 if (ricsim == null) {
  794.                     if(pde.getRicevutaAsincronaSimmetrica()!=null)
  795.                         ricsim = pde.getRicevutaAsincronaSimmetrica().toString();
  796.                     if ((ricsim == null) || "".equals(ricsim)) {
  797.                         ricsim = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_SIMMETRICA_ABILITATO;

  798.                     }
  799.                 }
  800.                 if (ricasim == null) {
  801.                     if(pde.getRicevutaAsincronaAsimmetrica()!=null)
  802.                         ricasim = pde.getRicevutaAsincronaAsimmetrica().toString();
  803.                     if ((ricasim == null) || "".equals(ricasim)) {
  804.                         ricasim = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_ASIMMETRICA_ABILITATO;
  805.                     }
  806.                 }
  807.                
  808.                 if (integrazioneStato == null) {
  809.                     if(pde.getIntegrazione() == null) {
  810.                         integrazioneStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_DEFAULT;
  811.                     } else if(TipoIntegrazione.DISABILITATO.getValue().equals(pde.getIntegrazione())) {
  812.                         integrazioneStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_DISABILITATO;
  813.                     } else {
  814.                         integrazioneStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_RIDEFINITO;
  815.                     }
  816.                 }

  817.                 if (integrazione == null) {
  818.                     integrazione = pde.getIntegrazione();
  819.                    
  820.                     List<String> integrazioneGruppiList = new ArrayList<>();
  821.                    
  822.                     if(integrazioneStato.equals(CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_RIDEFINITO)) {
  823.                         // decodificare il contenuto di integrazione per generare gli elementi grafici necessari.
  824.                         List<String> valoriIntegrazione = integrazione != null ? Arrays.asList(integrazione.split(",")) : new ArrayList<>();
  825.                         for (String valoreIntegrazione : valoriIntegrazione) {
  826.                             TipoIntegrazione tipoIntegrazione = TipoIntegrazione.toEnumConstant(valoreIntegrazione);
  827.                             GruppoIntegrazione group = tipoIntegrazione != null ? tipoIntegrazione.getGroup() : GruppoIntegrazione.PLUGIN;
  828.                             String gruppoValore = group.getValue();
  829.                            
  830.                             List<String> valoriIntegrazionePerGruppo = null;
  831.                             if(integrazioneGruppiValoriDeiGruppi.containsKey(gruppoValore)) {
  832.                                 valoriIntegrazionePerGruppo = integrazioneGruppiValoriDeiGruppi.remove(gruppoValore);
  833.                             } else {
  834.                                 valoriIntegrazionePerGruppo = new ArrayList<>();
  835.                             }
  836.                            
  837.                             valoriIntegrazionePerGruppo.add(valoreIntegrazione);
  838.                             integrazioneGruppiValoriDeiGruppi.put(gruppoValore, valoriIntegrazionePerGruppo);
  839.                              
  840.                             if(!integrazioneGruppiDaVisualizzare.contains(group)) {
  841.                                 integrazioneGruppiDaVisualizzare.add(group);
  842.                                 integrazioneGruppiList.add(gruppoValore);
  843.                             }
  844.                         }
  845.                        
  846.                         integrazioneGruppi = !integrazioneGruppiList.isEmpty() ? integrazioneGruppiList.toArray(new String[integrazioneGruppiList.size()]) : null;
  847.                     }
  848.                 }
  849.                
  850.                 if(ctModalitaSincronizzazione==null) {
  851.                     PolicyConfiguration policyConfig = new PolicyConfiguration(pde.getProprietaRateLimitingList(), porteDelegateCore.getControlloTrafficoPolicyRateLimitingTipiGestori(), false);
  852.                     ctModalitaSincronizzazione = policyConfig.getSyncMode();
  853.                     ctImplementazione = policyConfig.getImpl();
  854.                     ctContatori = policyConfig.getCount();
  855.                     ctTipologia = policyConfig.getEngineType();
  856.                     ctHeaderHttp = policyConfig.getHttpMode();
  857.                     ctHeaderHttpLimit = policyConfig.getHttpMode_limit();
  858.                     ctHeaderHttpRemaining = policyConfig.getHttpMode_remaining();
  859.                     ctHeaderHttpReset = policyConfig.getHttpMode_reset();
  860.                     ctHeaderHttpRetryAfter = policyConfig.getHttpMode_retry_after();
  861.                     ctHeaderHttpRetryAfterBackoff = policyConfig.getHttpMode_retry_after_backoff();
  862.                 }
  863.                
  864.                 if (messageEngine == null &&
  865.                     pde.getOptions()!=null) {
  866.                     Map<String, List<String>> props = PropertiesSerializator.convertoFromDBColumnValue(pde.getOptions());
  867.                     if(props!=null && props.size()>0) {
  868.                         String msgFactory = TransportUtils.getFirstValue(props,CostantiPdD.OPTIONS_MESSAGE_FACTORY);
  869.                         if(msgFactory!=null) {
  870.                             messageEngine = msgFactory;
  871.                         }
  872.                     }
  873.                 }

  874.                 if ((scadcorr == null) && (ca != null)) {
  875.                     scadcorr = ca.getScadenza();
  876.                 }
  877.                 if (modeaz == null) {
  878.                     PortaDelegataAzione pda = pde.getAzione();
  879.                     if (pda == null) {
  880.                         modeaz = "";
  881.                         azione = "";
  882.                         patternAzione = "";
  883.                     } else {
  884.                         if(pda.getIdentificazione()!=null)
  885.                             modeaz = pda.getIdentificazione().toString();
  886.                         azione = pda.getNome();
  887.                         patternAzione = pda.getPattern();
  888.                         azid = "" + pda.getId();
  889.                     }
  890.                     if ((modeaz == null) || "".equals(modeaz)) {
  891.                         modeaz = PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT;
  892.                     }
  893.                     boolean useForceWSDLBased = true;
  894.                     // assegno costante
  895.                     if (modeaz != null) {
  896.                         switch (PortaDelegataAzioneIdentificazione.toEnumConstant(modeaz)) {
  897.                         case STATIC:
  898.                             useForceWSDLBased = false;
  899.                             int azidInt = 0;
  900.                             if (azid != null)
  901.                                 azidInt = Integer.parseInt(azid);
  902.                             if ( (azidInt == -2) || (azidInt>0) ) {
  903.                                 azid = azione;
  904.                             }
  905.                             break;
  906.                         case INTERFACE_BASED:
  907.                             useForceWSDLBased = false;
  908.                             break;
  909.                         case CONTENT_BASED:
  910.                         case INPUT_BASED:
  911.                         case HEADER_BASED:
  912.                         case URL_BASED:
  913.                         case SOAP_ACTION_BASED:
  914.                         default:
  915.                             break;
  916.                         }

  917.                         if(useForceWSDLBased){
  918.                             StatoFunzionalita forceWsdlBased2 = pda.getForceInterfaceBased();

  919.                             if(forceWsdlBased2 != null && forceWsdlBased2.equals(StatoFunzionalita.ABILITATO)){
  920.                                 forceWsdlBased = "yes";
  921.                             } else {
  922.                                 forceWsdlBased = "";
  923.                             }
  924.                         }
  925.                     }
  926.                 }

  927.                 if ((modeaz != null) && !modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT) &&
  928.                         (azione == null)) {
  929.                     azione = "";
  930.                 }

  931.                 if(!usataInConfigurazioneDefault) {
  932.                     PortaDelegataAzione pda = pde.getAzione();
  933.                     if(pda != null) {
  934.                         List<String> azioneDelegataList = pda.getAzioneDelegataList();
  935.                         StringBuilder sb = new StringBuilder();
  936.                        
  937.                         for (String aD : azioneDelegataList) {
  938.                             if(sb.length() > 0) sb.append(", ");
  939.                             sb.append(aD);
  940.                         }
  941.                         azione = sb.toString();
  942.                     }
  943.                 }
  944.                
  945.                 // Se modesp = register-input, prendo la lista di tutti i
  946.                 // soggetti e la metto in un array
  947.                 String[] soggettiList = null;
  948.                 String[] soggettiListLabel = null;
  949.                 List<IDSoggetto> list = soggettiCore.getAllIdSoggettiRegistro(new FiltroRicercaSoggetti());
  950.                 if (list!=null && !list.isEmpty()) {

  951.                     List<String> soggettiListTmp = new ArrayList<>();
  952.                     Map<String, String> soggettiMapTmp = new HashMap<>();
  953.                    
  954.                     for (IDSoggetto soggetto : list) {
  955.                         if(tipiSoggettiCompatibiliAccordo.contains(soggetto.getTipo())){
  956.                             String keyIdSog = soggetto.getTipo() + "/" + soggetto.getNome();
  957.                             soggettiListTmp.add(keyIdSog);
  958.                             soggettiMapTmp.put(keyIdSog, porteDelegateHelper.getLabelNomeSoggetto(protocollo, soggetto.getTipo(), soggetto.getNome()));
  959.                         }
  960.                     }
  961.                     Collections.sort(soggettiListTmp);
  962.                     soggettiList = soggettiListTmp.toArray(new String[1]);
  963.                     soggettiListLabel = new String[soggettiList.length];
  964.                    
  965.                     for (int i = 0; i < soggettiList.length; i++) {
  966.                         String keyIdSog = soggettiList[i];
  967.                         soggettiListLabel[i] = soggettiMapTmp.get(keyIdSog);
  968.                     }
  969.                 }

  970.                 // Se modeservizio = register-input, prendo la lista di tutti i
  971.                 // servizi e la metto in un array
  972.                 String[] serviziList = null;
  973.                 String[] serviziListLabel = null;
  974.                 if ((idSoggettoErogatore != null && !"".equals(idSoggettoErogatore) && idSoggettoErogatore.contains("/"))) {
  975.                     IDSoggetto idSoggetto = new IDSoggetto(idSoggettoErogatore.split("/")[0], idSoggettoErogatore.split("/")[1]);
  976.                     FiltroRicercaServizi filtro = new FiltroRicercaServizi();
  977.                     filtro.setTipoSoggettoErogatore(idSoggetto.getTipo());
  978.                     filtro.setNomeSoggettoErogatore(idSoggetto.getNome());
  979.                     List<IDServizio> listIdServ = null;
  980.                     try{
  981.                         listIdServ = apsCore.getAllIdServizi(filtro);
  982.                     }catch(DriverRegistroServiziNotFound dNotFound){
  983.                         // ignore
  984.                     }
  985.                    
  986.                     if(listIdServ!=null && !listIdServ.isEmpty()){
  987.                         List<String> serviziListTmp = new ArrayList<>();
  988.                         Map<String, IDServizio> serviziMapTmp = new HashMap<>();
  989.                         for (IDServizio idServizio : listIdServ) {
  990.                             if(tipiServizioCompatibiliAccordo.contains(idServizio.getTipo())){
  991.                                 String keyServizio = idServizio.getTipo() + "/" + idServizio.getNome() + "/" + idServizio.getVersione();
  992.                                 serviziListTmp.add(keyServizio);
  993.                                 serviziMapTmp.put(keyServizio, idServizio);
  994.                             }
  995.                         }

  996.                         Collections.sort(serviziListTmp);
  997.                         serviziList = serviziListTmp.toArray(new String[1]);
  998.                         serviziListLabel = new String[serviziList.length];
  999.                         for (int i = 0; i < serviziList.length; i++) {
  1000.                             String idServTmp = serviziList[i];
  1001.                             serviziListLabel[i] = porteDelegateHelper.getLabelIdServizio(protocollo, serviziMapTmp.get(idServTmp));
  1002.                         }
  1003.                     }
  1004.                 }
  1005.                
  1006.                 IDSoggetto idSoggetto = null;
  1007.                 IDServizio idServizio = null;
  1008.                 AccordoServizioParteSpecifica servS = null;
  1009.                 if (    (servid != null && !"".equals(servid) && servid.contains("/"))
  1010.                         &&
  1011.                         (idSoggettoErogatore != null && !"".equals(idSoggettoErogatore) && idSoggettoErogatore.contains("/"))
  1012.                         ) {
  1013.                     idSoggetto = new IDSoggetto(idSoggettoErogatore.split("/")[0], idSoggettoErogatore.split("/")[1]);
  1014.                     idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servid.split("/")[0], servid.split("/")[1], idSoggetto,
  1015.                             Integer.parseInt(servid.split("/")[2]));
  1016.                     try{
  1017.                         servS = apsCore.getServizio(idServizio);
  1018.                     }catch(DriverRegistroServiziNotFound dNotFound){
  1019.                         // ignore
  1020.                     }
  1021.                     if(servS==null){
  1022.                         // è cambiato il soggetto erogatore. non è più valido il servizio
  1023.                         servid = null;
  1024.                         idServizio = null;
  1025.                         if(serviziList!=null && serviziList.length>0){
  1026.                             servid = serviziList[0];
  1027.                             idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servid.split("/")[0], servid.split("/")[1], idSoggetto,
  1028.                                     Integer.parseInt(servid.split("/")[2]));
  1029.                             try{
  1030.                                 servS = apsCore.getServizio(idServizio);
  1031.                             }catch(DriverRegistroServiziNotFound dNotFound){
  1032.                                 // ignore
  1033.                             }
  1034.                             if(servS==null){
  1035.                                 servid = null;
  1036.                                 idServizio = null;
  1037.                             }
  1038.                         }
  1039.                     }
  1040.                 }
  1041.                
  1042.                 AccordoServizioParteComuneSintetico as = null;
  1043.                 if ( servS!=null ) {
  1044.                     IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(servS.getAccordoServizioParteComune());
  1045.                     as = apcCore.getAccordoServizioSintetico(idAccordo);
  1046.                    
  1047.                     if(serviceBinding == null) {
  1048.                         serviceBinding = porteDelegateCore.toMessageServiceBinding(as.getServiceBinding());
  1049.                     }
  1050.                    
  1051.                 }
  1052.                
  1053.                 // Se modeaz = register-input, prendo la lista delle azioni
  1054.                 // associate a servid e la metto in un array
  1055.                 String[] azioniList = null;
  1056.                 String[] azioniListLabel = null;
  1057.                 List<String> filtraAzioniUtilizzate = new ArrayList<>();
  1058.                 if ((modeaz != null) && modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  1059.                
  1060.                     Map<String,String> azioni = porteDelegateCore.getAzioniConLabel(servS, as, addTrattinoSelezioneNonEffettuata , true, filtraAzioniUtilizzate);
  1061.                     if(azioni != null && azioni.size() > 0) {
  1062.                         azioniList = new String[azioni.size()];
  1063.                         azioniListLabel = new String[azioni.size()];
  1064.                         int i = 0;
  1065.                         for (Map.Entry<String,String> entry : azioni.entrySet()) {
  1066.                             azioniList[i] = entry.getKey();
  1067.                             azioniListLabel[i] = entry.getValue();
  1068.                             i++;
  1069.                         }
  1070.                     }
  1071.                 }
  1072.                 int numAzioni = 0;
  1073.                 if (azioniList != null)
  1074.                     numAzioni = azioniList.length;

  1075.                 // setto oldNomePD
  1076.                 pd.addHidden(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OLD_NOME_PD, oldNomePD);

  1077.                 // preparo i campi
  1078.                 List<DataElement> dati = new ArrayList<>();

  1079.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  1080.                 dati = porteDelegateHelper.addPorteDelegateToDati(TipoOperazione.CHANGE, idsogg, nomePorta, dati,
  1081.                         idPorta, descr, autenticazione,
  1082.                         autorizzazione,
  1083.                         idSoggettoErogatore, soggettiList, soggettiListLabel,
  1084.                         nomeSoggettoErogatore, tipoSoggettoErogatore,
  1085.                         patternErogatore, servid, serviziList,
  1086.                         serviziListLabel, servizio, tiposervizio, versioneServizio,
  1087.                         patternServizio, modeaz, azid, azioniListLabel,
  1088.                         azioniList, azione, patternAzione, numAzioni,
  1089.                         stateless, localForward, paLocalForward, ricsim, ricasim, statoValidazione,
  1090.                         tipoValidazione, numCorrApp, scadcorr, gestBody,
  1091.                         gestManifest, integrazioneStato, integrazione,
  1092.                         integrazioneGruppi, integrazioneGruppiDaVisualizzare, integrazioneGruppiValoriDeiGruppi,
  1093.                         autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom,
  1094.                         autorizzazioneCustom,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  1095.                         autorizzazioneContenutiStato, autorizzazioneContenuti,autorizzazioneContenutiProperties,
  1096.                         idsogg,protocollo,numSA,numRuoli,ruoloMatch,
  1097.                         statoMessageSecurity,statoMessageMTOM,
  1098.                         numCorrelazioneReq,numCorrelazioneRes,
  1099.                         forceWsdlBased,applicaMTOM,riusoID,
  1100.                         servS, as,serviceBinding,
  1101.                         statoPorta,usataInConfigurazioni,usataInConfigurazioneDefault,
  1102.                         StatoFunzionalita.ABILITATO.equals(pde.getRicercaPortaAzioneDelegata()),
  1103.                         (pde.getAzione()!=null ? pde.getAzione().getNomePortaDelegante() : null), gestioneToken,null,null,
  1104.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  1105.                         gestioneTokenValidazioneInput,gestioneTokenIntrospection,gestioneTokenUserInfo,gestioneTokenTokenForward,
  1106.                         autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  1107.                         autorizzazioneToken,autorizzazioneTokenOptions,
  1108.                         autorizzazioneScope,numScope, autorizzazioneScopeMatch,allegatoXacmlPolicy,
  1109.                         messageEngine, pde.getCanale(),
  1110.                         identificazioneAttributiStato, null,null, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  1111.                         autorizzazioneAutenticatiToken, null, numAutenticatiToken,
  1112.                         autorizzazioneRuoliToken,  null, numRuoliToken, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken,
  1113.                         ctModalitaSincronizzazione, ctImplementazione, ctContatori, ctTipologia,
  1114.                         ctHeaderHttp, ctHeaderHttpLimit, ctHeaderHttpRemaining, ctHeaderHttpReset,
  1115.                         ctHeaderHttpRetryAfter, ctHeaderHttpRetryAfterBackoff);

  1116.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, null, null, null, idAsps,
  1117.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  1118.                
  1119.                 pd.setDati(dati);

  1120.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  1121.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE, ForwardParams.CHANGE());
  1122.             }

  1123.             // Controlli sui campi immessi

  1124.             boolean isOk = porteDelegateHelper.porteDelegateCheckData(TipoOperazione.CHANGE, oldNomePD, datiAltroPorta,
  1125.                     serviceBinding);

  1126.             if (!isOk) {
  1127.                 // setto la barra del titolo
  1128.                 ServletUtils.setPageDataTitle(pd, lstParam);

  1129.                 // Se modesp = register-input, prendo la lista di tutti i
  1130.                 // soggetti e la metto in un array
  1131.                 String[] soggettiList = null;
  1132.                 String[] soggettiListLabel = null;
  1133.                 List<IDSoggetto> list = soggettiCore.getAllIdSoggettiRegistro(new FiltroRicercaSoggetti());
  1134.                 if (list!=null && !list.isEmpty()) {

  1135.                     List<String> soggettiListTmp = new ArrayList<>();
  1136.                     Map<String, String> soggettiMapTmp = new HashMap<>();
  1137.                    
  1138.                     for (IDSoggetto soggetto : list) {
  1139.                         if(tipiSoggettiCompatibiliAccordo.contains(soggetto.getTipo())){
  1140.                             String keyIdSog = soggetto.getTipo() + "/" + soggetto.getNome();
  1141.                             soggettiListTmp.add(keyIdSog);
  1142.                             soggettiMapTmp.put(keyIdSog, porteDelegateHelper.getLabelNomeSoggetto(protocollo, soggetto.getTipo(), soggetto.getNome()));
  1143.                         }
  1144.                     }
  1145.                     Collections.sort(soggettiListTmp);
  1146.                     soggettiList = soggettiListTmp.toArray(new String[1]);
  1147.                     soggettiListLabel = new String[soggettiList.length];
  1148.                    
  1149.                     for (int i = 0; i < soggettiList.length; i++) {
  1150.                         String keyIdSog = soggettiList[i];
  1151.                         soggettiListLabel[i] = soggettiMapTmp.get(keyIdSog);
  1152.                     }
  1153.                 }

  1154.                 // Se modeservizio = register-input, prendo la lista di tutti i servizi
  1155.                 // e la metto in un array
  1156.                 String[] serviziList = null;
  1157.                 String[] serviziListLabel = null;
  1158.                 if ((idSoggettoErogatore != null && !"".equals(idSoggettoErogatore) && idSoggettoErogatore.contains("/"))) {
  1159.                     IDSoggetto idSoggetto = new IDSoggetto(idSoggettoErogatore.split("/")[0], idSoggettoErogatore.split("/")[1]);
  1160.                     FiltroRicercaServizi filtro = new FiltroRicercaServizi();
  1161.                     filtro.setTipoSoggettoErogatore(idSoggetto.getTipo());
  1162.                     filtro.setNomeSoggettoErogatore(idSoggetto.getNome());
  1163.                     List<IDServizio> listTmp = null;
  1164.                     try{
  1165.                         listTmp = apsCore.getAllIdServizi(filtro);
  1166.                     }catch(DriverRegistroServiziNotFound dNotFound){
  1167.                         // ignore
  1168.                     }
  1169.                     if(listTmp!=null && !listTmp.isEmpty()){
  1170.                         List<String> serviziListTmp = new ArrayList<>();
  1171.                         List<String> serviziListLabelTmp = new ArrayList<>();

  1172.                         Map<String, IDServizio> serviziMapTmp = new HashMap<>();
  1173.                         for (IDServizio idServizio : listTmp) {
  1174.                             if(tipiServizioCompatibiliAccordo.contains(idServizio.getTipo())){
  1175.                                 String keyServizio = idServizio.getTipo() + "/" + idServizio.getNome() + "/" + idServizio.getVersione();
  1176.                                 serviziListTmp.add(keyServizio);
  1177.                                 serviziMapTmp.put(keyServizio, idServizio);
  1178.                                 serviziListLabelTmp.add(idServizio.getTipo() + "/" + idServizio.getNome()+ "/" + idServizio.getVersione().intValue());
  1179.                             }
  1180.                         }

  1181.                         Collections.sort(serviziListTmp);
  1182.                         serviziList = serviziListTmp.toArray(new String[1]);
  1183.                         serviziListLabel = new String[serviziList.length];
  1184.                         for (int i = 0; i < serviziList.length; i++) {
  1185.                             String idServTmp = serviziList[i];
  1186.                             serviziListLabel[i] = porteDelegateHelper.getLabelIdServizio(protocollo, serviziMapTmp.get(idServTmp));
  1187.                         }
  1188.                     }
  1189.                 }

  1190.                 IDSoggetto idSoggetto = null;
  1191.                 IDServizio idServizio = null;
  1192.                 AccordoServizioParteSpecifica servS = null;
  1193.                 if (    (servid != null && !"".equals(servid) && servid.contains("/"))
  1194.                         &&
  1195.                         (idSoggettoErogatore != null && !"".equals(idSoggettoErogatore) && idSoggettoErogatore.contains("/"))
  1196.                         ) {
  1197.                     idSoggetto = new IDSoggetto(idSoggettoErogatore.split("/")[0], idSoggettoErogatore.split("/")[1]);
  1198.                     idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servid.split("/")[0], servid.split("/")[1], idSoggetto,
  1199.                             Integer.parseInt(servid.split("/")[2]));
  1200.                     try{
  1201.                         servS = apsCore.getServizio(idServizio);
  1202.                     }catch(DriverRegistroServiziNotFound dNotFound){
  1203.                         // ignore
  1204.                     }
  1205.                 }
  1206.                
  1207.                 AccordoServizioParteComuneSintetico as = null;
  1208.                 if(servS!=null){
  1209.                     IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(servS.getAccordoServizioParteComune());
  1210.                     as = apcCore.getAccordoServizioSintetico(idAccordo);
  1211.                 }
  1212.                
  1213.                 // Se modeaz = register-input, prendo la lista delle azioni
  1214.                 // associate a servid e la metto in un array
  1215.                 String[] azioniList = null;
  1216.                 String[] azioniListLabel = null;
  1217.                 List<String> filtraAzioniUtilizzate = new ArrayList<>();
  1218.                 if ((modeaz != null) && modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  1219.                
  1220.                     Map<String,String> azioni = porteDelegateCore.getAzioniConLabel(servS, as, addTrattinoSelezioneNonEffettuata , true, filtraAzioniUtilizzate);
  1221.                     if(azioni != null && azioni.size() > 0) {
  1222.                         azioniList = new String[azioni.size()];
  1223.                         azioniListLabel = new String[azioni.size()];
  1224.                         int i = 0;
  1225.                         for (Map.Entry<String,String> entry : azioni.entrySet()) {
  1226.                             azioniList[i] = entry.getKey();
  1227.                             azioniListLabel[i] = entry.getValue();
  1228.                             i++;
  1229.                         }
  1230.                     }
  1231.                 }
  1232.                 int numAzioni = 0;
  1233.                 if (azioniList != null)
  1234.                     numAzioni = azioniList.length;

  1235.                 // setto oldNomePD
  1236.                 pd.addHidden(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OLD_NOME_PD, oldNomePD);

  1237.                 // preparo i campi
  1238.                 List<DataElement> dati = new ArrayList<>();
  1239.                 // i pattern sono i nomi

  1240.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  1241.                 dati = porteDelegateHelper.addPorteDelegateToDati(TipoOperazione.CHANGE, idsogg, nomePorta, dati,
  1242.                         idPorta, descr, autenticazione,
  1243.                         autorizzazione,
  1244.                         idSoggettoErogatore, soggettiList, soggettiListLabel,
  1245.                         nomeSoggettoErogatore, tipoSoggettoErogatore,
  1246.                         nomeSoggettoErogatore, servid,
  1247.                         serviziList, serviziListLabel, servizio,
  1248.                         tiposervizio, servizio, versioneServizio, modeaz, azid,
  1249.                         azioniListLabel, azioniList, azione, azione,
  1250.                         numAzioni,  stateless, localForward, paLocalForward, ricsim, ricasim,
  1251.                         statoValidazione, tipoValidazione, numCorrApp, scadcorr, gestBody,
  1252.                         gestManifest, integrazioneStato, integrazione,
  1253.                         integrazioneGruppi, integrazioneGruppiDaVisualizzare, integrazioneGruppiValoriDeiGruppi,
  1254.                         autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom,
  1255.                         autorizzazioneCustom,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  1256.                         autorizzazioneContenutiStato, autorizzazioneContenuti,autorizzazioneContenutiProperties,
  1257.                         idsogg,protocollo,numSA,numRuoli,ruoloMatch,
  1258.                         statoMessageSecurity,statoMessageMTOM,
  1259.                         numCorrelazioneReq,numCorrelazioneRes,forceWsdlBased,applicaMTOM,riusoID,
  1260.                         servS, as,serviceBinding,
  1261.                         statoPorta,usataInConfigurazioni,usataInConfigurazioneDefault,
  1262.                         StatoFunzionalita.ABILITATO.equals(pde.getRicercaPortaAzioneDelegata()),
  1263.                         (pde.getAzione()!=null ? pde.getAzione().getNomePortaDelegante() : null), gestioneToken,null,null,
  1264.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  1265.                         gestioneTokenValidazioneInput,gestioneTokenIntrospection,gestioneTokenUserInfo,gestioneTokenTokenForward,
  1266.                         autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  1267.                         autorizzazioneToken,autorizzazioneTokenOptions,
  1268.                         autorizzazioneScope,numScope, autorizzazioneScopeMatch,allegatoXacmlPolicy,
  1269.                         messageEngine, pde.getCanale(),
  1270.                         identificazioneAttributiStato, null,null, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  1271.                         autorizzazioneAutenticatiToken, null, numAutenticatiToken,
  1272.                         autorizzazioneRuoliToken,  null, numRuoliToken, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken,
  1273.                         ctModalitaSincronizzazione, ctImplementazione, ctContatori, ctTipologia,
  1274.                         ctHeaderHttp, ctHeaderHttpLimit, ctHeaderHttpRemaining, ctHeaderHttpReset,
  1275.                         ctHeaderHttpRetryAfter, ctHeaderHttpRetryAfterBackoff);
  1276.                
  1277.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, null, null, null, idAsps,
  1278.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  1279.                 pd.setDati(dati);

  1280.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  1281.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE,
  1282.                         ForwardParams.CHANGE());

  1283.             }

  1284.             // Modifico i dati della porta delegata nel db

  1285.             nomeSoggettoErogatore = idSoggettoErogatore.split("/")[1];
  1286.             tipoSoggettoErogatore = idSoggettoErogatore.split("/")[0];
  1287.            
  1288.             versioneServizio = servid.split("/")[2];
  1289.             servizio = servid.split("/")[1];
  1290.             tiposervizio = servid.split("/")[0];
  1291.            
  1292.             if (PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT.equals(modeaz)) {
  1293.                 azione = "";
  1294.             } else {
  1295.                 azid = "";
  1296.             }

  1297.             long idPA = pde.getId();

  1298.             PortaDelegata oldPD = porteDelegateCore.getPortaDelegata(idPA);

  1299.             PortaDelegata portaDelegata = (PortaDelegata) oldPD.clone();// new
  1300.             portaDelegata.setId(idPA);

  1301.             portaDelegata.setNome(nomePorta);
  1302.             IDPortaDelegata oldIDPortaDelegataForUpdate = new IDPortaDelegata();
  1303.             oldIDPortaDelegataForUpdate.setNome(oldPD.getNome());
  1304.             portaDelegata.setOldIDPortaDelegataForUpdate(oldIDPortaDelegataForUpdate);
  1305.             if(modificaDescrizione && (descr==null || StringUtils.isEmpty(descr)) && SubscriptionConfiguration.isDescriptionDefault(oldPD.getDescrizione())) {
  1306.                 // lascio la precedente descrizione
  1307.                 portaDelegata.setDescrizione(oldPD.getDescrizione());
  1308.             }
  1309.             else {
  1310.                 portaDelegata.setDescrizione(descr);
  1311.             }
  1312.             if(statoPorta==null || "".equals(statoPorta) || CostantiConfigurazione.ABILITATO.toString().equals(statoPorta)){
  1313.                 portaDelegata.setStato(StatoFunzionalita.ABILITATO);
  1314.             }
  1315.             else{
  1316.                 portaDelegata.setStato(StatoFunzionalita.DISABILITATO);
  1317.             }
  1318.            
  1319.             if (stateless!=null && stateless.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_STATELESS_DEFAULT))
  1320.                 portaDelegata.setStateless(null);
  1321.             else
  1322.                 portaDelegata.setStateless(StatoFunzionalita.toEnumConstant(stateless));
  1323.             if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_ALLEGA.equals(gestBody))
  1324.                 portaDelegata.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO));
  1325.             else
  1326.                 portaDelegata.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO));
  1327.             if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_SCARTA.equals(gestBody))
  1328.                 portaDelegata.setScartaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO));
  1329.             else
  1330.                 portaDelegata.setScartaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO));
  1331.             if (gestManifest!=null && gestManifest.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_STATELESS_DEFAULT))
  1332.                 portaDelegata.setGestioneManifest(null);
  1333.             else
  1334.                 portaDelegata.setGestioneManifest(StatoFunzionalita.toEnumConstant(gestManifest));
  1335.             portaDelegata.setRicevutaAsincronaSimmetrica(StatoFunzionalita.toEnumConstant(ricsim));
  1336.             portaDelegata.setRicevutaAsincronaAsimmetrica(StatoFunzionalita.toEnumConstant(ricasim));
  1337.             if(localForward!=null){
  1338.                 portaDelegata.setLocalForward(new PortaDelegataLocalForward());
  1339.                 portaDelegata.getLocalForward().setStato(StatoFunzionalita.toEnumConstant(localForward));
  1340.                 portaDelegata.getLocalForward().setPortaApplicativa(paLocalForward);
  1341.             }
  1342.            
  1343.             Map<String, List<String>> props = PropertiesSerializator.convertoFromDBColumnValue(portaDelegata.getOptions());
  1344.             props.remove(CostantiPdD.OPTIONS_MESSAGE_FACTORY);
  1345.             if(messageEngine!=null && !"".equals(messageEngine) && !CostantiControlStation.GESTIONE_MESSAGE_ENGINE_DEFAULT.equals(messageEngine)) {
  1346.                 TransportUtils.put(props,CostantiPdD.OPTIONS_MESSAGE_FACTORY, messageEngine,false);
  1347.             }
  1348.             if(props.size()>0) {
  1349.                 PropertiesSerializator ps = new PropertiesSerializator(props);
  1350.                 portaDelegata.setOptions(ps.convertToDBColumnValue());
  1351.             }
  1352.             else {
  1353.                 portaDelegata.setOptions(null);
  1354.             }

  1355.             PortaDelegataSoggettoErogatore pdSogg = new PortaDelegataSoggettoErogatore();
  1356.             IDSoggetto idSoggErogatore = new IDSoggetto(tipoSoggettoErogatore, nomeSoggettoErogatore);
  1357.             pdSogg.setId(soggettiCore.getSoggettoRegistro(idSoggErogatore).getId());
  1358.             if(pdSogg.getId()<=0){
  1359.                 pdSogg.setId(-2l);
  1360.             }
  1361.             pdSogg.setNome(nomeSoggettoErogatore);
  1362.             pdSogg.setTipo(tipoSoggettoErogatore);

  1363.             portaDelegata.setSoggettoErogatore(pdSogg);

  1364.             PortaDelegataServizio pdServizio = new PortaDelegataServizio();
  1365.             IDServizio idServizio = null;
  1366.             idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(tiposervizio, servizio, idSoggErogatore, Integer.parseInt(versioneServizio));
  1367.             try{
  1368.                 asps = apsCore.getServizio(idServizio);
  1369.                 pdServizio.setId(asps.getId());
  1370.             }catch(DriverRegistroServiziNotFound dNotFound){
  1371.                 // ignore
  1372.             }
  1373.             if(pdServizio.getId()<=0){
  1374.                 pdServizio.setId(-2l);
  1375.             }
  1376.             pdServizio.setNome(servizio);
  1377.             pdServizio.setTipo(tiposervizio);
  1378.             pdServizio.setVersione(Integer.parseInt(versioneServizio));

  1379.             portaDelegata.setServizio(pdServizio);

  1380.             // se l azione e' settata allora creo il bean
  1381.             if(modeaz!=null && modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_DELEGATED_BY)) {
  1382.                 // non modifico paAzione
  1383.             }
  1384.             else if (((azione != null) || (azid != null) || modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INPUT_BASED) ||
  1385.                             modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_SOAP_ACTION_BASED) ||
  1386.                             modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INTERFACE_BASED)) &&
  1387.                             (!"".equals(azione) || !azid.equals("") ||
  1388.                                     (modeaz != null &&
  1389.                                     (modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INPUT_BASED) ||
  1390.                                     modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_SOAP_ACTION_BASED) ||
  1391.                                     modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INTERFACE_BASED))))) {
  1392.                 PortaDelegataAzione pdAzione = new PortaDelegataAzione();

  1393.                 if (modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  1394.                     azione = azid;
  1395. /**                 IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  1396. //                  AccordoServizioParteComune as = apcCore.getAccordoServizio(idAccordo);
  1397. //
  1398. //                  if(asps.getPortType()!=null){
  1399. //                      // Bisogna prendere le operations del port type
  1400. //                      PortType pt = null;
  1401. //                      for (int i = 0; i < as.sizePortTypeList(); i++) {
  1402. //                          if(as.getPortType(i).getNome().equals(asps.getPortType())){
  1403. //                              pt = as.getPortType(i);
  1404. //                              break;
  1405. //                          }
  1406. //                      }
  1407. //                      if(pt==null){
  1408. //                          throw new Exception("Accordo servizio parte specifica ["+idServizio.toString()+"] possiede un port type ["+asps.getPortType()+"] che non risulta essere registrato nell'accordo di servizio parte comune ["+asps.getAccordoServizioParteComune()+"]");
  1409. //                      }
  1410. //                      if(pt.sizeAzioneList()>0){
  1411. //                          for (int i = 0; i < pt.sizeAzioneList(); i++) {
  1412. //                              if(pt.getAzione(i).getNome().equals(azione)){
  1413. //                                  pdAzione.setId(pt.getAzione(i).getId());
  1414. //                                  break;
  1415. //                              }
  1416. //                          }
  1417. //                      }
  1418. //                  }else{
  1419. //                      if(as.sizeAzioneList()>0){
  1420. //                          for (int i = 0; i < as.sizeAzioneList(); i++) {
  1421. //                              if(as.getAzione(i).getNome().equals(azione)){
  1422. //                                  pdAzione.setId(as.getAzione(i).getId());
  1423. //                                  break;
  1424. //                              }
  1425. //                          }
  1426. //                      }
  1427. //                  }*/

  1428.                     if(pdAzione.getId()<=0){
  1429.                         pdAzione.setId(-2l);
  1430.                     }
  1431.                 }
  1432.                 pdAzione.setNome(azione);
  1433.                 pdAzione.setIdentificazione(PortaDelegataAzioneIdentificazione.toEnumConstant(modeaz));
  1434.                 pdAzione.setPattern(azione);

  1435.                 //FORCE WSDL BASED
  1436.                 if(!modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT) &&
  1437.                         !modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INTERFACE_BASED)){

  1438.                     if(forceWsdlBased != null && (ServletUtils.isCheckBoxEnabled(forceWsdlBased))){
  1439.                         pdAzione.setForceInterfaceBased(StatoFunzionalita.ABILITATO);
  1440.                     }else {
  1441.                         pdAzione.setForceInterfaceBased(StatoFunzionalita.DISABILITATO);
  1442.                     }
  1443.                 } else {
  1444.                     pdAzione.setForceInterfaceBased(null);
  1445.                 }


  1446.                 portaDelegata.setAzione(pdAzione);
  1447.             } else {
  1448.                 portaDelegata.setAzione(null);
  1449.             }

  1450.             // soggetto proprietario
  1451.             SoggettoCtrlStat soggettoCS = soggettiCore.getSoggettoCtrlStat(soggInt);
  1452.             portaDelegata.setIdSoggetto(soggettoCS.getId());
  1453.             portaDelegata.setTipoSoggettoProprietario(soggettoCS.getTipo());
  1454.             portaDelegata.setNomeSoggettoProprietario(soggettoCS.getNome());

  1455.             // Cambio i dati della vecchia CorrelazioneApplicativa
  1456.             // Non ne creo una nuova, altrimenti mi perdo le vecchie entry
  1457.             if (ca != null)
  1458.                 ca.setScadenza(scadcorr);
  1459.             portaDelegata.setCorrelazioneApplicativa(ca);

  1460.             if(integrazioneStato.equals(CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_DEFAULT)) {
  1461.                 portaDelegata.setIntegrazione(null);
  1462.             } else if(integrazioneStato.equals(CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_DISABILITATO)) {
  1463.                 portaDelegata.setIntegrazione(CostantiControlStation.VALUE_PARAMETRO_PORTE_INTEGRAZIONE_STATO_DISABILITATO);
  1464.             } else {
  1465.                 List<String> valoriFinaliIntegrazione = new ArrayList<>();
  1466.                 for (GruppoIntegrazione group : integrazioneGruppiDaVisualizzare) {
  1467.                     valoriFinaliIntegrazione.addAll(integrazioneGruppiValoriDeiGruppi.get(group.getValue()));
  1468.                 }
  1469.                 portaDelegata.setIntegrazione(StringUtils.join(valoriFinaliIntegrazione.toArray(new String[valoriFinaliIntegrazione.size()]), ","));
  1470.             }

  1471.             if(datiAltroPorta) {
  1472.                 PolicyConfiguration oldPolicyConfig = new PolicyConfiguration(pde.getProprietaRateLimitingList(), porteDelegateCore.getControlloTrafficoPolicyRateLimitingTipiGestori(), false);
  1473.                 boolean changeImpl = false;
  1474.                 if(oldPolicyConfig.getEngineType()!=null) {
  1475.                     changeImpl=!oldPolicyConfig.getEngineType().equals(ctTipologia);
  1476.                 }
  1477.                 else if(ctContatori!=null) {
  1478.                     changeImpl=true;
  1479.                 }
  1480.                                
  1481.                 PolicyConfiguration policyConfig = new PolicyConfiguration();
  1482.                 if(changeImpl) {
  1483.                     policyConfig.setGestorePolicyConfigDate(DateManager.getTimeMillis());
  1484.                 }
  1485.                 else {
  1486.                     policyConfig.setGestorePolicyConfigDate(oldPolicyConfig.getGestorePolicyConfigDate());
  1487.                 }
  1488.                 policyConfig.setSyncMode(ctModalitaSincronizzazione);
  1489.                 policyConfig.setImpl(ctImplementazione);
  1490.                 policyConfig.setCount(ctContatori);
  1491.                 policyConfig.setEngineType(ctTipologia);
  1492.                 policyConfig.setHttpMode(ctHeaderHttp);
  1493.                 policyConfig.setHttpMode_limit(ctHeaderHttpLimit);
  1494.                 policyConfig.setHttpMode_remaining(ctHeaderHttpRemaining);
  1495.                 policyConfig.setHttpMode_reset(ctHeaderHttpReset);
  1496.                 policyConfig.setHttpMode_retry_after(ctHeaderHttpRetryAfter);
  1497.                 policyConfig.setHttpMode_retry_after_backoff(ctHeaderHttpRetryAfterBackoff);
  1498.                 portaDelegata.setProprietaRateLimitingList(new ArrayList<>());
  1499.                 policyConfig.saveIn(portaDelegata.getProprietaRateLimitingList());
  1500.             }
  1501.            
  1502.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  1503.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);

  1504.             // Preparo la lista
  1505.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);


  1506.             int idLista = -1;
  1507.             List<PortaDelegata> lista = null;
  1508.            
  1509.             switch (parentPD) {
  1510.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE:
  1511.                
  1512.                 int idAspsInt = Integer.parseInt(idAsps);
  1513.                 asps = apsCore.getAccordoServizioParteSpecifica(idAspsInt);
  1514.                 IDServizio idServizio2 = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
  1515.                
  1516.                 AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  1517.                
  1518.                 if(datiInvocazione || datiAltroApi) {
  1519.                     if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  1520.                         ErogazioniHelper erogazioniHelper = new ErogazioniHelper(request, pd, session);
  1521.                         erogazioniHelper.prepareErogazioneChange(TipoOperazione.CHANGE, asps,
  1522.                                 new IDSoggetto(portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario()));
  1523.                         ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  1524.                         return ServletUtils.getStrutsForwardEditModeFinished(mapping, ErogazioniCostanti.OBJECT_NAME_ASPS_EROGAZIONI, ForwardParams.CHANGE());
  1525.                     }
  1526.                    
  1527.                     String tipologia = ServletUtils.getObjectFromSession(request, session, String.class, AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE);
  1528.                     boolean gestioneFruitori = false;
  1529.                     if(tipologia!=null &&
  1530.                         AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_FRUIZIONE.equals(tipologia)) {
  1531.                         gestioneFruitori = true;
  1532.                     }
  1533.                     if(gestioneFruitori) {
  1534.                        
  1535.                         idLista = Liste.SERVIZI;
  1536.                        
  1537.                         ricerca = apsHelper.checkSearchParameters(idLista, ricerca);
  1538.                        
  1539.                         ricerca.addFilter(idLista, Filtri.FILTRO_DOMINIO, SoggettiCostanti.SOGGETTO_DOMINIO_ESTERNO_VALUE);
  1540.                        
  1541.                         String superUser =   ServletUtils.getUserLoginFromSession(session);
  1542.                         PermessiUtente pu = ServletUtils.getUserFromSession(request, session).getPermessi();
  1543.                         boolean [] permessi = new boolean[2];
  1544.                         permessi[0] = pu.isServizi();
  1545.                         permessi[1] = pu.isAccordiCooperazione();
  1546.                         List<AccordoServizioParteSpecifica> lista2 = null;
  1547.                         if(apsCore.isVisioneOggettiGlobale(superUser)){
  1548.                             lista2 = apsCore.soggettiServizioList(null, ricerca,permessi, gestioneFruitori, false);
  1549.                         }else{
  1550.                             lista2 = apsCore.soggettiServizioList(superUser, ricerca, permessi, gestioneFruitori, false);
  1551.                         }

  1552.                         apsHelper.prepareServiziList(ricerca, lista2);
  1553.                        
  1554.                     }
  1555.                     else {
  1556.                    
  1557.                         idLista = Liste.SERVIZI_FRUITORI;
  1558.                         ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  1559.                        
  1560.                         List<Fruitore> listaFruitori = apsCore.serviziFruitoriList(idAspsInt, ricerca);
  1561.                         apsHelper.prepareServiziFruitoriList(listaFruitori, idAsps, ricerca);
  1562.                        
  1563.                     }
  1564.                 }
  1565.                 else {
  1566.                     idLista = Liste.CONFIGURAZIONE_FRUIZIONE;
  1567.                     ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  1568.                    
  1569.                     List<MappingFruizionePortaDelegata> listaMapping = apsCore.serviziFruitoriMappingList((long) Integer.parseInt(idFruizione), idSoggettoFruitore, idServizio2, ricerca);
  1570.                     apsHelper.serviziFruitoriMappingList(listaMapping, idAsps, idsogg, idSoggettoFruitore, idFruizione, ricerca);
  1571.                 }
  1572.                
  1573.                 break;
  1574.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_SOGGETTO:
  1575.                 idLista = Liste.PORTE_DELEGATE_BY_SOGGETTO;
  1576.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  1577.                 lista = porteDelegateCore.porteDelegateList(soggInt, ricerca);
  1578.                 porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
  1579.                 break;
  1580.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE:
  1581.             default:
  1582.                 idLista = Liste.PORTE_DELEGATE;
  1583.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  1584.                 lista = porteDelegateCore.porteDelegateList(null, ricerca);
  1585.                 porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
  1586.                 break;
  1587.             }

  1588.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  1589.            
  1590.             ForwardParams fwP = ForwardParams.CHANGE();
  1591.            
  1592.             if( (datiAltroPorta || modificaDescrizione) && !porteDelegateHelper.isModalitaCompleta()) {
  1593.                 fwP = PorteDelegateCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE;
  1594.             }
  1595.            
  1596.             // Forward control to the specified success URI
  1597.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE, fwP);

  1598.         } catch (Exception e) {
  1599.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  1600.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE,
  1601.                     ForwardParams.CHANGE());
  1602.         }  
  1603.     }
  1604. }