AccordiServizioParteComuneAdd.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.apc;

  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import java.util.stream.Collectors;
  26. import java.util.stream.Stream;

  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.Liste;
  36. import org.openspcoop2.core.config.CanaleConfigurazione;
  37. import org.openspcoop2.core.config.CanaliConfigurazione;
  38. import org.openspcoop2.core.config.Soggetto;
  39. import org.openspcoop2.core.id.IDAccordo;
  40. import org.openspcoop2.core.id.IDAccordoCooperazione;
  41. import org.openspcoop2.core.id.IDSoggetto;
  42. import org.openspcoop2.core.registry.AccordoCooperazione;
  43. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  44. import org.openspcoop2.core.registry.AccordoServizioParteComuneServizioComposto;
  45. import org.openspcoop2.core.registry.GruppiAccordo;
  46. import org.openspcoop2.core.registry.Gruppo;
  47. import org.openspcoop2.core.registry.GruppoAccordo;
  48. import org.openspcoop2.core.registry.IdSoggetto;
  49. import org.openspcoop2.core.registry.ProtocolProperty;
  50. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  51. import org.openspcoop2.core.registry.constants.FormatoSpecifica;
  52. import org.openspcoop2.core.registry.constants.PddTipologia;
  53. import org.openspcoop2.core.registry.constants.ProfiloCollaborazione;
  54. import org.openspcoop2.core.registry.constants.StatiAccordo;
  55. import org.openspcoop2.core.registry.constants.StatoFunzionalita;
  56. import org.openspcoop2.core.registry.driver.FiltroRicercaGruppi;
  57. import org.openspcoop2.core.registry.driver.IDAccordoCooperazioneFactory;
  58. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  59. import org.openspcoop2.core.registry.driver.ValidazioneStatoPackageException;
  60. import org.openspcoop2.message.constants.MessageType;
  61. import org.openspcoop2.message.constants.ServiceBinding;
  62. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  63. import org.openspcoop2.protocol.manifest.constants.InterfaceType;
  64. import org.openspcoop2.protocol.sdk.ProtocolException;
  65. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  66. import org.openspcoop2.protocol.sdk.constants.ProfiloDiCollaborazione;
  67. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  68. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  69. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  70. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  71. import org.openspcoop2.web.ctrlstat.servlet.ac.AccordiCooperazioneCore;
  72. import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiCostanti;
  73. import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiHelper;
  74. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  75. import org.openspcoop2.web.ctrlstat.servlet.gruppi.GruppiCore;
  76. import org.openspcoop2.web.ctrlstat.servlet.protocol_properties.ProtocolPropertiesCostanti;
  77. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  78. import org.openspcoop2.web.lib.mvc.Costanti;
  79. import org.openspcoop2.web.lib.mvc.DataElement;
  80. import org.openspcoop2.web.lib.mvc.ForwardParams;
  81. import org.openspcoop2.web.lib.mvc.GeneralData;
  82. import org.openspcoop2.web.lib.mvc.PageData;
  83. import org.openspcoop2.web.lib.mvc.Parameter;
  84. import org.openspcoop2.web.lib.mvc.ServletUtils;
  85. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  86. /**
  87.  * accordiAdd
  88.  *
  89.  * @author Andrea Poli (apoli@link.it)
  90.  * @author Stefano Corallo (corallo@link.it)
  91.  * @author Sandra Giangrandi (sandra@link.it)
  92.  * @author $Author$
  93.  * @version $Rev$, $Date$
  94.  *
  95.  */
  96. public final class AccordiServizioParteComuneAdd extends Action {

  97.    

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

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

  101.         // Inizializzo PageData
  102.         PageData pd = new PageData();

  103.         GeneralHelper generalHelper = new GeneralHelper(session);

  104.         // Inizializzo GeneralData
  105.         GeneralData gd = generalHelper.initGeneralData(request);

  106.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  107.         AccordiServizioParteComuneAddStrutsBean strutsBean = new AccordiServizioParteComuneAddStrutsBean();
  108.        
  109.         // Parametri Protocol Properties relativi al tipo di operazione e al tipo di visualizzazione
  110.         strutsBean.consoleOperationType = ConsoleOperationType.ADD;
  111.        
  112.         // Parametri relativi al tipo operazione
  113.         TipoOperazione tipoOp = TipoOperazione.ADD;

  114.         try {
  115.             ApiHelper apcHelper = new ApiHelper(request, pd, session);
  116.             Boolean isModalitaVistaApiCustom = ServletUtils.getBooleanAttributeFromSession(ApiCostanti.SESSION_ATTRIBUTE_VISTA_APC_API, session, request, false).getValue();
  117.            
  118.             strutsBean.editMode = apcHelper.getParameter(Costanti.DATA_ELEMENT_EDIT_MODE_NAME);
  119.             strutsBean.nome = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_NOME);
  120.             strutsBean.descr = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_DESCRIZIONE);
  121.             strutsBean.profcoll = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PROFILO_COLLABORAZIONE);
  122.            
  123.            
  124.             strutsBean.wsdldef = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_DEFINITORIO);
  125.             strutsBean.wsdlconc = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_CONCETTUALE);
  126.             strutsBean.wsdlserv = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_EROGATORE);
  127.             strutsBean.wsdlservcorr = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_FRUITORE);

  128.             strutsBean.wsblconc = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_CONCETTUALE);
  129.             strutsBean.wsblserv = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_EROGATORE);
  130.             strutsBean.wsblservcorr = apcHelper.getBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_FRUITORE);

  131.             strutsBean.filtrodup = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_FILTRO_DUPLICATI);
  132.             strutsBean.confric = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_CONFERMA_RICEZIONE);
  133.             strutsBean.idcoll = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_COLLABORAZIONE);
  134.             strutsBean.idRifRichiesta = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID_RIFERIMENTO_RICHIESTA);
  135.             strutsBean.consord = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_CONSEGNA_ORDINE);
  136.             strutsBean.scadenza = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SCADENZA);
  137.             strutsBean.referente = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_REFERENTE);
  138.             strutsBean.versione = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_VERSIONE);
  139.            
  140.             String serviceBindingS = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SERVICE_BINDING);
  141.             strutsBean.serviceBinding = StringUtils.isNotEmpty(serviceBindingS) ? ServiceBinding.valueOf(serviceBindingS) : null;
  142.             String messageProcessorS = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_MESSAGE_TYPE);
  143.             strutsBean.messageType = (StringUtils.isNotEmpty(messageProcessorS) && !messageProcessorS.equals(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_MESSAGE_TYPE_DEFAULT)) ? MessageType.valueOf(messageProcessorS) : null;
  144.             String formatoSpecificaS = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_INTERFACE_TYPE);
  145.             strutsBean.interfaceType = StringUtils.isNotEmpty(formatoSpecificaS) ? InterfaceType.toEnumConstant(formatoSpecificaS) : null;
  146.            
  147.             strutsBean.gruppi = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_GRUPPI);
  148.             strutsBean.canale = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_CANALE);
  149.             strutsBean.canaleStato = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_CANALE_STATO);

  150.             // patch per version spinner fino a che non si trova un modo piu' elegante
  151.             // Veniva sempre impostato false, lo lascio commentato in questo punto perche' veniva passato nella decode della richiesta multipart...
  152.             /**         if(this.isBackwardCompatibilityAccordo11){
  153.             //              if("0".equals(strutsBean.versione))
  154.             //                  strutsBean.versione = "";
  155.             //          } */

  156.             String priv = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PRIVATO);
  157.             strutsBean.privato = ServletUtils.isCheckBoxEnabled(priv);

  158.             String isServComp = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_IS_SERVIZIO_COMPOSTO);
  159.             strutsBean.isServizioComposto = ServletUtils.isCheckBoxEnabled(isServComp);

  160.             strutsBean.accordoCooperazione = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ACCORDO_COOPERAZIONE);
  161.             strutsBean.statoPackage = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_STATO_PACKAGE);

  162.             strutsBean.tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  163.             if("".equals(strutsBean.tipoAccordo))
  164.                 strutsBean.tipoAccordo = null;
  165.             if(strutsBean.tipoAccordo!=null){
  166.                 if(AccordiServizioParteComuneCostanti.PARAMETRO_VALORE_APC_TIPO_ACCORDO_PARTE_COMUNE.equals(strutsBean.tipoAccordo)){
  167.                     strutsBean.isServizioComposto = false;
  168.                 }else if(AccordiServizioParteComuneCostanti.PARAMETRO_VALORE_APC_TIPO_ACCORDO_SERVIZIO_COMPOSTO.equals(strutsBean.tipoAccordo)){
  169.                     strutsBean.isServizioComposto = true;
  170.                 }
  171.             }

  172.             if (apcHelper.isMultipart()) {
  173.                 /** this.decodeRequest(request,ch.core.isBackwardCompatibilityAccordo11());
  174.                 //              strutsBean.decodeRequestValidazioneDocumenti = false; // init
  175.                 //              this.decodeRequest(request,false); */

  176.                 //Quando trovava la linea corrispondente a AccordiServizioParteComuneCostanti.PARAMETRO_APC_VALIDAZIONE_DOCUMENTI  
  177.                 //eseguiva questo codice
  178.                 strutsBean.decodeRequestValidazioneDocumenti = true;
  179.                 String tmpValidazioneDocumenti = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_VALIDAZIONE_DOCUMENTI);
  180.                 strutsBean.validazioneDocumenti = ServletUtils.isCheckBoxEnabled(tmpValidazioneDocumenti);
  181.             }

  182.             if(ServletUtils.isEditModeInProgress(strutsBean.editMode)){
  183.                 // primo accesso alla servlet
  184.                 strutsBean.validazioneDocumenti = true;
  185.             }else{
  186.                 if(!strutsBean.decodeRequestValidazioneDocumenti){
  187.                     String tmpValidazioneDocumenti = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_VALIDAZIONE_DOCUMENTI);
  188.                     strutsBean.validazioneDocumenti = ServletUtils.isCheckBoxEnabled(tmpValidazioneDocumenti);
  189.                 }
  190.             }

  191.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
  192.             SoggettiCore soggettiCore = new SoggettiCore(apcCore);
  193.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore(apcCore);
  194.             GruppiCore gruppiCore = new GruppiCore(apcCore);
  195.             ConfigurazioneCore confCore = new ConfigurazioneCore(apcCore);
  196.             String labelAccordoServizio = AccordiServizioParteComuneUtilities.getTerminologiaAccordoServizio(strutsBean.tipoAccordo);
  197.            
  198.             // carico i canali
  199.             CanaliConfigurazione gestioneCanali = confCore.getCanaliConfigurazione(false);
  200.             List<CanaleConfigurazione> canaleList = gestioneCanali != null ? gestioneCanali.getCanaleList() : new ArrayList<>();
  201.             boolean gestioneCanaliEnabled = gestioneCanali != null && org.openspcoop2.core.config.constants.StatoFunzionalita.ABILITATO.equals(gestioneCanali.getStato());
  202.            
  203.             // Tipi protocollo supportati
  204.             // Controllo comunque quelli operativi, almeno uno deve esistere
  205.             List<String> listaTipiProtocollo = apcCore.getProtocolliByFilter(request, session, true, PddTipologia.OPERATIVO, false, strutsBean.isServizioComposto);

  206.             // primo accesso
  207.             strutsBean.tipoProtocollo =  apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PROTOCOLLO);
  208.             if(strutsBean.tipoProtocollo == null){
  209.                 strutsBean.tipoProtocollo = apcCore.getProtocolloDefault(request, session, listaTipiProtocollo);
  210.             }
  211.            
  212.             String nuovaVersioneTmp = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_API_NUOVA_VERSIONE);
  213.             strutsBean.nuovaVersione = ServletUtils.isCheckBoxEnabled(nuovaVersioneTmp);
  214.             int gestioneNuovaVersioneMin = 1;
  215.             boolean nuovaVersioneRidefinisciInterfaccia = true;
  216.             long gestioneNuovaVersioneOldIdApc = -1;
  217.             List<ProtocolProperty> gestioneNuovaVersioneOldProtocolProperties = null;
  218.             if(strutsBean.nuovaVersione) {
  219.                
  220.                 String nuovaVersioneTmpMinVersion = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_API_NUOVA_VERSIONE_MIN);
  221.                 if(!StringUtils.isEmpty(nuovaVersioneTmpMinVersion)) {
  222.                     gestioneNuovaVersioneMin = Integer.parseInt(nuovaVersioneTmpMinVersion);
  223.                 }
  224.                                
  225.                 String tmpIdPrecedenteAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID);
  226.                 if(!StringUtils.isEmpty(tmpIdPrecedenteAccordo)) {
  227.                    
  228.                     // ci entro solamente la prima volta al "click" sulla nuova versione
  229.                    
  230.                     nuovaVersioneRidefinisciInterfaccia = true; // default
  231.                    
  232.                     // fisso alcuni valori
  233.                     long idAccordoPrec = Long.parseLong(tmpIdPrecedenteAccordo);
  234.                     gestioneNuovaVersioneOldIdApc = idAccordoPrec;
  235.                     AccordoServizioParteComune aspc = apcCore.getAccordoServizioFull(idAccordoPrec);
  236.                     gestioneNuovaVersioneOldProtocolProperties = aspc.getProtocolPropertyList();
  237.                     IDAccordo idAccordoPrecedente = IDAccordoFactory.getInstance().getIDAccordoFromAccordo(aspc);
  238.                     strutsBean.nome = aspc.getNome();
  239.                     strutsBean.referente = soggettiCore.getSoggetto(aspc.getSoggettoReferente().toIDSoggetto()).getId().longValue()+"";
  240.                     strutsBean.tipoProtocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(aspc.getSoggettoReferente().getTipo());
  241.                     strutsBean.serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  242.                     if(aspc.getMessageType()!=null) {
  243.                         strutsBean.messageType = apcCore.toMessageMessageType(aspc.getMessageType());
  244.                     }
  245.                     if(aspc.getServizioComposto()!=null && aspc.getServizioComposto().getAccordoCooperazione()!=null && !"".equals(aspc.getServizioComposto().getAccordoCooperazione())) {
  246.                         IDAccordoCooperazione idAccordoCooperazione = IDAccordoCooperazioneFactory.getInstance().getIDAccordoFromUri(aspc.getServizioComposto().getAccordoCooperazione());
  247.                         strutsBean.accordoCooperazione = acCore.getAccordoCooperazione(idAccordoCooperazione).getId().longValue()+"";
  248.                         strutsBean.isServizioComposto = true;
  249.                     }
  250.                     if(strutsBean.interfaceType==null) {
  251.                         strutsBean.interfaceType = apcCore.formatoSpecifica2InterfaceType(aspc.getFormatoSpecifica());
  252.                     }
  253.                     if(strutsBean.descr==null || StringUtils.isEmpty(strutsBean.descr)) {
  254.                         strutsBean.descr = aspc.getDescrizione();
  255.                     }
  256.                     if((strutsBean.gruppi==null || StringUtils.isEmpty(strutsBean.gruppi)) &&
  257.                         aspc.getGruppi()!=null && aspc.getGruppi().getGruppoList()!=null && !aspc.getGruppi().getGruppoList().isEmpty()) {
  258.                         List<String> nomiGruppi = aspc.getGruppi().getGruppoList().stream().flatMap(e-> Stream.of(e.getNome())).collect(Collectors.toList());
  259.                         strutsBean.gruppi = StringUtils.join(nomiGruppi, ",");
  260.                     }
  261.                     if(strutsBean.profcoll==null || StringUtils.isEmpty(strutsBean.profcoll)) {
  262.                         strutsBean.profcoll = AccordiServizioParteComuneHelper.convertProfiloCollaborazioneDB2View(aspc.getProfiloCollaborazione());
  263.                     }
  264.                     if(strutsBean.filtrodup==null || StringUtils.isEmpty(strutsBean.filtrodup)) {
  265.                         strutsBean.filtrodup = AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoDB2View(aspc.getFiltroDuplicati());
  266.                     }
  267.                     if(strutsBean.confric==null || StringUtils.isEmpty(strutsBean.confric)) {
  268.                         strutsBean.confric = AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoDB2View(aspc.getConfermaRicezione());
  269.                     }
  270.                     if(strutsBean.idcoll==null || StringUtils.isEmpty(strutsBean.idcoll)) {
  271.                         strutsBean.idcoll = AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoDB2View(aspc.getIdCollaborazione());
  272.                     }
  273.                     if(strutsBean.idRifRichiesta==null || StringUtils.isEmpty(strutsBean.idRifRichiesta)) {
  274.                         strutsBean.idRifRichiesta = AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoDB2View(aspc.getIdRiferimentoRichiesta());
  275.                     }
  276.                     if(strutsBean.consord==null || StringUtils.isEmpty(strutsBean.consord)) {
  277.                         strutsBean.consord = AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoDB2View(aspc.getConsegnaInOrdine());
  278.                     }
  279.                     if(strutsBean.scadenza==null || StringUtils.isEmpty(strutsBean.scadenza)) {
  280.                         strutsBean.scadenza = aspc.getScadenza() != null ? aspc.getScadenza() : "";
  281.                     }
  282.                    
  283.                     gestioneNuovaVersioneMin = apcCore.getAccordoServizioParteComuneNextVersion(idAccordoPrecedente);
  284.                     if(strutsBean.versione==null || StringUtils.isEmpty(strutsBean.versione)) {
  285.                         strutsBean.versione = gestioneNuovaVersioneMin+"";
  286.                     }
  287.                     if(strutsBean.canale==null || StringUtils.isEmpty(strutsBean.canale)) {
  288.                         strutsBean.canale = aspc.getCanale();
  289.                     }
  290.                     if(strutsBean.canaleStato==null || StringUtils.isEmpty(strutsBean.canaleStato)) {
  291.                         if(strutsBean.canale == null) {
  292.                             strutsBean.canaleStato = AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_DEFAULT;
  293.                         } else {
  294.                             strutsBean.canaleStato = AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_RIDEFINITO;
  295.                         }
  296.                     }
  297.                 }
  298.                 else {
  299.                     String nuovaVersioneRidefinisciInterfacciaTmp = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_API_NUOVA_VERSIONE_RIDEFINISCI_INTERFACCIA);
  300.                     nuovaVersioneRidefinisciInterfaccia = ServletUtils.isCheckBoxEnabled(nuovaVersioneRidefinisciInterfacciaTmp);
  301.                
  302.                     String nuovaVersioneOldIdApcTmp = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_API_NUOVA_VERSIONE_OLD_ID_APC);
  303.                     gestioneNuovaVersioneOldIdApc = Long.valueOf(nuovaVersioneOldIdApcTmp);
  304.                 }
  305.             }
  306.            
  307.             strutsBean.protocolFactory = ProtocolFactoryManager.getInstance().getProtocolFactoryByName(strutsBean.tipoProtocollo);
  308.             strutsBean.consoleDynamicConfiguration =  strutsBean.protocolFactory.createDynamicConfigurationConsole();
  309.             strutsBean.registryReader = soggettiCore.getRegistryReader(strutsBean.protocolFactory);
  310.             strutsBean.configRegistryReader = soggettiCore.getConfigIntegrationReader(strutsBean.protocolFactory);
  311.            
  312.             // service binding
  313.             if(strutsBean.serviceBinding == null) {
  314.                 strutsBean.serviceBinding  = soggettiCore.getDefaultServiceBinding(strutsBean.protocolFactory);
  315.             }
  316.            
  317.             FiltroRicercaGruppi filtroRicerca = new FiltroRicercaGruppi();
  318.             filtroRicerca.setServiceBinding(apcCore.fromMessageServiceBinding(strutsBean.serviceBinding));
  319.             List<String> elencoGruppi = gruppiCore.getAllGruppi(filtroRicerca);

  320.             boolean showReferente = false;
  321.             if(strutsBean.isServizioComposto){
  322.                 showReferente = true;
  323.             }
  324.             else {
  325.                 showReferente = apcCore.isSupportatoSoggettoReferente(strutsBean.tipoProtocollo);
  326.             }
  327.            
  328.             // ID Accordo Null per default
  329.             IDAccordo idApc = null;        
  330.             strutsBean.consoleConfiguration = (strutsBean.tipoAccordo==null || strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE)) ?
  331.                     strutsBean.consoleDynamicConfiguration.getDynamicConfigAccordoServizioParteComune(strutsBean.consoleOperationType, apcHelper,
  332.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc)
  333.                     : strutsBean.consoleDynamicConfiguration.getDynamicConfigAccordoServizioComposto(strutsBean.consoleOperationType, apcHelper,
  334.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  335.                    
  336.             strutsBean.protocolProperties = apcHelper.estraiProtocolPropertiesDaRequest(strutsBean.consoleConfiguration, strutsBean.consoleOperationType);
  337.            
  338.             if(strutsBean.nuovaVersione && gestioneNuovaVersioneOldProtocolProperties!=null && !gestioneNuovaVersioneOldProtocolProperties.isEmpty()){
  339.                 ProtocolPropertiesUtils.mergeProtocolPropertiesRegistry(strutsBean.protocolProperties, gestioneNuovaVersioneOldProtocolProperties, strutsBean.consoleOperationType);
  340.             }

  341.             // Flag per controllare il mapping automatico di porttype e operation
  342.             boolean enableAutoMapping = apcCore.isEnableAutoMappingWsdlIntoAccordo();
  343.             boolean enableAutoMappingEstraiXsdSchemiFromWsdlTypes = apcCore.isEnableAutoMappingWsdlIntoAccordoEstrazioneSchemiInWsdlTypes();

  344.            
  345.            
  346.             //Carico la lista dei tipi di soggetti gestiti dal protocollo
  347.             List<String> tipiSoggettiGestitiProtocollo = soggettiCore.getTipiSoggettiGestitiProtocollo(strutsBean.tipoProtocollo);

  348.             // Preparo il menu
  349.             apcHelper.makeMenu();
  350.                
  351.             if(listaTipiProtocollo.isEmpty()) {
  352.                 boolean msg = true;
  353.                 if(strutsBean.isServizioComposto) {
  354.                     List<String> listaTipiProtocolloSenzaAccordiCooperazione = apcCore.getProtocolliByFilter(request, session, true, PddTipologia.OPERATIVO, false, false);
  355.                     if(!listaTipiProtocolloSenzaAccordiCooperazione.isEmpty()) {
  356.                         pd.setMessage("Non risultano registrati accordi di cooperazione", Costanti.MESSAGE_TYPE_INFO);
  357.                         msg = false;
  358.                     }
  359.                 }
  360.                 if(msg) {
  361.                     if(soggettiCore.isGestionePddAbilitata(apcHelper)) {
  362.                         pd.setMessage("Non risultano registrati soggetti associati a porte di dominio di tipo operativo", Costanti.MESSAGE_TYPE_INFO);
  363.                     }
  364.                     else {
  365.                         pd.setMessage("Non risultano registrati soggetti di dominio interno", Costanti.MESSAGE_TYPE_INFO);
  366.                     }
  367.                 }
  368.                 pd.disableEditMode();

  369.                 List<DataElement> dati = new ArrayList<>();

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

  371.                 pd.setDati(dati);

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

  373.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC,
  374.                         ForwardParams.ADD());
  375.             }
  376.            
  377.             List<Soggetto> listaSoggetti=null;
  378.             if(apcCore.isVisioneOggettiGlobale(userLogin)){
  379.                 listaSoggetti = soggettiCore.soggettiList(null, new ConsoleSearch(true));
  380.             }else{
  381.                 listaSoggetti = soggettiCore.soggettiList(userLogin, new ConsoleSearch(true));
  382.             }
  383.             String[] providersList = null;
  384.             String[] providersListLabel = null;

  385.             List<String> soggettiListTmp = new ArrayList<>();
  386.             List<String> soggettiListLabelTmp = new ArrayList<>();
  387.             soggettiListTmp.add("-");
  388.             soggettiListLabelTmp.add("-");

  389.             if (!listaSoggetti.isEmpty()) {
  390.                 for (Soggetto soggetto : listaSoggetti) {
  391.                     if(tipiSoggettiGestitiProtocollo.contains(soggetto.getTipo())){
  392.                         soggettiListTmp.add(soggetto.getId().toString());
  393.                         /** soggettiListLabelTmp.add(soggetto.getTipo() + "/" + soggetto.getNome()); */
  394.                         soggettiListLabelTmp.add(apcHelper.getLabelNomeSoggetto(strutsBean.tipoProtocollo, soggetto.getTipo() , soggetto.getNome() ));
  395.                     }
  396.                 }
  397.             }
  398.             providersList = soggettiListTmp.toArray(new String[1]);
  399.             providersListLabel = soggettiListLabelTmp.toArray(new String[1]);

  400.             String[] accordiCooperazioneEsistenti=null;
  401.             String[] accordiCooperazioneEsistentiLabel=null;

  402.  
  403.             String postBackElementName = apcHelper.getParameter(Costanti.POSTBACK_ELEMENT_NAME);

  404.             // Controllo se ho modificato il protocollo, resetto il referente e il service binding
  405.             if(postBackElementName != null ){
  406.                 if(postBackElementName.equalsIgnoreCase(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PROTOCOLLO)){
  407.                     strutsBean.referente = null;
  408.                     apcHelper.deleteBinaryParameters(strutsBean.wsdlconc,strutsBean.wsdldef,strutsBean.wsdlserv,strutsBean.wsdlservcorr,strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr);
  409.                     apcHelper.deleteProtocolPropertiesBinaryParameters(strutsBean.wsdlconc,strutsBean.wsdldef,strutsBean.wsdlserv,strutsBean.wsdlservcorr,strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr);
  410.                     strutsBean.serviceBinding  = soggettiCore.getDefaultServiceBinding(strutsBean.protocolFactory);
  411.                     strutsBean.interfaceType = null;
  412.                     strutsBean.messageType = null;
  413.                    
  414.                     strutsBean.wsdldef = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_DEFINITORIO);
  415.                     strutsBean.wsdlconc = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_CONCETTUALE);
  416.                     strutsBean.wsdlserv = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_EROGATORE);
  417.                     strutsBean.wsdlservcorr = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_FRUITORE);

  418.                     strutsBean.wsblconc = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_CONCETTUALE);
  419.                     strutsBean.wsblserv = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_EROGATORE);
  420.                     strutsBean.wsblservcorr = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_FRUITORE);
  421.                    
  422.                     filtroRicerca = new FiltroRicercaGruppi();
  423.                     filtroRicerca.setServiceBinding(apcCore.fromMessageServiceBinding(strutsBean.serviceBinding));
  424.                     elencoGruppi = gruppiCore.getAllGruppi(filtroRicerca);
  425.                 }
  426.                 else if(postBackElementName.equalsIgnoreCase(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SERVICE_BINDING)){
  427.                     strutsBean.interfaceType = null;
  428.                     strutsBean.messageType = null;
  429.                    
  430.                     strutsBean.wsdldef = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_DEFINITORIO);
  431.                     strutsBean.wsdlconc = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_CONCETTUALE);
  432.                     strutsBean.wsdlserv = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_EROGATORE);
  433.                     strutsBean.wsdlservcorr = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_WSDL_FRUITORE);

  434.                     strutsBean.wsblconc = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_CONCETTUALE);
  435.                     strutsBean.wsblserv = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_EROGATORE);
  436.                     strutsBean.wsblservcorr = apcHelper.newBinaryParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_SPECIFICA_CONVERSAZIONE_FRUITORE);
  437.                    
  438.                     filtroRicerca = new FiltroRicercaGruppi();
  439.                     filtroRicerca.setServiceBinding(apcCore.fromMessageServiceBinding(strutsBean.serviceBinding));
  440.                     elencoGruppi = gruppiCore.getAllGruppi(filtroRicerca);
  441.                 }
  442.             }

  443.             org.openspcoop2.core.registry.Soggetto soggettoReferente = null;
  444.             try{
  445.                 soggettoReferente = soggettiCore.getSoggettoRegistro(Long.valueOf(strutsBean.referente));
  446.             }catch(Exception e){
  447.                 // ignore
  448.             }
  449.             List<String> tipiSoggettiCompatibili = new ArrayList<>();
  450.             if(soggettoReferente!=null){
  451.                 String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoReferente.getTipo());
  452.                 tipiSoggettiCompatibili = soggettiCore.getTipiSoggettiGestitiProtocollo(protocollo);
  453.             }

  454.             if(strutsBean.isServizioComposto) {
  455.                 List<AccordoCooperazione> listaTmp = null;
  456.                 if(apcCore.isVisioneOggettiGlobale(userLogin)){
  457.                     listaTmp = acCore.accordiCooperazioneList(null, new ConsoleSearch(true));
  458.                 }else{
  459.                     listaTmp = acCore.accordiCooperazioneList(userLogin, new ConsoleSearch(true));
  460.                 }
  461.                 List<AccordoCooperazione> listaAccordoCooperazione = new ArrayList<>();
  462.                 for (AccordoCooperazione accordoCooperazione : listaTmp) {
  463.                     if(accordoCooperazione.getSoggettoReferente()!=null &&
  464.                         tipiSoggettiCompatibili!=null && tipiSoggettiCompatibili.contains(accordoCooperazione.getSoggettoReferente().getTipo())){
  465.                         listaAccordoCooperazione.add(accordoCooperazione);
  466.                     }
  467.                 }
  468.                 if (listaAccordoCooperazione != null && !listaAccordoCooperazione.isEmpty()) {
  469.                     accordiCooperazioneEsistenti = new String[listaAccordoCooperazione.size()+1];
  470.                     accordiCooperazioneEsistentiLabel = new String[listaAccordoCooperazione.size()+1];
  471.                     int i = 1;
  472.                     accordiCooperazioneEsistenti[0]="-";
  473.                     accordiCooperazioneEsistentiLabel[0]="-";
  474.                     Iterator<AccordoCooperazione> itL = listaAccordoCooperazione.iterator();
  475.                     while (itL.hasNext()) {
  476.                         AccordoCooperazione singleAC = itL.next();
  477.                         accordiCooperazioneEsistenti[i] = "" + singleAC.getId();
  478.                         accordiCooperazioneEsistentiLabel[i] = apcHelper.getLabelIdAccordoCooperazione(acCore.getAccordoCooperazione(singleAC.getId()));
  479.                         i++;
  480.                     }
  481.                 } else {
  482.                     accordiCooperazioneEsistenti = new String[1];
  483.                     accordiCooperazioneEsistentiLabel = new String[1];
  484.                     accordiCooperazioneEsistenti[0]="-";
  485.                     accordiCooperazioneEsistentiLabel[0]="-";
  486.                 }
  487.             }
  488.            
  489.             // message type resta null
  490.             // fromato specifica
  491.             if(strutsBean.interfaceType == null) {
  492.                 if(strutsBean.serviceBinding != null) {
  493.                     switch(strutsBean.serviceBinding) {
  494.                     case REST:
  495.                         strutsBean.interfaceType = InterfaceType.toEnumConstant(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_INTERFACE_TYPE_REST);
  496.                         break;
  497.                     case SOAP:
  498.                     default:
  499.                         strutsBean.interfaceType = InterfaceType.toEnumConstant(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_INTERFACE_TYPE_SOAP);
  500.                         break;
  501.                     }
  502.                 }
  503.             }

  504.             // Se nome = null, devo visualizzare la pagina per l'inserimento dati
  505.             String servletNameApcList = (isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) ? ApiCostanti.SERVLET_NAME_APC_API_LIST : AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_LIST;
  506.             Parameter pTipoAccordo = AccordiServizioParteComuneUtilities.getParametroAccordoServizio(strutsBean.tipoAccordo);
  507.             List<Parameter> listaParams = new ArrayList<>();
  508.             listaParams.add(new Parameter(labelAccordoServizio, servletNameApcList, pTipoAccordo));
  509.             listaParams.add(new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_AGGIUNGI,null));
  510.            
  511.            
  512.             if(ServletUtils.isEditModeInProgress(strutsBean.editMode)){

  513.                 // setto la barra del titolo
  514.                 ServletUtils.setPageDataTitle(pd, listaParams);

  515.                 if(strutsBean.nome==null){
  516.                     strutsBean.nome = "";
  517.                     strutsBean.accordoCooperazione = "";
  518.                     strutsBean.confric  = "";
  519.                     strutsBean.consord = "";
  520.                     strutsBean.descr = "";
  521.                     strutsBean.filtrodup = "yes";
  522.                     strutsBean.idcoll = "";
  523.                     strutsBean.idRifRichiesta = "";
  524.                     strutsBean.profcoll = "sincrono";
  525.                    
  526.                     if(strutsBean.serviceBinding != null) {
  527.                         switch(strutsBean.serviceBinding) {
  528.                         case REST:
  529.                             if( strutsBean.protocolFactory.createProtocolConfiguration().isSupportato(strutsBean.serviceBinding, ProfiloDiCollaborazione.ONEWAY)) {
  530.                                 strutsBean.profcoll = "oneway"; // es. as4
  531.                             }
  532.                             else {
  533.                                 strutsBean.profcoll = "sincrono";
  534.                             }
  535.                             break;
  536.                         case SOAP:
  537.                         default:
  538.                             break;
  539.                         }
  540.                     }
  541.                    
  542.                     strutsBean.accordoCooperazione = "-1";
  543.                     strutsBean.scadenza= "";
  544.                     strutsBean.privato = false;
  545.                     if(strutsBean.tipoProtocollo == null){
  546.                         strutsBean.tipoProtocollo = apcCore.getProtocolloDefault(request, session, listaTipiProtocollo);
  547.                     }
  548.                     strutsBean.referente= "";

  549.                     if(strutsBean.tipoAccordo!=null){
  550.                         if("apc".equals(strutsBean.tipoAccordo)){
  551.                             strutsBean.isServizioComposto = false;
  552.                         }else if("asc".equals(strutsBean.tipoAccordo)){
  553.                             strutsBean.isServizioComposto = true;
  554.                         }
  555.                     }else{
  556.                         strutsBean.isServizioComposto=false;
  557.                     }
  558.                     if(apcHelper.isShowGestioneWorkflowStatoDocumenti()){
  559.                         if(strutsBean.statoPackage==null)
  560.                             strutsBean.statoPackage=StatiAccordo.bozza.toString();
  561.                     }else{
  562.                         strutsBean.statoPackage=StatiAccordo.finale.toString();
  563.                     }
  564.                     /**if(core.isBackwardCompatibilityAccordo11()){
  565.                     //  strutsBean.versione="0";
  566.                     //}else{*/
  567.                     strutsBean.versione="1";
  568.                    
  569.                     strutsBean.gruppi = "";
  570.                     strutsBean.canaleStato = AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_DEFAULT;
  571.                     strutsBean.canale = "";
  572.                 }

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

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

  576.                 // update della configurazione
  577.                 if(strutsBean.tipoAccordo==null || strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE))
  578.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioParteComune(strutsBean.consoleConfiguration,
  579.                         strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  580.                         strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  581.                 else
  582.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioComposto(strutsBean.consoleConfiguration,
  583.                             strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  584.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc);

  585.                 dati = apcHelper.addAccordiToDati(dati, strutsBean.nome, strutsBean.descr, strutsBean.profcoll, strutsBean.wsdldef, strutsBean.wsdlconc, strutsBean.wsdlserv, strutsBean.wsdlservcorr, strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr,
  586.                         strutsBean.filtrodup, strutsBean.confric, strutsBean.idcoll, strutsBean.idRifRichiesta, strutsBean.consord, strutsBean.scadenza, "0", tipoOp,
  587.                         false, true, strutsBean.referente, strutsBean.versione, providersList, providersListLabel,
  588.                         strutsBean.privato, strutsBean.isServizioComposto, accordiCooperazioneEsistenti, accordiCooperazioneEsistentiLabel,
  589.                         strutsBean.accordoCooperazione, strutsBean.statoPackage, strutsBean.statoPackage, strutsBean.tipoAccordo, strutsBean.validazioneDocumenti,
  590.                         strutsBean.tipoProtocollo, listaTipiProtocollo,false,false,strutsBean.protocolFactory,
  591.                         strutsBean.serviceBinding,strutsBean.messageType,strutsBean.interfaceType, strutsBean.gruppi, elencoGruppi,
  592.                         strutsBean.nuovaVersione, gestioneNuovaVersioneMin, nuovaVersioneRidefinisciInterfaccia, gestioneNuovaVersioneOldIdApc,
  593.                         false, strutsBean.canaleStato, strutsBean.canale, canaleList, gestioneCanaliEnabled);

  594.                 // aggiunta campi custom
  595.                 dati = apcHelper.addProtocolPropertiesToDatiRegistry(dati, strutsBean.consoleConfiguration,strutsBean.consoleOperationType, strutsBean.protocolProperties);

  596.                 pd.setDati(dati);

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

  598.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC,
  599.                         ForwardParams.ADD());
  600.             }

  601.             boolean visibilitaAccordoCooperazione=false;
  602.             if(!"-".equals(strutsBean.accordoCooperazione) && !"".equals(strutsBean.accordoCooperazione)  && strutsBean.accordoCooperazione!=null){
  603.                 AccordoCooperazione ac = acCore.getAccordoCooperazione(Long.parseLong(strutsBean.accordoCooperazione));
  604.                 visibilitaAccordoCooperazione=ac.getPrivato()!=null && ac.getPrivato();
  605.             }

  606.             // Controlli sui campi immessi
  607.             boolean isOk = apcHelper.accordiCheckData(tipoOp, strutsBean.nome, strutsBean.descr, strutsBean.profcoll,
  608.                     strutsBean.wsdldef, strutsBean.wsdlconc, strutsBean.wsdlserv, strutsBean.wsdlservcorr,
  609.                     strutsBean.filtrodup, strutsBean.confric, strutsBean.idcoll, strutsBean.idRifRichiesta, strutsBean.consord,
  610.                     strutsBean.scadenza, "0",strutsBean.referente, strutsBean.versione,strutsBean.accordoCooperazione,strutsBean.privato,visibilitaAccordoCooperazione,null,
  611.                     strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr, strutsBean.validazioneDocumenti, strutsBean.tipoProtocollo,null,strutsBean.serviceBinding,strutsBean.messageType,strutsBean.interfaceType,
  612.                     showReferente, strutsBean.gruppi, strutsBean.canaleStato, strutsBean.canale, gestioneCanaliEnabled);

  613.             // updateDynamic
  614.             if(isOk) {
  615.                 if(strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE))
  616.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioParteComune(strutsBean.consoleConfiguration,
  617.                         strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  618.                         strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  619.                 else
  620.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioComposto(strutsBean.consoleConfiguration,
  621.                             strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  622.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  623.             }
  624.            
  625.             // Validazione base dei parametri custom
  626.             if(isOk){
  627.                 try{
  628.                     apcHelper.validaProtocolProperties(strutsBean.consoleConfiguration, strutsBean.consoleOperationType, strutsBean.protocolProperties);
  629.                 }catch(ProtocolException e){
  630.                     ControlStationCore.getLog().error(e.getMessage(),e);
  631.                     pd.setMessage(e.getMessage());
  632.                     isOk = false;
  633.                 }
  634.             }

  635.             // Valido i parametri custom se ho gia' passato tutta la validazione prevista
  636.             if(isOk){
  637.                 try{
  638.                     idApc = apcHelper.getIDAccordoFromValues(strutsBean.nome, strutsBean.referente, strutsBean.versione, visibilitaAccordoCooperazione);
  639.                     //validazione campi dinamici
  640.                     if(strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE))
  641.                         strutsBean.consoleDynamicConfiguration.validateDynamicConfigAccordoServizioParteComune(strutsBean.consoleConfiguration, strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  642.                                 strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  643.                     else
  644.                         strutsBean.consoleDynamicConfiguration.validateDynamicConfigAccordoServizioComposto(strutsBean.consoleConfiguration, strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  645.                                 strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  646.                 }catch(ProtocolException e){
  647.                     ControlStationCore.getLog().error(e.getMessage(),e);
  648.                     pd.setMessage(e.getMessage());
  649.                     isOk = false;
  650.                 }
  651.             }

  652.             if (!isOk) {

  653.                 // setto la barra del titolo
  654.                 ServletUtils.setPageDataTitle(pd, listaParams);

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

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

  658.                 // update della configurazione
  659.                 if(strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE))
  660.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioParteComune(strutsBean.consoleConfiguration,
  661.                         strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  662.                         strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  663.                 else
  664.                     strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioComposto(strutsBean.consoleConfiguration,
  665.                             strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  666.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc);

  667.                 dati = apcHelper.addAccordiToDati(dati, strutsBean.nome, strutsBean.descr, strutsBean.profcoll, strutsBean.wsdldef, strutsBean.wsdlconc, strutsBean.wsdlserv, strutsBean.wsdlservcorr, strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr,
  668.                         strutsBean.filtrodup, strutsBean.confric, strutsBean.idcoll, strutsBean.idRifRichiesta, strutsBean.consord, strutsBean.scadenza, "0", tipoOp,
  669.                         false, true,strutsBean.referente, strutsBean.versione, providersList, providersListLabel,
  670.                         strutsBean.privato, strutsBean.isServizioComposto, accordiCooperazioneEsistenti, accordiCooperazioneEsistentiLabel,
  671.                         strutsBean.accordoCooperazione, strutsBean.statoPackage, strutsBean.statoPackage, strutsBean.tipoAccordo, strutsBean.validazioneDocumenti,
  672.                         strutsBean.tipoProtocollo, listaTipiProtocollo,false,false,strutsBean.protocolFactory,
  673.                         strutsBean.serviceBinding,strutsBean.messageType,strutsBean.interfaceType, strutsBean.gruppi, elencoGruppi,
  674.                         strutsBean.nuovaVersione, gestioneNuovaVersioneMin, nuovaVersioneRidefinisciInterfaccia, gestioneNuovaVersioneOldIdApc,
  675.                         false, strutsBean.canaleStato, strutsBean.canale, canaleList, gestioneCanaliEnabled);

  676.                 // aggiunta campi custom
  677.                 dati = apcHelper.addProtocolPropertiesToDatiRegistry(dati, strutsBean.consoleConfiguration,strutsBean.consoleOperationType, strutsBean.protocolProperties);

  678.                 pd.setDati(dati);

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

  680.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  681.                         AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.ADD());
  682.             }
  683.            
  684.             List<Object> objectToCreate = new ArrayList<>();

  685.             AccordoServizioParteComune as = new AccordoServizioParteComune();

  686.             // preparo l'oggetto
  687.             as.setNome(strutsBean.nome);
  688.             as.setDescrizione(strutsBean.descr);

  689.             // profilo collaborazione
  690.             // controllo profilo collaborazione
  691.             strutsBean.profcoll = AccordiServizioParteComuneHelper.convertProfiloCollaborazioneView2DB(strutsBean.profcoll);
  692.             as.setProfiloCollaborazione(ProfiloCollaborazione.toEnumConstant(strutsBean.profcoll));

  693.             FormatoSpecifica formato = apcCore.interfaceType2FormatoSpecifica(strutsBean.interfaceType);
  694.            
  695.             String wsdlconcS = strutsBean.wsdlconc.getValue() != null ? new String(strutsBean.wsdlconc.getValue()) : null;
  696.             as.setByteWsdlConcettuale(apcCore.getInterfaceAsByteArray(formato, wsdlconcS));
  697.             String wsdldefS = strutsBean.wsdldef.getValue() != null ? new String(strutsBean.wsdldef.getValue()) : null;
  698.             as.setByteWsdlDefinitorio(apcCore.getInterfaceAsByteArray(formato, wsdldefS));
  699.             String wsdlservS = strutsBean.wsdlserv.getValue() != null ? new String(strutsBean.wsdlserv.getValue()) : null;
  700.             as.setByteWsdlLogicoErogatore(apcCore.getInterfaceAsByteArray(formato, wsdlservS));
  701.             String wsdlservcorrS = strutsBean.wsdlservcorr.getValue() != null ? new String(strutsBean.wsdlservcorr.getValue()) : null;
  702.             as.setByteWsdlLogicoFruitore(apcCore.getInterfaceAsByteArray(formato, wsdlservcorrS));

  703.             // Se un utente ha impostato solo il logico erogatore (avviene automaticamente nel caso non venga visualizzato il campo concettuale)
  704.             // imposto lo stesso wsdl anche per il concettuale. Tanto Rappresenta la stessa informazione, ma e' utile per lo stato dell'accordo
  705.             boolean facilityUnicoWSDLInterfacciaStandard = false;
  706.             if(as.getByteWsdlLogicoErogatore()!=null && as.getByteWsdlLogicoFruitore()==null && as.getByteWsdlConcettuale()==null){
  707.                 as.setByteWsdlConcettuale(as.getByteWsdlLogicoErogatore());
  708.                 facilityUnicoWSDLInterfacciaStandard = true;
  709.             }

  710.             // Conversione Abilitato/Disabilitato
  711.             as.setFiltroDuplicati(StatoFunzionalita.toEnumConstant(AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoView2DB(strutsBean.filtrodup)));
  712.             as.setConfermaRicezione(StatoFunzionalita.toEnumConstant(AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoView2DB(strutsBean.confric)));
  713.             as.setConsegnaInOrdine(StatoFunzionalita.toEnumConstant(AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoView2DB(strutsBean.consord)));
  714.             as.setIdCollaborazione(StatoFunzionalita.toEnumConstant(AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoView2DB(strutsBean.idcoll)));
  715.             as.setIdRiferimentoRichiesta(StatoFunzionalita.toEnumConstant(AccordiServizioParteComuneHelper.convertAbilitatoDisabilitatoView2DB(strutsBean.idRifRichiesta)));
  716.             if ((strutsBean.scadenza != null) && (!"".equals(strutsBean.scadenza)))
  717.                 as.setScadenza(strutsBean.scadenza);
  718.             as.setSuperUser(userLogin);
  719.             as.setUtilizzoSenzaAzione(true);// default true
  720.             String wsblconcS = strutsBean.wsblconc.getValue() != null ? new String(strutsBean.wsblconc.getValue()) : null;
  721.             as.setByteSpecificaConversazioneConcettuale(apcCore.getInterfaceAsByteArray(formato, wsblconcS));
  722.             String wsblservS = strutsBean.wsblserv.getValue() != null ? new String(strutsBean.wsblserv.getValue()) : null;
  723.             as.setByteSpecificaConversazioneErogatore(apcCore.getInterfaceAsByteArray(formato, wsblservS));
  724.             String wsblservcorrS = strutsBean.wsblservcorr.getValue() != null ? new String(strutsBean.wsblservcorr.getValue()) : null;
  725.             as.setByteSpecificaConversazioneFruitore(apcCore.getInterfaceAsByteArray(formato, wsblservcorrS));
  726.            
  727.             // servicebinding / messagetype / formatospecifica
  728.             as.setServiceBinding(apcCore.fromMessageServiceBinding(strutsBean.serviceBinding));
  729.             as.setMessageType(apcCore.fromMessageMessageType(strutsBean.messageType));
  730.             as.setFormatoSpecifica(formato);
  731.            
  732.             if(strutsBean.referente!=null && !"".equals(strutsBean.referente) && !"-".equals(strutsBean.referente)){
  733.                 int idRef = 0;
  734.                 try {
  735.                     idRef = Integer.parseInt(strutsBean.referente);
  736.                 } catch (Exception e) {
  737.                 }
  738.                 if (idRef != 0) {
  739.                     int idReferente = Integer.parseInt(strutsBean.referente);
  740.                     Soggetto s = soggettiCore.getSoggetto(idReferente);        
  741.                     IdSoggetto assr = new IdSoggetto();
  742.                     assr.setTipo(s.getTipo());
  743.                     assr.setNome(s.getNome());
  744.                     as.setSoggettoReferente(assr);
  745.                 }
  746.             }else{              
  747.                 if(!showReferente) {
  748.                     // Recupero Soggetto Default
  749.                     IDSoggetto idSoggetto = apcCore.getSoggettoOperativoDefault(userLogin, strutsBean.tipoProtocollo);
  750.                     Soggetto s = soggettiCore.getSoggetto(idSoggetto);
  751.                     IdSoggetto assr = new IdSoggetto();
  752.                     assr.setTipo(s.getTipo());
  753.                     assr.setNome(s.getNome());
  754.                     as.setSoggettoReferente(assr);
  755.                 }
  756.                 else {
  757.                     as.setSoggettoReferente(null);
  758.                 }
  759.             }
  760.             if(strutsBean.versione!=null){
  761.                 as.setVersione(Integer.parseInt(strutsBean.versione));
  762.             }
  763.             as.setPrivato(strutsBean.privato ? Boolean.TRUE : Boolean.FALSE);

  764.             if(strutsBean.accordoCooperazione!=null && !"".equals(strutsBean.accordoCooperazione) && !"-".equals(strutsBean.accordoCooperazione)){
  765.                 AccordoServizioParteComuneServizioComposto assc = new AccordoServizioParteComuneServizioComposto();
  766.                 assc.setIdAccordoCooperazione(Long.parseLong(strutsBean.accordoCooperazione));
  767.                 as.setServizioComposto(assc);
  768.             }

  769.             // stato
  770.             as.setStatoPackage(strutsBean.statoPackage);

  771.             // gruppi
  772.             if(StringUtils.isNotEmpty(strutsBean.gruppi)) {
  773.                 if(as.getGruppi() == null)
  774.                     as.setGruppi(new GruppiAccordo());
  775.            
  776.                 List<String> nomiGruppi = Arrays.asList(strutsBean.gruppi.split(","));
  777.                
  778.                 for (String nomeGruppo : nomiGruppi) {
  779.                     if(!gruppiCore.existsGruppo(nomeGruppo)) {
  780.                         Gruppo nuovoGruppo = new Gruppo();
  781.                         nuovoGruppo.setNome(nomeGruppo);
  782.                         nuovoGruppo.setSuperUser(userLogin);
  783.                         objectToCreate.add(nuovoGruppo);
  784.                     }
  785.                    
  786.                     GruppoAccordo gruppoAccordo = new GruppoAccordo();
  787.                     gruppoAccordo.setNome(nomeGruppo);
  788.                     as.getGruppi().addGruppo(gruppoAccordo );
  789.                 }
  790.             }
  791.            
  792.             // canale
  793.             if(gestioneCanaliEnabled) {
  794.                 if(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_RIDEFINITO.equals(strutsBean.canaleStato)) {
  795.                     as.setCanale(strutsBean.canale);
  796.                 } else {
  797.                     as.setCanale(null);
  798.                 }
  799.             } else {
  800.                 as.setCanale(null);
  801.             }

  802.             if(strutsBean.nuovaVersione && !nuovaVersioneRidefinisciInterfaccia) {
  803.                 IDAccordo idAcc = apcCore.getIdAccordoServizio(gestioneNuovaVersioneOldIdApc);
  804.                 AccordoServizioParteComune aspcOld = apcCore.getAccordoServizioFull(idAcc, true); // devo leggere anche gli allegati
  805.                 as.setAllegatoList(aspcOld.getAllegatoList());
  806.                 as.setSpecificaSemiformaleList(aspcOld.getSpecificaSemiformaleList());
  807.                 as.setAzioneList(aspcOld.getAzioneList());
  808.                 as.setPortTypeList(aspcOld.getPortTypeList());
  809.                 as.setResourceList(aspcOld.getResourceList());
  810.                 as.setByteWsdlDefinitorio(aspcOld.getByteWsdlDefinitorio());
  811.                 as.setByteWsdlConcettuale(aspcOld.getByteWsdlConcettuale());
  812.                 as.setByteWsdlLogicoErogatore(aspcOld.getByteWsdlLogicoErogatore());
  813.                 as.setByteWsdlLogicoFruitore(aspcOld.getByteWsdlLogicoFruitore());
  814.                 as.setByteSpecificaConversazioneConcettuale(aspcOld.getByteSpecificaConversazioneConcettuale());
  815.                 as.setByteSpecificaConversazioneErogatore(aspcOld.getByteSpecificaConversazioneErogatore());
  816.                 as.setByteSpecificaConversazioneFruitore(aspcOld.getByteSpecificaConversazioneFruitore());
  817.             }
  818.            

  819.             // Check stato
  820.             if(apcHelper.isShowGestioneWorkflowStatoDocumenti()){

  821.                 try{
  822.                     boolean utilizzoAzioniDiretteInAccordoAbilitato = apcCore.isShowAccordiColonnaAzioni();
  823.                     apcCore.validaStatoAccordoServizio(as, utilizzoAzioniDiretteInAccordoAbilitato, true);
  824.                 }catch(ValidazioneStatoPackageException validazioneException){

  825.                     // Setto messaggio di errore
  826.                     pd.setMessage(validazioneException.toString());

  827.                     // setto la barra del titolo
  828.                     ServletUtils.setPageDataTitle(pd, listaParams);

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

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

  832.                     // update della configurazione
  833.                     if(strutsBean.tipoAccordo.equals(ProtocolPropertiesCostanti.PARAMETRO_VALORE_PP_TIPO_ACCORDO_PARTE_COMUNE))
  834.                         strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioParteComune(strutsBean.consoleConfiguration,
  835.                             strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  836.                             strutsBean.registryReader, strutsBean.configRegistryReader, idApc);
  837.                     else
  838.                         strutsBean.consoleDynamicConfiguration.updateDynamicConfigAccordoServizioComposto(strutsBean.consoleConfiguration,
  839.                                 strutsBean.consoleOperationType, apcHelper, strutsBean.protocolProperties,
  840.                                 strutsBean.registryReader, strutsBean.configRegistryReader, idApc);

  841.                     dati = apcHelper.addAccordiToDati(dati, strutsBean.nome, strutsBean.descr, strutsBean.profcoll, strutsBean.wsdldef, strutsBean.wsdlconc, strutsBean.wsdlserv, strutsBean.wsdlservcorr, strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr,
  842.                             strutsBean.filtrodup, strutsBean.confric, strutsBean.idcoll, strutsBean.idRifRichiesta, strutsBean.consord, strutsBean.scadenza, "0", tipoOp,
  843.                             false, true,strutsBean.referente, strutsBean.versione, providersList, providersListLabel,
  844.                             strutsBean.privato, strutsBean.isServizioComposto, accordiCooperazioneEsistenti, accordiCooperazioneEsistentiLabel,
  845.                             strutsBean.accordoCooperazione, strutsBean.statoPackage, strutsBean.statoPackage, strutsBean.tipoAccordo, strutsBean.validazioneDocumenti,
  846.                             strutsBean.tipoProtocollo, listaTipiProtocollo,false,false,strutsBean.protocolFactory,
  847.                             strutsBean.serviceBinding,strutsBean.messageType,strutsBean.interfaceType, strutsBean.gruppi, elencoGruppi,
  848.                             strutsBean.nuovaVersione, gestioneNuovaVersioneMin, nuovaVersioneRidefinisciInterfaccia, gestioneNuovaVersioneOldIdApc,
  849.                             false, strutsBean.canaleStato, strutsBean.canale, canaleList, gestioneCanaliEnabled);

  850.                     // aggiunta campi custom
  851.                     dati = apcHelper.addProtocolPropertiesToDatiRegistry(dati, strutsBean.consoleConfiguration,strutsBean.consoleOperationType, strutsBean.protocolProperties);

  852.                     pd.setDati(dati);

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

  854.                     return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.ADD());

  855.                 }
  856.             }

  857.             // Automapping
  858.             if(!strutsBean.nuovaVersione || nuovaVersioneRidefinisciInterfaccia) {
  859.                 AccordiServizioParteComuneUtilities.mapppingAutomaticoInterfaccia(as, apcCore,
  860.                         enableAutoMapping, strutsBean.validazioneDocumenti, enableAutoMappingEstraiXsdSchemiFromWsdlTypes, facilityUnicoWSDLInterfacciaStandard,
  861.                         strutsBean.tipoProtocollo, strutsBean.interfaceType);
  862.             }

  863.             //imposto properties custom
  864.             as.setProtocolPropertyList(ProtocolPropertiesUtils.toProtocolPropertiesRegistry(strutsBean.protocolProperties, strutsBean.consoleOperationType,null));
  865.            
  866.             objectToCreate.add(as);
  867.             // effettuo le operazioni
  868.             apcCore.performCreateOperation(userLogin, apcHelper.smista(), objectToCreate.toArray(new Object[objectToCreate.size()]));
  869.            
  870.             // cancello i file temporanei
  871.             apcHelper.deleteBinaryParameters(strutsBean.wsdlconc,strutsBean.wsdldef,strutsBean.wsdlserv,strutsBean.wsdlservcorr,strutsBean.wsblconc,strutsBean.wsblserv,strutsBean.wsblservcorr);
  872.             apcHelper.deleteBinaryProtocolPropertiesTmpFiles(strutsBean.protocolProperties);

  873.             // Verifico stato
  874.             boolean incomplete = apcHelper.setMessageWarningStatoConsistenzaAccordo(true, as);
  875.            
  876.             // Preparo la lista
  877.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  878.             if(incomplete || apcCore.isSetSearchAfterAdd()) {
  879.                 apcCore.setSearchAfterAdd(Liste.ACCORDI, as.getNome(), request, session, ricerca);
  880.             }
  881.            
  882.             List<AccordoServizioParteComuneSintetico> lista = AccordiServizioParteComuneUtilities.accordiList(apcCore, userLogin, ricerca, strutsBean.tipoAccordo);

  883.             if(isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) {
  884.                 apcHelper.prepareApiList(lista, ricerca, strutsBean.tipoAccordo);
  885.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  886.                 return ServletUtils.getStrutsForwardEditModeFinished(mapping, ApiCostanti.OBJECT_NAME_APC_API, ForwardParams.ADD());
  887.             }
  888.            
  889.             apcHelper.prepareAccordiList(lista, ricerca, strutsBean.tipoAccordo);

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

  891.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.ADD());

  892.         } catch (Exception e) {
  893.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  894.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.ADD());
  895.         }

  896.     }
  897. }