BasicArchive.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.protocol.basic.archive;

  21. import java.io.InputStream;
  22. import java.io.OutputStream;
  23. import java.util.ArrayList;
  24. import java.util.HashMap;
  25. import java.util.Iterator;
  26. import java.util.List;
  27. import java.util.Map;

  28. import javax.wsdl.BindingOperation;
  29. import javax.xml.namespace.QName;

  30. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  31. import org.openspcoop2.core.registry.Operation;
  32. import org.openspcoop2.core.registry.PortType;
  33. import org.openspcoop2.core.registry.Resource;
  34. import org.openspcoop2.core.registry.ResourceParameter;
  35. import org.openspcoop2.core.registry.ResourceRepresentation;
  36. import org.openspcoop2.core.registry.ResourceRepresentationJson;
  37. import org.openspcoop2.core.registry.ResourceRepresentationXml;
  38. import org.openspcoop2.core.registry.ResourceRequest;
  39. import org.openspcoop2.core.registry.ResourceResponse;
  40. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  41. import org.openspcoop2.core.registry.constants.FormatoSpecifica;
  42. import org.openspcoop2.core.registry.constants.HttpMethod;
  43. import org.openspcoop2.core.registry.constants.ParameterType;
  44. import org.openspcoop2.core.registry.constants.ProfiloCollaborazione;
  45. import org.openspcoop2.core.registry.constants.RepresentationType;
  46. import org.openspcoop2.core.registry.constants.RepresentationXmlType;
  47. import org.openspcoop2.core.registry.constants.ServiceBinding;
  48. import org.openspcoop2.core.registry.driver.IDAccordoCooperazioneFactory;
  49. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  50. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  51. import org.openspcoop2.core.registry.wsdl.AccordoServizioWrapperUtilities;
  52. import org.openspcoop2.message.xml.MessageXMLUtils;
  53. import org.openspcoop2.protocol.basic.BasicComponentFactory;
  54. import org.openspcoop2.protocol.basic.Costanti;
  55. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  56. import org.openspcoop2.protocol.sdk.ProtocolException;
  57. import org.openspcoop2.protocol.sdk.archive.Archive;
  58. import org.openspcoop2.protocol.sdk.archive.ArchiveEsitoDelete;
  59. import org.openspcoop2.protocol.sdk.archive.ArchiveEsitoImport;
  60. import org.openspcoop2.protocol.sdk.archive.ArchiveMode;
  61. import org.openspcoop2.protocol.sdk.archive.ArchiveModeType;
  62. import org.openspcoop2.protocol.sdk.archive.ExportMode;
  63. import org.openspcoop2.protocol.sdk.archive.IArchive;
  64. import org.openspcoop2.protocol.sdk.archive.ImportMode;
  65. import org.openspcoop2.protocol.sdk.archive.MapPlaceholder;
  66. import org.openspcoop2.protocol.sdk.archive.MappingModeTypesExtensions;
  67. import org.openspcoop2.protocol.sdk.constants.ArchiveType;
  68. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;
  69. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  70. import org.openspcoop2.utils.rest.ApiFactory;
  71. import org.openspcoop2.utils.rest.ApiFormats;
  72. import org.openspcoop2.utils.rest.ApiReaderConfig;
  73. import org.openspcoop2.utils.rest.IApiReader;
  74. import org.openspcoop2.utils.rest.ParseWarningException;
  75. import org.openspcoop2.utils.rest.api.Api;
  76. import org.openspcoop2.utils.rest.api.ApiBodyParameter;
  77. import org.openspcoop2.utils.rest.api.ApiCookieParameter;
  78. import org.openspcoop2.utils.rest.api.ApiHeaderParameter;
  79. import org.openspcoop2.utils.rest.api.ApiOperation;
  80. import org.openspcoop2.utils.rest.api.ApiReference;
  81. import org.openspcoop2.utils.rest.api.ApiRequestDynamicPathParameter;
  82. import org.openspcoop2.utils.rest.api.ApiRequestFormParameter;
  83. import org.openspcoop2.utils.rest.api.ApiRequestQueryParameter;
  84. import org.openspcoop2.utils.rest.api.ApiResponse;
  85. import org.openspcoop2.utils.transport.http.HttpRequestMethod;
  86. import org.openspcoop2.utils.wsdl.DefinitionWrapper;
  87. import org.openspcoop2.utils.wsdl.WSDLUtilities;
  88. import org.openspcoop2.utils.xml.AbstractXMLUtils;
  89. import org.slf4j.Logger;
  90. import org.w3c.dom.Document;

  91. /**
  92.  *  BasicArchive
  93.  *
  94.  * @author Poli Andrea (apoli@link.it)
  95.  * @author $Author$
  96.  * @version $Rev$, $Date$
  97.  */
  98. public class BasicArchive extends BasicComponentFactory implements IArchive {

  99.     protected IDAccordoCooperazioneFactory idAccordoCooperazioneFactory;
  100.     protected IDAccordoFactory idAccordoFactory;
  101.     protected IDServizioFactory idServizioFactory;
  102.     protected EsitoUtils esitoUtils;
  103.     public BasicArchive(IProtocolFactory<?> protocolFactory) throws ProtocolException{
  104.         super(protocolFactory);
  105.         this.idAccordoCooperazioneFactory = IDAccordoCooperazioneFactory.getInstance();
  106.         this.idAccordoFactory = IDAccordoFactory.getInstance();
  107.         this.idServizioFactory = IDServizioFactory.getInstance();
  108.         this.esitoUtils = new EsitoUtils(protocolFactory);
  109.     }

  110.    
  111.    
  112.    
  113.     /* ----- Utilita' generali ----- */
  114.    
  115.     @Override
  116.     public MappingModeTypesExtensions getMappingTypesExtensions(ArchiveMode mode)
  117.             throws ProtocolException {
  118.         MappingModeTypesExtensions m = new MappingModeTypesExtensions();
  119.         m.add(Costanti.OPENSPCOOP_ARCHIVE_EXT, Costanti.OPENSPCOOP_ARCHIVE_MODE_TYPE);
  120.         return m;
  121.     }
  122.    
  123.     private static boolean normalizeDescription255 = false;
  124.     public static boolean isNormalizeDescription255() {
  125.         return normalizeDescription255;
  126.     }
  127.     public static void setNormalizeDescription255(boolean normalizeDescription255) {
  128.         BasicArchive.normalizeDescription255 = normalizeDescription255;
  129.     }
  130.     private static boolean normalizeDescription4000 = false;
  131.     public static boolean isNormalizeDescription4000() {
  132.         return normalizeDescription4000;
  133.     }
  134.     public static void setNormalizeDescription4000(boolean normalizeDescription4000) {
  135.         BasicArchive.normalizeDescription4000 = normalizeDescription4000;
  136.     }
  137.     private String normalizeDescriptionApi(String description) {
  138.         if(BasicArchive.normalizeDescription255) {
  139.             return normalizeDescriptionEngine(description, 255);
  140.         }
  141.         else if(BasicArchive.normalizeDescription4000) {
  142.             return normalizeDescriptionEngine(description, 4000);
  143.         }
  144.         else {
  145.             return description;
  146.         }
  147.     }
  148.     private String normalizeDescriptionOtherElementApi(String description) {
  149.         return normalizeDescriptionEngine(description, 255);
  150.     }
  151.     private String normalizeDescriptionEngine(String description, int maxSize) {
  152.         if(description==null) {
  153.             return null;
  154.         }
  155.          String descr = description;
  156.          while(descr.contains("\r")) {
  157.              descr = descr.replace("\r", "");
  158.          }
  159.          int offset = 15; // uso maxSize-15 per essere sicuro che finisca in oracle con caratteri strani (value too large for column "GOVWAY330"."ACCORDI"."DESCRIZIONE" (actual: 257, maximum: 255))
  160.          if(descr.length()<=(maxSize-offset)) {
  161.              return descr;
  162.          }
  163.          else {
  164.              int ulterioreOffset = 10;
  165.              if(maxSize==4000) {
  166.                  ulterioreOffset = 50;
  167.              }
  168.              return descr.substring(0, ((maxSize-ulterioreOffset)-offset))+ " ...";
  169.          }
  170.     }
  171.    
  172.     /**
  173.      * Imposta per ogni portType e operation presente nell'accordo fornito come parametro
  174.      * le informazioni di protocollo analizzando i documenti interni agli archivi
  175.      */
  176.     @Override
  177.     public void setProtocolInfo(AccordoServizioParteComune accordoServizioParteComune) throws ProtocolException{
  178.         setProtocolInfoEngine(accordoServizioParteComune, this.protocolFactory.getLogger());
  179.     }
  180.     public void setProtocolInfo(AccordoServizioParteComune accordoServizioParteComune,Logger log) throws ProtocolException{
  181.         setProtocolInfoEngine(accordoServizioParteComune, log);
  182.     }
  183.     private void setProtocolInfoEngine(AccordoServizioParteComune accordoServizioParteComune,Logger log) throws ProtocolException{
  184.        
  185.         // NOTA non usare in questo metodo e nel metodo _setProtocolInfo il protocolFactory e dipendenze su di uno specifico protocollo.
  186.         //      Viene usato dal meccanismo di import per definire la struttura di un accordo in base al wsdl, indipendentemente dallo specifico protocollo
  187.        

  188.        
  189.         if(ServiceBinding.SOAP.equals(accordoServizioParteComune.getServiceBinding())) {
  190.        
  191.             if(accordoServizioParteComune.sizePortTypeList()>0){
  192.                 throw new ProtocolException("Protocol Info already exists");
  193.             }
  194.            
  195.             if(accordoServizioParteComune.getFormatoSpecifica()==null || FormatoSpecifica.WSDL_11.equals(accordoServizioParteComune.getFormatoSpecifica())) {
  196.                 byte[] wsdlConcettuale = accordoServizioParteComune.getByteWsdlConcettuale();
  197.                 if(wsdlConcettuale!=null){
  198.                     setProtocolInfoFromWsdlEngine(wsdlConcettuale, accordoServizioParteComune, "Concettuale", log);
  199.                 }
  200.                 else{
  201.                     if(accordoServizioParteComune.getByteWsdlLogicoErogatore()!=null){
  202.                         setProtocolInfoFromWsdlEngine(accordoServizioParteComune.getByteWsdlLogicoErogatore(), accordoServizioParteComune, "LogicoErogatore", log);
  203.                     }
  204.                     if(accordoServizioParteComune.getByteWsdlLogicoFruitore()!=null){
  205.                         setProtocolInfoFromWsdlEngine(accordoServizioParteComune.getByteWsdlLogicoFruitore(), accordoServizioParteComune, "LogicoFruitore", log);
  206.                     }
  207.                 }
  208.             }
  209.            
  210.         }
  211.         else {
  212.            
  213.             if(accordoServizioParteComune.sizeResourceList()>0){
  214.                 throw new ProtocolException("Protocol Info already exists");
  215.             }
  216.            
  217.             if(accordoServizioParteComune.getFormatoSpecifica()!=null) {
  218.                
  219.                 byte[] wsdlConcettuale = accordoServizioParteComune.getByteWsdlConcettuale();
  220.                 if(wsdlConcettuale!=null){
  221.                     switch (accordoServizioParteComune.getFormatoSpecifica()) {
  222.                     case WADL:
  223.                         setProtocolInfoFromRestInterfaceEngine(wsdlConcettuale, accordoServizioParteComune, ApiFormats.WADL, log);
  224.                         break;
  225.                     case SWAGGER_2:
  226.                         setProtocolInfoFromRestInterfaceEngine(wsdlConcettuale, accordoServizioParteComune, ApiFormats.SWAGGER_2, log);
  227.                         break;
  228.                     case OPEN_API_3:
  229.                         setProtocolInfoFromRestInterfaceEngine(wsdlConcettuale, accordoServizioParteComune, ApiFormats.OPEN_API_3, log);
  230.                         break;
  231.                     default:
  232.                         // altre interfacce non supportate per rest
  233.                         break;
  234.                     }
  235.                 }
  236.                
  237.             }
  238.            
  239.         }
  240.     }
  241.     private void setProtocolInfoFromWsdlEngine(byte [] wsdlBytes,AccordoServizioParteComune accordoServizioParteComune,String tipo,Logger log) throws ProtocolException{
  242.        
  243.         try{
  244.        
  245.             AbstractXMLUtils xmlUtils = MessageXMLUtils.DEFAULT;
  246.             WSDLUtilities wsdlUtilities = new WSDLUtilities(xmlUtils);
  247.             Document d = xmlUtils.newDocument(wsdlBytes);
  248.             wsdlUtilities.removeTypes(d);
  249.             DefinitionWrapper wsdl = new DefinitionWrapper(d,xmlUtils,false,false);
  250.            
  251.             // port types
  252.             Map<?, ?> porttypesWSDL = wsdl.getAllPortTypes();
  253.             if(porttypesWSDL==null || porttypesWSDL.size()<=0){
  254.                 throw new ProtocolException("WSDL"+tipo+" corrotto: non contiene la definizione di nessun port-type");
  255.             }
  256.             if(porttypesWSDL!=null && porttypesWSDL.size()>0){
  257.    
  258.                 Iterator<?> it = porttypesWSDL.keySet().iterator();
  259.                 while(it.hasNext()){
  260.                     javax.xml.namespace.QName key = (javax.xml.namespace.QName) it.next();
  261.                     javax.wsdl.PortType ptWSDL = (javax.wsdl.PortType) porttypesWSDL.get(key);
  262.                     String ptName = ptWSDL.getQName().getLocalPart();
  263.                    
  264.                     // cerco portType
  265.                     boolean foundPortType = false;
  266.                     PortType ptOpenSPCoop = null;
  267.                     for (PortType ptCheck : accordoServizioParteComune.getPortTypeList()) {
  268.                         if(ptCheck.getNome().equals(ptName)){
  269.                             ptOpenSPCoop = ptCheck;
  270.                             foundPortType = true;
  271.                             break;
  272.                         }
  273.                     }
  274.                    
  275.                     // cerco binding (se il wsdl contiene la parte implementativa)
  276.                     Map<?, ?> bindingsWSDL = wsdl.getAllBindings();
  277.                     javax.wsdl.Binding bindingWSDL = null;
  278.                     if(bindingsWSDL!=null && bindingsWSDL.size()>0){
  279.                         Iterator<?> itBinding = bindingsWSDL.keySet().iterator();
  280.                         while (itBinding.hasNext()) {
  281.                             javax.xml.namespace.QName tmp = (javax.xml.namespace.QName) itBinding.next();
  282.                             if(tmp!=null){
  283.                                 javax.wsdl.Binding tmpBinding = wsdl.getBinding(tmp);
  284.                                 if(tmpBinding!=null && tmpBinding.getPortType()!=null &&
  285.                                         tmpBinding.getPortType().getQName()!=null &&
  286.                                         ptName.equals(tmpBinding.getPortType().getQName().getLocalPart())){
  287.                                     bindingWSDL = tmpBinding;
  288.                                     break;
  289.                                 }
  290.                             }
  291.                         }
  292.                     }
  293.                    
  294.                     // se non esiste creo il port-type
  295.                     if(ptOpenSPCoop==null){
  296.                         ptOpenSPCoop = new PortType();
  297.                         ptOpenSPCoop.setNome(ptName);
  298.                         ptOpenSPCoop.setProfiloCollaborazione(CostantiRegistroServizi.SINCRONO);
  299.                         ptOpenSPCoop.setProfiloPT(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  300.                         ptOpenSPCoop.setFiltroDuplicati(CostantiRegistroServizi.ABILITATO);                
  301.                     }
  302.                    
  303.                     // Calcolo profilo del port-type
  304.                     ProfiloCollaborazione profiloPt = accordoServizioParteComune.getProfiloCollaborazione();
  305.                     if(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO.equals(ptOpenSPCoop.getProfiloPT()) && ptOpenSPCoop.getProfiloCollaborazione()!=null) {
  306.                         profiloPt = ptOpenSPCoop.getProfiloCollaborazione();
  307.                     }
  308.                    
  309.                     // SoapBinding
  310.                     if(bindingWSDL!=null){
  311.                         AccordoServizioWrapperUtilities.setPortTypeSoapBindingStyle(bindingWSDL, log, ptOpenSPCoop);
  312.                     }
  313.                    
  314.                     // itero sulle operation
  315.                     for(int i=0; i<ptWSDL.getOperations().size();i++){
  316.                         javax.wsdl.Operation opWSDL = (javax.wsdl.Operation) ptWSDL.getOperations().get(i);
  317.                         String opNome = opWSDL.getName();
  318.                        
  319.                         boolean foundOperation = false;
  320.                         Operation opOpenSPCoop = null;
  321.                         for (Operation opCheck : ptOpenSPCoop.getAzioneList()) {
  322.                             if(opCheck.getNome().equals(opNome)){
  323.                                 foundOperation = true;
  324.                                 break;
  325.                             }
  326.                         }
  327.                         if(foundOperation){
  328.                             continue;// gia definito in un altro wsdl (normale e correlato) ??
  329.                         }
  330.                        
  331.                         // imposto dati base operazione
  332.                         opOpenSPCoop = new Operation();
  333.                         opOpenSPCoop.setNome(opNome);
  334.                         opOpenSPCoop.setProfAzione(CostantiRegistroServizi.PROFILO_AZIONE_RIDEFINITO);
  335.                         opOpenSPCoop.setFiltroDuplicati(CostantiRegistroServizi.ABILITATO);
  336.                        
  337.                         // Prendo la definizione del messaggio di input
  338.                         HashMap<String,QName> mapPartQNameInput = new HashMap<>();
  339.                         AccordoServizioWrapperUtilities.addMessageInputOperation(opWSDL, log, opOpenSPCoop, mapPartQNameInput);
  340.                        
  341.                         // Prendo la definizione del messaggio di output
  342.                         HashMap<String,QName> mapPartQNameOutput = new HashMap<>();
  343.                         AccordoServizioWrapperUtilities.addMessageOutputOperation(opWSDL, log, opOpenSPCoop, mapPartQNameOutput);
  344.                        
  345.                         // profilo di collaborazione (non basta guardare l'output, poiche' puo' avere poi un message vuoto e quindi equivale a non avere l'output)
  346.                         /**if(opWSDL.getOutput()!=null){*/
  347.                         ProfiloCollaborazione profiloOp = null;
  348.                         if(opOpenSPCoop.getMessageOutput()!=null){
  349.                             profiloOp = CostantiRegistroServizi.SINCRONO;
  350.                         }else{
  351.                             profiloOp = CostantiRegistroServizi.ONEWAY;
  352.                         }
  353.                         opOpenSPCoop.setProfiloCollaborazione(profiloOp);
  354.                         if(profiloPt.equals(profiloOp)) {
  355.                             opOpenSPCoop.setProfAzione(CostantiRegistroServizi.PROFILO_AZIONE_DEFAULT);
  356.                         }
  357.                        
  358.                         // cerco operation binding (se il wsdl contiene la parte implementativa)
  359.                         if(bindingWSDL!=null){
  360.                                
  361.                             List<?> bindingsOperation = bindingWSDL.getBindingOperations();
  362.                             for(int j=0; j<bindingsOperation.size();j++){
  363.                                 BindingOperation bindingOperationWSDL = (BindingOperation) bindingsOperation.get(j);
  364.                                
  365.                                 if(bindingOperationWSDL.getOperation()!=null &&
  366.                                         opNome.equals(bindingOperationWSDL.getOperation().getName())){
  367.                                
  368.                                     // SoapBinding Operation
  369.                                     AccordoServizioWrapperUtilities.
  370.                                         setOperationSoapBindingInformation(bindingOperationWSDL, log,
  371.                                                 opOpenSPCoop, ptOpenSPCoop);
  372.                                    
  373.                                     // Raccolgo Message-Input
  374.                                     if(opOpenSPCoop.getMessageInput()!=null){
  375.                                         AccordoServizioWrapperUtilities.
  376.                                             setMessageInputSoapBindingInformation(bindingOperationWSDL, log,
  377.                                                     opOpenSPCoop, ptOpenSPCoop, mapPartQNameInput,
  378.                                                     wsdl.getTargetNamespace());
  379.                                     }
  380.                                    
  381.                                     // Raccolgo Message-Output
  382.                                     if(opOpenSPCoop.getMessageOutput()!=null){
  383.                                         AccordoServizioWrapperUtilities.
  384.                                             setMessageOutputSoapBindingInformation(bindingOperationWSDL, log,
  385.                                                     opOpenSPCoop, ptOpenSPCoop, mapPartQNameOutput,
  386.                                                     wsdl.getTargetNamespace());
  387.                                     }
  388.                                    
  389.                                 }
  390.                             }
  391.                         }
  392.                        
  393.                         // aggiunto l'azione al port type
  394.                         ptOpenSPCoop.addAzione(opOpenSPCoop);
  395.                        
  396.                     }
  397.                    
  398.                     if(!foundPortType){
  399.                         accordoServizioParteComune.addPortType(ptOpenSPCoop);
  400.                     }
  401.                    
  402.                 }
  403.             }
  404.         }catch(Exception e){
  405.             throw new ProtocolException(e.getMessage(),e);
  406.         }
  407.     }
  408.    
  409.     private static final String TROVATO_PARAMETRO_COOKIE_PREFIX = "Trovato parametro cookie '";
  410.     private static final String TROVATO_PARAMETRO_HEADER_PREFIX = "Trovato parametro header '";
  411.     private static final String SENZA_TIPO_SUFFIX = "' senza tipo";
  412.     private static final String SENZA_SCHEMA_SUFFIX = "' senza schema";
  413.    
  414.     private void setProtocolInfoFromRestInterfaceEngine(byte [] bytes,AccordoServizioParteComune accordoServizioParteComune,ApiFormats format,Logger log) throws ProtocolException{
  415.        
  416.         try {
  417.            
  418.             ApiReaderConfig config = new ApiReaderConfig();
  419.             config.setProcessInclude(false);
  420.            
  421.             IApiReader apiReader = ApiFactory.newApiReader(format);
  422.             apiReader.init(log, bytes, config);
  423.            
  424.              Api api = apiReader.read();
  425.              try {
  426.                  boolean usingFromSetProtocolInfo = true;
  427.                  api.validate(usingFromSetProtocolInfo, false);
  428.              }catch(ParseWarningException warning) {
  429.                  // ignore
  430.              }
  431.              
  432.              if(
  433.                 (accordoServizioParteComune.getDescrizione()==null || "".equals(accordoServizioParteComune.getDescrizione()))
  434.                 &&
  435.                 (api.getDescription()!=null)
  436.                  ){
  437.                  accordoServizioParteComune.setDescrizione(this.normalizeDescriptionApi(api.getDescription()));
  438.              }
  439.              
  440.              if(api.sizeOperations()>0) {
  441.                  for (ApiOperation apiOp : api.getOperations()) {
  442.                    
  443.                     // cerco resource
  444.                     Resource resourceOpenSPCoop = null;
  445.                     for (Resource resourceCheck : accordoServizioParteComune.getResourceList()) {
  446.                         if(resourceCheck.getPath()!=null && resourceCheck.getMethod()!=null) {
  447.                             HttpRequestMethod httpMethodCheck = HttpRequestMethod.valueOf(resourceCheck.getMethod().getValue());
  448.                             if(resourceCheck.getPath().equals(apiOp.getPath()) &&
  449.                                     httpMethodCheck!=null &&
  450.                                     httpMethodCheck.equals(apiOp.getHttpMethod())) {
  451.                                 resourceOpenSPCoop = resourceCheck;
  452.                                 break;
  453.                             }
  454.                         }
  455.                     }
  456.                    
  457.                     // se non esiste creo la risorsa
  458.                     if(resourceOpenSPCoop==null){
  459.                         resourceOpenSPCoop = new Resource();
  460.                         resourceOpenSPCoop.setNome(APIUtils.normalizeResourceName(apiOp.getHttpMethod(), apiOp.getPath()));
  461.                         resourceOpenSPCoop.setDescrizione(this.normalizeDescriptionOtherElementApi(apiOp.getDescription()));    
  462.                         resourceOpenSPCoop.setMethod(HttpMethod.toEnumConstant(apiOp.getHttpMethod().name()));
  463.                         resourceOpenSPCoop.setPath(apiOp.getPath());
  464.                         accordoServizioParteComune.addResource(resourceOpenSPCoop);
  465.                     }

  466.                     // Richiesta
  467.                     if(resourceOpenSPCoop.getRequest()==null) {
  468.                         resourceOpenSPCoop.setRequest(new ResourceRequest());
  469.                     }
  470.                     if(apiOp.getRequest()!=null) {
  471.                        
  472.                         if(apiOp.getRequest().sizeBodyParameters()>0) {
  473.                             for (ApiBodyParameter body : apiOp.getRequest().getBodyParameters()) {
  474.                                 String mediaType = body.getMediaType();
  475.                                 ResourceRepresentation rr = null;
  476.                                 for (ResourceRepresentation rrCheck : resourceOpenSPCoop.getRequest().getRepresentationList()) {
  477.                                     if(mediaType.equals(rrCheck.getMediaType())) {
  478.                                         rr = rrCheck;
  479.                                         break;
  480.                                     }
  481.                                 }
  482.                                 if(rr==null) {
  483.                                     rr = new ResourceRepresentation();
  484.                                     rr.setMediaType(mediaType);
  485.                                     resourceOpenSPCoop.getRequest().addRepresentation(rr);
  486.                                 }
  487.                                 rr.setNome(body.getName());
  488.                                 rr.setDescrizione(this.normalizeDescriptionOtherElementApi(body.getDescription()));
  489.                                 if(body.getElement()!=null) {
  490.                                     if(body.getElement() instanceof QName) {
  491.                                         QName qname = (QName)body.getElement();
  492.                                         rr.setRepresentationType(RepresentationType.XML);
  493.                                         ResourceRepresentationXml xml = new ResourceRepresentationXml();
  494.                                         xml.setXmlType(RepresentationXmlType.ELEMENT);
  495.                                         xml.setNome(qname.getLocalPart());
  496.                                         xml.setNamespace(qname.getNamespaceURI());
  497.                                         rr.setXml(xml);
  498.                                     }
  499.                                     else if(body.getElement() instanceof String) {
  500.                                         String jsonType = (String)body.getElement();
  501.                                         rr.setRepresentationType(RepresentationType.JSON);
  502.                                         ResourceRepresentationJson json = new ResourceRepresentationJson();
  503.                                         json.setTipo(jsonType);
  504.                                         rr.setJson(json);
  505.                                     }
  506.                                     else if(body.getElement() instanceof ApiReference) {
  507.                                         ApiReference apiRef = (ApiReference) body.getElement();
  508.                                         String jsonType = apiRef.getType();
  509.                                         rr.setRepresentationType(RepresentationType.JSON);
  510.                                         ResourceRepresentationJson json = new ResourceRepresentationJson();
  511.                                         json.setTipo(apiRef.getSchemaRef()+"#"+jsonType);
  512.                                         rr.setJson(json);
  513.                                     }
  514.                                     else {
  515.                                         rr.setRepresentationType(null);
  516.                                         rr.setJson(null);
  517.                                         rr.setXml(null);
  518.                                     }
  519.                                 }
  520.                                 else {
  521.                                     rr.setRepresentationType(null);
  522.                                     rr.setJson(null);
  523.                                     rr.setXml(null);
  524.                                 }
  525.                             }
  526.                         }

  527.                         if(apiOp.getRequest().sizeCookieParameters()>0) {
  528.                             for (ApiCookieParameter cookie : apiOp.getRequest().getCookieParameters()) {
  529.                                 String nome = cookie.getName();
  530.                                 if(nome==null) {
  531.                                     throw new ProtocolException("Trovato parametro cookie senza nome");
  532.                                 }
  533.                                 ResourceParameter rp = null;
  534.                                 for (ResourceParameter rpCheck : resourceOpenSPCoop.getRequest().getParameterList()) {
  535.                                     if(ParameterType.COOKIE.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  536.                                         rp = rpCheck;
  537.                                         break;
  538.                                     }
  539.                                 }
  540.                                 if(rp==null) {
  541.                                     rp = new ResourceParameter();
  542.                                     rp.setParameterType(ParameterType.COOKIE);
  543.                                     rp.setNome(cookie.getName());
  544.                                     resourceOpenSPCoop.getRequest().addParameter(rp);
  545.                                 }
  546.                                 rp.setDescrizione(this.normalizeDescriptionOtherElementApi(cookie.getDescription()));
  547.                                 rp.setRequired(cookie.isRequired());
  548.                                 if(cookie.getApiParameterSchema()!=null) {
  549.                                     String type = cookie.getApiParameterSchema().getType();
  550.                                     if(type==null) {
  551.                                         throw new ProtocolException(TROVATO_PARAMETRO_COOKIE_PREFIX+rp.getNome()+SENZA_TIPO_SUFFIX);
  552.                                     }
  553.                                     rp.setTipo(type);
  554.                                     rp.setRestrizioni(cookie.getApiParameterSchema().toString());
  555.                                 }
  556.                                 else {
  557.                                     throw new ProtocolException(TROVATO_PARAMETRO_COOKIE_PREFIX+rp.getNome()+SENZA_SCHEMA_SUFFIX);
  558.                                 }
  559.                             }                          
  560.                         }
  561.                        
  562.                         if(apiOp.getRequest().sizeDynamicPathParameters()>0) {
  563.                             for (ApiRequestDynamicPathParameter dynamicPath : apiOp.getRequest().getDynamicPathParameters()) {
  564.                                 String nome = dynamicPath.getName();
  565.                                 if(nome==null) {
  566.                                     throw new ProtocolException("Trovato parametro dynamic path senza nome");
  567.                                 }
  568.                                 ResourceParameter rp = null;
  569.                                 for (ResourceParameter rpCheck : resourceOpenSPCoop.getRequest().getParameterList()) {
  570.                                     if(ParameterType.DYNAMIC_PATH.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  571.                                         rp = rpCheck;
  572.                                         break;
  573.                                     }
  574.                                 }
  575.                                 if(rp==null) {
  576.                                     rp = new ResourceParameter();
  577.                                     rp.setParameterType(ParameterType.DYNAMIC_PATH);
  578.                                     rp.setNome(dynamicPath.getName());
  579.                                     resourceOpenSPCoop.getRequest().addParameter(rp);
  580.                                 }
  581.                                 rp.setDescrizione(this.normalizeDescriptionOtherElementApi(dynamicPath.getDescription()));
  582.                                 rp.setRequired(dynamicPath.isRequired());
  583.                                 if(dynamicPath.getApiParameterSchema()!=null) {
  584.                                     String type = dynamicPath.getApiParameterSchema().getType();
  585.                                     if(type==null) {
  586.                                         throw new ProtocolException("Trovato parametro dynamic path '"+rp.getNome()+SENZA_TIPO_SUFFIX);
  587.                                     }
  588.                                     rp.setTipo(type);
  589.                                     rp.setRestrizioni(dynamicPath.getApiParameterSchema().toString());
  590.                                 }
  591.                                 else {
  592.                                     throw new ProtocolException("Trovato parametro dynamic path '"+rp.getNome()+SENZA_SCHEMA_SUFFIX);
  593.                                 }
  594.                             }                          
  595.                         }
  596.                        
  597.                         if(apiOp.getRequest().sizeFormParameters()>0) {
  598.                             for (ApiRequestFormParameter form : apiOp.getRequest().getFormParameters()) {
  599.                                 String nome = form.getName();
  600.                                 if(nome==null) {
  601.                                     throw new ProtocolException("Trovato parametro form senza nome");
  602.                                 }
  603.                                 ResourceParameter rp = null;
  604.                                 for (ResourceParameter rpCheck : resourceOpenSPCoop.getRequest().getParameterList()) {
  605.                                     if(ParameterType.FORM.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  606.                                         rp = rpCheck;
  607.                                         break;
  608.                                     }
  609.                                 }
  610.                                 if(rp==null) {
  611.                                     rp = new ResourceParameter();
  612.                                     rp.setParameterType(ParameterType.FORM);
  613.                                     rp.setNome(form.getName());
  614.                                     resourceOpenSPCoop.getRequest().addParameter(rp);
  615.                                 }
  616.                                 rp.setDescrizione(this.normalizeDescriptionOtherElementApi(form.getDescription()));
  617.                                 rp.setRequired(form.isRequired());
  618.                                 if(form.getApiParameterSchema()!=null) {
  619.                                     String type = form.getApiParameterSchema().getType();
  620.                                     if(type==null) {
  621.                                         throw new ProtocolException("Trovato parametro form '"+rp.getNome()+SENZA_TIPO_SUFFIX);
  622.                                     }
  623.                                     rp.setTipo(type);
  624.                                     rp.setRestrizioni(form.getApiParameterSchema().toString());
  625.                                 }
  626.                                 else {
  627.                                     throw new ProtocolException("Trovato parametro form '"+rp.getNome()+SENZA_SCHEMA_SUFFIX);
  628.                                 }
  629.                             }                          
  630.                         }
  631.                        
  632.                         if(apiOp.getRequest().sizeHeaderParameters()>0) {
  633.                             for (ApiHeaderParameter header : apiOp.getRequest().getHeaderParameters()) {
  634.                                 String nome = header.getName();
  635.                                 if(nome==null) {
  636.                                     throw new ProtocolException("Trovato parametro header senza nome");
  637.                                 }
  638.                                 ResourceParameter rp = null;
  639.                                 for (ResourceParameter rpCheck : resourceOpenSPCoop.getRequest().getParameterList()) {
  640.                                     if(ParameterType.HEADER.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  641.                                         rp = rpCheck;
  642.                                         break;
  643.                                     }
  644.                                 }
  645.                                 if(rp==null) {
  646.                                     rp = new ResourceParameter();
  647.                                     rp.setParameterType(ParameterType.HEADER);
  648.                                     rp.setNome(header.getName());
  649.                                     resourceOpenSPCoop.getRequest().addParameter(rp);
  650.                                 }
  651.                                 rp.setDescrizione(this.normalizeDescriptionOtherElementApi(header.getDescription()));
  652.                                 rp.setRequired(header.isRequired());
  653.                                 if(header.getApiParameterSchema()!=null) {
  654.                                     String type = header.getApiParameterSchema().getType();
  655.                                     if(type==null) {
  656.                                         throw new ProtocolException(TROVATO_PARAMETRO_HEADER_PREFIX+rp.getNome()+SENZA_TIPO_SUFFIX);
  657.                                     }
  658.                                     rp.setTipo(type);
  659.                                     rp.setRestrizioni(header.getApiParameterSchema().toString());
  660.                                 }
  661.                                 else {
  662.                                     throw new ProtocolException(TROVATO_PARAMETRO_HEADER_PREFIX+rp.getNome()+SENZA_SCHEMA_SUFFIX);
  663.                                 }
  664.                             }                          
  665.                         }
  666.                        
  667.                         if(apiOp.getRequest().sizeQueryParameters()>0) {
  668.                             for (ApiRequestQueryParameter query : apiOp.getRequest().getQueryParameters()) {
  669.                                 String nome = query.getName();
  670.                                 if(nome==null) {
  671.                                     throw new ProtocolException("Trovato parametro query senza nome");
  672.                                 }
  673.                                 ResourceParameter rp = null;
  674.                                 for (ResourceParameter rpCheck : resourceOpenSPCoop.getRequest().getParameterList()) {
  675.                                     if(ParameterType.QUERY.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  676.                                         rp = rpCheck;
  677.                                         break;
  678.                                     }
  679.                                 }
  680.                                 if(rp==null) {
  681.                                     rp = new ResourceParameter();
  682.                                     rp.setParameterType(ParameterType.QUERY);
  683.                                     rp.setNome(query.getName());
  684.                                     resourceOpenSPCoop.getRequest().addParameter(rp);
  685.                                 }
  686.                                 rp.setDescrizione(this.normalizeDescriptionOtherElementApi(query.getDescription()));
  687.                                 rp.setRequired(query.isRequired());
  688.                                 if(query.getApiParameterSchema()!=null) {
  689.                                     String type = query.getApiParameterSchema().getType();
  690.                                     if(type==null) {
  691.                                         throw new ProtocolException("Trovato parametro query '"+rp.getNome()+SENZA_TIPO_SUFFIX);
  692.                                     }
  693.                                     rp.setTipo(type);
  694.                                     rp.setRestrizioni(query.getApiParameterSchema().toString());
  695.                                 }
  696.                                 else {
  697.                                     throw new ProtocolException("Trovato parametro query '"+rp.getNome()+SENZA_SCHEMA_SUFFIX);
  698.                                 }
  699.                             }                          
  700.                         }
  701.                        
  702.                     }
  703.                    
  704.                     // Risposta
  705.                     if(apiOp.sizeResponses()>0) {
  706.                         for (ApiResponse apiResponse : apiOp.getResponses()) {
  707.                            
  708.                             int status = apiResponse.getHttpReturnCode();
  709.                             boolean defaultResponse = apiResponse.isDefaultHttpReturnCode();
  710.                             ResourceResponse resourceOpenSPCoopResponse = null;
  711.                             for (ResourceResponse resourceCheck : resourceOpenSPCoop.getResponseList()) {
  712.                                 if( (status == resourceCheck.getStatus()) || (defaultResponse && ApiResponse.isDefaultHttpReturnCode(resourceCheck.getStatus()))) {
  713.                                     resourceOpenSPCoopResponse = resourceCheck;
  714.                                     break;
  715.                                 }
  716.                             }
  717.                             if(resourceOpenSPCoopResponse==null) {
  718.                                 resourceOpenSPCoopResponse = new ResourceResponse();
  719.                                 if(defaultResponse) {
  720.                                     resourceOpenSPCoopResponse.setStatus(ApiResponse.getDefaultHttpReturnCode());
  721.                                 }
  722.                                 else {
  723.                                     resourceOpenSPCoopResponse.setStatus(status);
  724.                                 }
  725.                                 resourceOpenSPCoop.addResponse(resourceOpenSPCoopResponse);
  726.                             }
  727.                             resourceOpenSPCoopResponse.setDescrizione(this.normalizeDescriptionOtherElementApi(apiResponse.getDescription()));
  728.                            
  729.                             if(apiResponse.sizeBodyParameters()>0) {
  730.                                 for (ApiBodyParameter body : apiResponse.getBodyParameters()) {
  731.                                     String mediaType = body.getMediaType();
  732.                                     ResourceRepresentation rr = null;
  733.                                     for (ResourceRepresentation rrCheck : resourceOpenSPCoopResponse.getRepresentationList()) {
  734.                                         if(mediaType.equals(rrCheck.getMediaType())) {
  735.                                             rr = rrCheck;
  736.                                             break;
  737.                                         }
  738.                                     }
  739.                                     if(rr==null) {
  740.                                         rr = new ResourceRepresentation();
  741.                                         rr.setMediaType(mediaType);
  742.                                         resourceOpenSPCoopResponse.addRepresentation(rr);
  743.                                     }
  744.                                     rr.setNome(body.getName());
  745.                                     rr.setDescrizione(this.normalizeDescriptionOtherElementApi(body.getDescription()));
  746.                                     if(body.getElement()!=null) {
  747.                                         if(body.getElement() instanceof QName) {
  748.                                             QName qname = (QName)body.getElement();
  749.                                             rr.setRepresentationType(RepresentationType.XML);
  750.                                             ResourceRepresentationXml xml = new ResourceRepresentationXml();
  751.                                             xml.setXmlType(RepresentationXmlType.ELEMENT);
  752.                                             xml.setNome(qname.getLocalPart());
  753.                                             xml.setNamespace(qname.getNamespaceURI());
  754.                                             rr.setXml(xml);
  755.                                         }
  756.                                         else if(body.getElement() instanceof String) {
  757.                                             String jsonType = (String)body.getElement();
  758.                                             rr.setRepresentationType(RepresentationType.JSON);
  759.                                             ResourceRepresentationJson json = new ResourceRepresentationJson();
  760.                                             json.setTipo(jsonType);
  761.                                             rr.setJson(json);
  762.                                         }
  763.                                         else if(body.getElement() instanceof ApiReference) {
  764.                                             ApiReference apiRef = (ApiReference) body.getElement();
  765.                                             String jsonType = apiRef.getType();
  766.                                             rr.setRepresentationType(RepresentationType.JSON);
  767.                                             ResourceRepresentationJson json = new ResourceRepresentationJson();
  768.                                             json.setTipo(apiRef.getSchemaRef()+"#"+jsonType);
  769.                                             rr.setJson(json);
  770.                                         }
  771.                                         else {
  772.                                             rr.setRepresentationType(null);
  773.                                             rr.setJson(null);
  774.                                             rr.setXml(null);
  775.                                         }
  776.                                     }
  777.                                     else {
  778.                                         rr.setRepresentationType(null);
  779.                                         rr.setJson(null);
  780.                                         rr.setXml(null);
  781.                                     }
  782.                                 }
  783.                             }
  784.                            
  785.                             if(apiResponse.sizeCookieParameters()>0) {
  786.                                 for (ApiCookieParameter cookie : apiResponse.getCookieParameters()) {
  787.                                     String nome = cookie.getName();
  788.                                     if(nome==null) {
  789.                                         throw new ProtocolException("Trovato parametro cookie nella risposta senza nome");
  790.                                     }
  791.                                     ResourceParameter rp = null;
  792.                                     for (ResourceParameter rpCheck : resourceOpenSPCoopResponse.getParameterList()) {
  793.                                         if(ParameterType.COOKIE.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  794.                                             rp = rpCheck;
  795.                                             break;
  796.                                         }
  797.                                     }
  798.                                     if(rp==null) {
  799.                                         rp = new ResourceParameter();
  800.                                         rp.setParameterType(ParameterType.COOKIE);
  801.                                         rp.setNome(cookie.getName());
  802.                                         resourceOpenSPCoopResponse.addParameter(rp);
  803.                                     }
  804.                                     rp.setDescrizione(this.normalizeDescriptionOtherElementApi(cookie.getDescription()));
  805.                                     rp.setRequired(cookie.isRequired());
  806.                                     if(cookie.getApiParameterSchema()!=null) {
  807.                                         String type = cookie.getApiParameterSchema().getType();
  808.                                         if(type==null) {
  809.                                             throw new ProtocolException(TROVATO_PARAMETRO_COOKIE_PREFIX+rp.getNome()+"' nella risposta senza tipo");
  810.                                         }
  811.                                         rp.setTipo(type);
  812.                                         rp.setRestrizioni(cookie.getApiParameterSchema().toString());
  813.                                     }
  814.                                     else {
  815.                                         throw new ProtocolException(TROVATO_PARAMETRO_COOKIE_PREFIX+rp.getNome()+"' nella risposta senza schema");
  816.                                     }
  817.                                 }                          
  818.                             }
  819.                            
  820.                             if(apiResponse.sizeHeaderParameters()>0) {
  821.                                 for (ApiHeaderParameter header : apiResponse.getHeaderParameters()) {
  822.                                     String nome = header.getName();
  823.                                     if(nome==null) {
  824.                                         throw new ProtocolException("Trovato parametro header nella risposta senza nome");
  825.                                     }
  826.                                     ResourceParameter rp = null;
  827.                                     for (ResourceParameter rpCheck : resourceOpenSPCoopResponse.getParameterList()) {
  828.                                         if(ParameterType.HEADER.equals(rpCheck.getParameterType()) && nome.equals(rpCheck.getNome())) {
  829.                                             rp = rpCheck;
  830.                                             break;
  831.                                         }
  832.                                     }
  833.                                     if(rp==null) {
  834.                                         rp = new ResourceParameter();
  835.                                         rp.setParameterType(ParameterType.HEADER);
  836.                                         rp.setNome(header.getName());
  837.                                         resourceOpenSPCoopResponse.addParameter(rp);
  838.                                     }
  839.                                     rp.setDescrizione(this.normalizeDescriptionOtherElementApi(header.getDescription()));
  840.                                     rp.setRequired(header.isRequired());
  841.                                     if(header.getApiParameterSchema()!=null) {
  842.                                         String type = header.getApiParameterSchema().getType();
  843.                                         if(type==null) {
  844.                                             throw new ProtocolException(TROVATO_PARAMETRO_HEADER_PREFIX+rp.getNome()+"' nella risposta senza tipo");
  845.                                         }
  846.                                         rp.setTipo(type);
  847.                                         rp.setRestrizioni(header.getApiParameterSchema().toString());
  848.                                     }
  849.                                     else {
  850.                                         throw new ProtocolException(TROVATO_PARAMETRO_HEADER_PREFIX+rp.getNome()+"' nella risposta senza schema");
  851.                                     }
  852.                                 }                          
  853.                             }
  854.                         }
  855.                     }
  856.                 }
  857.              }
  858.              
  859.              // Check nomi univoci delle risorse
  860.              if(accordoServizioParteComune.sizeResourceList()>0) {
  861.                  boolean foundEquals = true;
  862.                  while (foundEquals) {
  863.                      foundEquals = false;
  864.                      
  865.                      for (int i = 0; i < accordoServizioParteComune.sizeResourceList(); i++) {
  866.                          Resource resource = accordoServizioParteComune.getResource(i);
  867.                          List<Resource> lR = new ArrayList<>();
  868.                          for (Resource resourceCheck : accordoServizioParteComune.getResourceList()) {
  869.                              if(resourceCheck.getNome().equals(resource.getNome())) {
  870.                                  lR.add(resourceCheck);
  871.                              }
  872.                          }
  873.                          if(lR.size()>1) {
  874.                              for (int j = 0; j < lR.size(); j++) {
  875.                                  Resource resourceDaModificare = lR.get(j);
  876.                                  String newName = resourceDaModificare.getNome();
  877.                                  if(newName.length()>250) {
  878.                                      newName = newName.substring(0, 250)+"_"+(j+1);
  879.                                  }
  880.                                  else {
  881.                                      newName = newName +"_"+(j+1);
  882.                                  }
  883.                                  resourceDaModificare.setNome(newName);
  884.                              }
  885.                              foundEquals = true;
  886.                          }
  887.                      }
  888.                  }
  889.                  
  890.              }

  891.            
  892.         }catch(Exception e){
  893.             throw new ProtocolException(e.getMessage(),e);
  894.         }
  895.        
  896.     }
  897.    
  898.    
  899.    

  900.    
  901.    
  902.    
  903.     /* ----- Import ----- */
  904.    
  905.     @Override
  906.     public List<ImportMode> getImportModes() throws ProtocolException {
  907.         List<ImportMode> list = new ArrayList<>();
  908.         list.add(Costanti.OPENSPCOOP_IMPORT_ARCHIVE_MODE);
  909.         return list;
  910.     }

  911.     @Override
  912.     public Archive importArchive(byte[]archive,ArchiveMode mode,ArchiveModeType type,
  913.             IRegistryReader registryReader,IConfigIntegrationReader configIntegrationReader,
  914.             boolean validationDocuments, MapPlaceholder placeholder) throws ProtocolException {
  915.        
  916.         ZIPReadUtils zipUtils = new ZIPReadUtils(this.protocolFactory.getLogger(),registryReader,configIntegrationReader);
  917.         return zipUtils.getArchive(archive,placeholder,validationDocuments);
  918.        
  919.     }
  920.    
  921.     @Override
  922.     public Archive importArchive(InputStream archive,ArchiveMode mode,ArchiveModeType type,
  923.             IRegistryReader registryReader,IConfigIntegrationReader configIntegrationReader,
  924.             boolean validationDocuments, MapPlaceholder placeholder) throws ProtocolException {
  925.        
  926.         try{
  927.             ZIPReadUtils zipUtils = new ZIPReadUtils(this.protocolFactory.getLogger(),registryReader,configIntegrationReader);
  928.             return zipUtils.getArchive(archive,placeholder,validationDocuments);
  929.         }finally{
  930.             try{
  931.                 if(archive!=null){
  932.                     archive.close();
  933.                 }
  934.             }catch(Exception eClose){
  935.                 // close
  936.             }
  937.         }
  938.        
  939.     }
  940.    
  941.     @Override
  942.     public void finalizeImportArchive(Archive archive,ArchiveMode mode,ArchiveModeType type,
  943.             IRegistryReader registryReader,IConfigIntegrationReader configIntegrationReader,
  944.             boolean validationDocuments, MapPlaceholder placeholder) throws ProtocolException {
  945.         // nop
  946.     }
  947.    
  948.     @Override
  949.     public String toString(ArchiveEsitoImport esito, ArchiveMode archiveMode) throws ProtocolException{
  950.         return this.esitoUtils.toString(esito,true,true);
  951.     }
  952.    
  953.     @Override
  954.     public String toString(ArchiveEsitoDelete esito, ArchiveMode archiveMode) throws ProtocolException{
  955.         return this.esitoUtils.toString(esito,true,false);
  956.     }
  957.    
  958.    
  959.    
  960.    
  961.    
  962.    
  963.    
  964.     /* ----- Export ----- */
  965.    
  966.     @Override
  967.     public List<ExportMode> getExportModes(ArchiveType archiveType)
  968.             throws ProtocolException {
  969.         List<ExportMode> list = new ArrayList<>();
  970.         list.add((ExportMode)Costanti.OPENSPCOOP_EXPORT_ARCHIVE_MODE.clone()); // vengono supportati tutti i tipi
  971.         return list;
  972.     }
  973.    
  974.     @Override
  975.     public MappingModeTypesExtensions getExportMappingTypesExtensions(Archive archive, ArchiveMode mode,
  976.             IRegistryReader registroReader, IConfigIntegrationReader configIntegrationReader) throws ProtocolException{
  977.         return this.getMappingTypesExtensions(mode); // basic ignora archive
  978.     }

  979.     @Override
  980.     public byte[] exportArchive(Archive archive, ArchiveMode mode,
  981.             IRegistryReader registryReader,IConfigIntegrationReader configIntegrationReader)
  982.             throws ProtocolException {
  983.         ZIPWriteUtils zipUtils = new ZIPWriteUtils(super.getProtocolFactory().getLogger(),registryReader,configIntegrationReader);
  984.         return zipUtils.generateArchive(archive);
  985.     }
  986.    
  987.     @Override
  988.     public void exportArchive(Archive archive, OutputStream out, ArchiveMode mode,
  989.             IRegistryReader registryReader,IConfigIntegrationReader configIntegrationReader)
  990.             throws ProtocolException {
  991.         ZIPWriteUtils zipUtils = new ZIPWriteUtils(super.getProtocolFactory().getLogger(),registryReader,configIntegrationReader);
  992.         zipUtils.generateArchive(archive, out);
  993.     }
  994.    




  995. }