TransactionDumpMessaggioServiceSearchImpl.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.pdd.logger.dump;

  21. import java.sql.Connection;
  22. import java.util.List;
  23. import java.util.Map;

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.core.commons.CoreException;
  26. import org.openspcoop2.core.transazioni.DumpAllegato;
  27. import org.openspcoop2.core.transazioni.DumpHeaderAllegato;
  28. import org.openspcoop2.core.transazioni.DumpHeaderTrasporto;
  29. import org.openspcoop2.core.transazioni.DumpMessaggio;
  30. import org.openspcoop2.core.transazioni.DumpMultipartHeader;
  31. import org.openspcoop2.core.transazioni.dao.jdbc.JDBCDumpMessaggioServiceSearchImpl;
  32. import org.openspcoop2.core.transazioni.utils.PropertiesSerializator;
  33. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  34. import org.openspcoop2.utils.sql.ISQLQueryObject;
  35. import org.slf4j.Logger;

  36. /**    
  37.  * TransactionDumpMessaggioServiceSearchImpl
  38.  *
  39.  * @author Poli Andrea (poli@link.it)
  40.  * @author $Author$
  41.  * @version $Rev$, $Date$
  42.  */
  43. public class TransactionDumpMessaggioServiceSearchImpl extends JDBCDumpMessaggioServiceSearchImpl {

  44.     public TransactionDumpMessaggioServiceSearchImpl() {
  45.         super();
  46.     }

  47.     @Override
  48.     protected DumpMessaggio getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws Exception {
  49.        
  50.         DumpMessaggio dumpMessaggio = super.getEngine(jdbcProperties, log, connection, sqlQueryObject, tableId, idMappingResolutionBehaviour);
  51.    
  52.         readMultipartHeaderExt(dumpMessaggio);
  53.        
  54.         readHeaderExt(dumpMessaggio);
  55.        
  56.         readAllegatiExt(dumpMessaggio);
  57.        
  58.         return dumpMessaggio;
  59.        
  60.     }
  61.    
  62.     private void readMultipartHeaderExt(DumpMessaggio dumpMessaggio) throws CoreException {
  63.         if(dumpMessaggio.getMultipartHeaderExt()!=null && !StringUtils.isEmpty(dumpMessaggio.getMultipartHeaderExt())) {
  64.             Map<String, List<String>> headers = PropertiesSerializator.convertoFromDBColumnValue(dumpMessaggio.getMultipartHeaderExt());
  65.             if(headers!=null && headers.size()>0){
  66.                 readMultipartHeaderExt(dumpMessaggio, headers);
  67.             }
  68.         }
  69.     }
  70.     private void readMultipartHeaderExt(DumpMessaggio dumpMessaggio, Map<String, List<String>> headers) {
  71.         for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
  72.             String key = entry.getKey();
  73.             List<String> values = entry.getValue();
  74.             if(values!=null && !values.isEmpty()) {
  75.                 for (String value : values) {
  76.                     DumpMultipartHeader headerMultipart = new DumpMultipartHeader();
  77.                     headerMultipart.setNome(key);
  78.                     headerMultipart.setValore(value);
  79.                     headerMultipart.setDumpTimestamp(dumpMessaggio.getDumpTimestamp());
  80.                     dumpMessaggio.addMultipartHeader(headerMultipart);
  81.                 }
  82.             }
  83.         }
  84.     }
  85.    
  86.     private void readHeaderExt(DumpMessaggio dumpMessaggio) throws CoreException {
  87.         if(dumpMessaggio.getHeaderExt()!=null && !StringUtils.isEmpty(dumpMessaggio.getHeaderExt())) {
  88.             Map<String, List<String>> headers = PropertiesSerializator.convertoFromDBColumnValue(dumpMessaggio.getHeaderExt());
  89.             if(headers!=null && headers.size()>0){
  90.                 readHeaderExt(dumpMessaggio, headers);
  91.             }
  92.         }
  93.     }
  94.     private void readHeaderExt(DumpMessaggio dumpMessaggio, Map<String, List<String>> headers) {
  95.         for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
  96.             String key = entry.getKey();
  97.             List<String> values = entry.getValue();
  98.             if(values!=null && !values.isEmpty()) {
  99.                 for (String value : values) {                  
  100.                     DumpHeaderTrasporto headerTrasporto = new DumpHeaderTrasporto();
  101.                     headerTrasporto.setNome(key);
  102.                     headerTrasporto.setValore(value);
  103.                     headerTrasporto.setDumpTimestamp(dumpMessaggio.getDumpTimestamp());
  104.                     dumpMessaggio.addHeaderTrasporto(headerTrasporto);
  105.                 }
  106.             }
  107.         }
  108.     }
  109.    
  110.     private void readAllegatiExt(DumpMessaggio dumpMessaggio) throws CoreException {
  111.         if(dumpMessaggio.getAllegatoList()!=null && !dumpMessaggio.getAllegatoList().isEmpty()) {
  112.             for (DumpAllegato dumpAllegato : dumpMessaggio.getAllegatoList()) {
  113.                
  114.                 if(dumpAllegato.getHeaderExt()!=null && !StringUtils.isEmpty(dumpAllegato.getHeaderExt())) {
  115.                     Map<String, List<String>> headers = PropertiesSerializator.convertoFromDBColumnValue(dumpAllegato.getHeaderExt());
  116.                     if(headers!=null && headers.size()>0){
  117.                         readAllegatiExt(dumpMessaggio, dumpAllegato, headers);
  118.                     }
  119.                 }
  120.                
  121.             }
  122.         }
  123.     }
  124.     private void readAllegatiExt(DumpMessaggio dumpMessaggio,DumpAllegato dumpAllegato, Map<String, List<String>> headers) {
  125.         for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
  126.             String key = entry.getKey();
  127.             List<String> values = entry.getValue();
  128.             if(values!=null && !values.isEmpty()) {
  129.                 for (String value : values) {                  
  130.                     DumpHeaderAllegato headerAllegato = new DumpHeaderAllegato();
  131.                     headerAllegato.setNome(key);
  132.                     headerAllegato.setValore(value);
  133.                     headerAllegato.setDumpTimestamp(dumpMessaggio.getDumpTimestamp());
  134.                     dumpAllegato.addHeader(headerAllegato);
  135.                 }
  136.             }
  137.         }
  138.     }
  139. }