Importer.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.engine.archive;

  21. import org.openspcoop2.core.config.driver.db.DriverConfigurazioneDB;
  22. import org.openspcoop2.core.registry.driver.db.DriverRegistroServiziDB;
  23. import org.openspcoop2.protocol.basic.registry.ConfigIntegrationReader;
  24. import org.openspcoop2.protocol.basic.registry.RegistryReader;
  25. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  26. import org.openspcoop2.protocol.sdk.ConfigurazionePdD;
  27. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  28. import org.openspcoop2.protocol.sdk.archive.Archive;
  29. import org.openspcoop2.protocol.sdk.archive.ArchiveEsitoImport;
  30. import org.openspcoop2.protocol.sdk.archive.ArchiveMode;
  31. import org.openspcoop2.protocol.sdk.archive.ArchiveModeType;
  32. import org.openspcoop2.protocol.sdk.archive.IArchive;
  33. import org.openspcoop2.utils.LoggerWrapperFactory;
  34. import org.openspcoop2.utils.resources.FileSystemUtilities;
  35. import org.openspcoop2.utils.resources.Loader;
  36. import org.slf4j.Logger;

  37. /**
  38.  *  Importer
  39.  *
  40.  * @author Poli Andrea (apoli@link.it)
  41.  * @author $Author$
  42.  * @version $Rev$, $Date$
  43.  */
  44. public class Importer {

  45.     public static void main(String[] args) throws Exception {
  46.        
  47.         Logger log = LoggerWrapperFactory.getLogger(Importer.class);
  48.        
  49.         // Lettura file
  50.         String archiveFile = args[0];
  51.         byte[] archiveBytes = FileSystemUtilities.readBytesFromFile(archiveFile);
  52.        
  53.         // Protocollo
  54.         String protocollo = args[1];
  55.        
  56.         // Mode
  57.         String mode = args[2]; // es. cnipa, openspcoop
  58.         ArchiveMode archiveMode = new ArchiveMode(mode);
  59.        
  60.         // tipoArchivio
  61.         String type = args[3]; // es. *, apc, aps ...
  62.         ArchiveModeType archiveModeType = new ArchiveModeType(type);
  63.        
  64.         // validateDocuments
  65.         boolean validateDocuments = Boolean.parseBoolean(args[4]);
  66.        
  67.         // userLogin
  68.         String userLogin = args[5];
  69.        
  70.         // nomePddOperativa
  71.         String nomePddOperativa = args[6];
  72.        
  73.         // tipoPddDefault
  74.         String tipoPddDefault = args[7];
  75.        
  76.         // updateAbilitato
  77.         boolean updateAbilitato = Boolean.parseBoolean(args[8]);
  78.         boolean importPolicyConfig = Boolean.parseBoolean(args[9]);
  79.         boolean importPluginConfig = Boolean.parseBoolean(args[10]);
  80.         boolean checkExistsPluginConfig = Boolean.parseBoolean(args[11]);
  81.         boolean importConfig = Boolean.parseBoolean(args[12]);

  82.         // other
  83.         boolean isShowCorrelazioneAsincronaInAccordi = true;
  84.         boolean isShowGestioneWorkflowStatoDocumenti = true;
  85.         boolean isShowAccordiColonnaAzioni = true;
  86.         boolean isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto = false;
  87.         boolean isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto = false;
  88.         boolean isSoggettiApplicativiCredenzialiBasicPermitSameCredentials = false;
  89.         boolean isSoggettiApplicativiCredenzialiSslPermitSameCredentials = false;
  90.         boolean isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials = false;
  91.        
  92.         // Inizializzazione ProtocolFactoryManager
  93.         ConfigurazionePdD configPdD = new ConfigurazionePdD();
  94.         configPdD.setLoader(new Loader());
  95.         configPdD.setLog(log);
  96.         ProtocolFactoryManager.initializeSingleProtocol(log, configPdD, protocollo);
  97.        
  98.        
  99.         // Inizializzo Reader
  100.         DriverRegistroServiziDB driverRegistroServizi = null;
  101.         DriverConfigurazioneDB driverConfigurazione = null;
  102.         org.openspcoop2.core.plugins.dao.jdbc.JDBCServiceManager serviceManagerPlugins = null;
  103.         org.openspcoop2.core.controllo_traffico.dao.jdbc.JDBCServiceManager serviceManagerControlloTraffico = null;
  104.         org.openspcoop2.core.allarmi.dao.jdbc.JDBCServiceManager serviceManagerAllarmi = null;
  105.         // TODO INIT
  106.         RegistryReader archiveRegistryReader = new RegistryReader(driverRegistroServizi,log);
  107.         ConfigIntegrationReader archiveConfigIntegrationReader = new ConfigIntegrationReader(driverConfigurazione,log);
  108.        
  109.        
  110.         // trasformazione in archivio openspcoop2
  111.         IProtocolFactory<?> pf = ProtocolFactoryManager.getInstance().getProtocolFactoryByName(protocollo);
  112.         IArchive archiveEngine = pf.createArchive();
  113.         Archive archive = archiveEngine.importArchive(archiveBytes, archiveMode, archiveModeType, archiveRegistryReader, archiveConfigIntegrationReader, validateDocuments,null);
  114.        
  115.        
  116.         // validazione
  117.         ArchiveValidator validator = new ArchiveValidator(archiveRegistryReader);
  118.         ImportInformationMissingCollection importInformationMissingCollection = new ImportInformationMissingCollection();
  119.         validator.validateArchive(archive, protocollo, validateDocuments, importInformationMissingCollection, userLogin,
  120.                 isShowCorrelazioneAsincronaInAccordi, false);
  121.         // TODO: Gestore correttamente le eccezioni
  122.        
  123.        
  124.         // Import
  125.         ArchiveEngine importerEngine = new ArchiveEngine(driverRegistroServizi, driverConfigurazione,
  126.                 serviceManagerPlugins,
  127.                 serviceManagerControlloTraffico,
  128.                 serviceManagerAllarmi);
  129.         ImporterArchiveUtils importerArchiveUtils =
  130.                 new ImporterArchiveUtils(importerEngine, log, userLogin, nomePddOperativa, tipoPddDefault,
  131.                         isShowGestioneWorkflowStatoDocumenti, updateAbilitato,
  132.                         importPolicyConfig,
  133.                         importPluginConfig, checkExistsPluginConfig,
  134.                         importConfig);
  135.         ArchiveEsitoImport result = importerArchiveUtils.importArchive(archive, userLogin,
  136.                 isShowAccordiColonnaAzioni,
  137.                 isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto,
  138.                 isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto,
  139.                 isSoggettiApplicativiCredenzialiBasicPermitSameCredentials,
  140.                 isSoggettiApplicativiCredenzialiSslPermitSameCredentials,
  141.                 isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials);
  142.         String resultAsString = archiveEngine.toString(result, archiveMode);
  143.         log.info(resultAsString);
  144.        

  145.     }

  146. }