TransazioniHelper.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.core.monitor.rs.server.api.impl.utils;


  21. import java.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Optional;

  25. import org.apache.commons.lang3.BooleanUtils;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.openspcoop2.core.id.IDSoggetto;
  28. import org.openspcoop2.core.monitor.rs.server.config.DBManager;
  29. import org.openspcoop2.core.monitor.rs.server.config.LoggerProperties;
  30. import org.openspcoop2.core.monitor.rs.server.config.ServerProperties;
  31. import org.openspcoop2.core.monitor.rs.server.model.EsitoTransazioneFullSearchEnum;
  32. import org.openspcoop2.core.monitor.rs.server.model.FiltroApiBase;
  33. import org.openspcoop2.core.monitor.rs.server.model.FiltroApiSoggetti;
  34. import org.openspcoop2.core.monitor.rs.server.model.FiltroEsito;
  35. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteErogazioneApplicativo;
  36. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteErogazioneSoggetto;
  37. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteFruizioneApplicativo;
  38. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteIdAutenticato;
  39. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteIndirizzoIP;
  40. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteTokenClaim;
  41. import org.openspcoop2.core.monitor.rs.server.model.FiltroMittenteTokenClaimSoggetto;
  42. import org.openspcoop2.core.monitor.rs.server.model.FiltroRicercaRuoloTransazioneEnum;
  43. import org.openspcoop2.core.monitor.rs.server.model.ListaTransazioni;
  44. import org.openspcoop2.core.monitor.rs.server.model.OneOfRicercaIntervalloTemporaleMittente;
  45. import org.openspcoop2.core.monitor.rs.server.model.RicercaBaseTransazione;
  46. import org.openspcoop2.core.monitor.rs.server.model.RicercaIdApplicativo;
  47. import org.openspcoop2.core.monitor.rs.server.model.RicercaIntervalloTemporale;
  48. import org.openspcoop2.generic_project.utils.ServiceManagerProperties;
  49. import org.openspcoop2.message.constants.ServiceBinding;
  50. import org.openspcoop2.monitor.engine.condition.EsitoUtils;
  51. import org.openspcoop2.protocol.sdk.config.IProtocolConfiguration;
  52. import org.openspcoop2.utils.UtilsException;
  53. import org.openspcoop2.utils.service.beans.FiltroRicercaId;
  54. import org.openspcoop2.utils.service.beans.utils.ListaUtils;
  55. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;
  56. import org.openspcoop2.web.monitor.core.constants.CaseSensitiveMatch;
  57. import org.openspcoop2.web.monitor.core.constants.Costanti;
  58. import org.openspcoop2.web.monitor.core.constants.TipoMatch;
  59. import org.openspcoop2.web.monitor.transazioni.bean.TransazioneBean;
  60. import org.openspcoop2.web.monitor.transazioni.bean.TransazioniSearchForm;
  61. import org.openspcoop2.web.monitor.transazioni.dao.TransazioniService;

  62. /**
  63.  * TransazioniHelper
  64.  *
  65.  * @author $Author$
  66.  * @version $Rev$, $Date$
  67.  *
  68.  */
  69. public class TransazioniHelper {
  70.    
  71.     public static boolean isEmpty(IDSoggetto _this) {
  72.         return StringUtils.isEmpty(_this.getTipo()) || StringUtils.isEmpty(_this.getNome());
  73.     }

  74.     public static final void overrideFiltroApiBase(FiltroApiBase filtro_api, String azione, IDSoggetto erogatore, TransazioniSearchForm search, MonitoraggioEnv env) {
  75.        
  76.         search.setNomeAzione(azione);
  77.        
  78.         if (filtro_api == null)
  79.             return;
  80.        
  81.         boolean checkAzione = true;
  82.         if(filtro_api instanceof FiltroApiSoggetti) {
  83.             FiltroApiSoggetti f = (FiltroApiSoggetti) filtro_api;
  84.             if(f.getApiImplementata()!=null) {
  85.                 checkAzione = false;
  86.             }
  87.         }
  88.        
  89.         if ( !StringUtils.isEmpty(filtro_api.getNome()) || filtro_api.getVersione() != null ||
  90.                 (checkAzione && !StringUtils.isEmpty(azione)) ||
  91.                 !StringUtils.isEmpty(filtro_api.getTipo())) {
  92.            
  93.             if (StringUtils.isEmpty(filtro_api.getNome())) {
  94.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Filtro Api incompleto. Specificare il nome della API");
  95.             }
  96.                        
  97.             if (erogatore == null || TransazioniHelper.isEmpty(erogatore)) {
  98.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Filtro Api incompleto. Specificare il Soggetto Erogatore (Nelle fruizioni รจ il soggetto remoto)");
  99.             }
  100.            
  101.             if (filtro_api.getVersione() == null) {
  102.                 filtro_api.setVersione(1);
  103.             }
  104.            
  105.             if (filtro_api.getTipo() == null) {
  106.                 try {
  107.                     IProtocolConfiguration protocolConf = env.protocolFactoryMgr
  108.                             .getProtocolFactoryByName(env.tipo_protocollo).createProtocolConfiguration();
  109.                     ServiceBinding defaultBinding = protocolConf.getDefaultServiceBindingConfiguration(null)
  110.                             .getDefaultBinding();
  111.                     filtro_api.setTipo(protocolConf.getTipoServizioDefault(defaultBinding));
  112.                 } catch (Exception e) {
  113.                     throw FaultCode.ERRORE_INTERNO
  114.                             .toException("Impossibile determinare il tipo del servizio: " + e.getMessage());
  115.                 }

  116.             }
  117.            
  118.             String uri = ReportisticaHelper.buildNomeServizioForOverride(filtro_api.getNome(), filtro_api.getTipo(), filtro_api.getVersione(), Optional.of(erogatore));
  119.             if (uri == null) {
  120.                 throw FaultCode.ERRORE_INTERNO.toException("Non sono riuscito a costruire la URI dell'Id Servizio");
  121.             }
  122.            
  123.             search.setNomeServizio(uri);            
  124.         }
  125.     }

  126.     public static final void overrideFiltroFruizione(FiltroApiSoggetti filtro, String azione,
  127.             TransazioniSearchForm search, MonitoraggioEnv env) {
  128.         if (filtro == null)
  129.             return;

  130.         TransazioniHelper.overrideFiltroApiBase(filtro, azione, new IDSoggetto(env.tipoSoggetto, filtro.getErogatore()), search, env);
  131.     }
  132.    
  133.     public static final void overrideFiltroQualsiasi(FiltroApiSoggetti filtro, String azione,
  134.             TransazioniSearchForm search, MonitoraggioEnv env) {
  135.         if (filtro == null)
  136.             return;

  137.         TransazioniHelper.overrideFiltroApiBase(filtro, azione, new IDSoggetto(env.tipoSoggetto, filtro.getErogatore()), search, env);
  138.         if (!StringUtils.isEmpty(filtro.getSoggettoRemoto()))
  139.             search.setTipoNomeTrafficoPerSoggetto(new IDSoggetto(env.tipoSoggetto, filtro.getSoggettoRemoto()).toString());
  140.     }
  141.    
  142.     public static final void overrideFiltroRicercaId(FiltroRicercaId filtro, TransazioniSearchForm search,
  143.             MonitoraggioEnv env, String tipoRiconoscimento) {
  144.         if (filtro == null)
  145.             return;

  146.         search.setMittenteMatchingType(
  147.                 (BooleanUtils.isTrue(filtro.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  148.         search.setMittenteCaseSensitiveType(
  149.                 (BooleanUtils.isTrue(filtro.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE
  150.                         : CaseSensitiveMatch.INSENSITIVE).toString());
  151.         search.setValoreRiconoscimento(filtro.getId());
  152.         search.setRiconoscimento(tipoRiconoscimento);
  153.     }

  154.     public static final void overrideFiltroMittenteIdApplicativo(FiltroMittenteIdAutenticato filtro,
  155.             TransazioniSearchForm search, MonitoraggioEnv env) {
  156.         if (filtro == null)
  157.             return;
  158.         TransazioniHelper.overrideFiltroRicercaId(filtro, search, env, Costanti.VALUE_TIPO_RICONOSCIMENTO_IDENTIFICATIVO_AUTENTICATO);
  159.         search.setAutenticazione(Enums.toTipoAutenticazione.get(filtro.getAutenticazione()).toString());
  160.     }
  161.    
  162.     public static final void overrideFiltroMittenteIndirizzoIP(FiltroMittenteIndirizzoIP filtro,
  163.             TransazioniSearchForm search, MonitoraggioEnv env) {
  164.         if (filtro == null)
  165.             return;
  166.         TransazioniHelper.overrideFiltroRicercaId(filtro, search, env, Costanti.VALUE_TIPO_RICONOSCIMENTO_INDIRIZZO_IP);
  167.         if(filtro.getTipo()!=null) {
  168.             search.setClientAddressMode(Enums.toTipoIndirizzzoIP.get(filtro.getTipo()));
  169.         }
  170.     }

  171.     private static void setEsitoCodice(EsitoTransazioneFullSearchEnum tipo , FiltroEsito filtro, TransazioniSearchForm search) {
  172.         if(filtro.getCodice()!=null) {
  173.             search.setEsitoDettaglio(filtro.getCodice());
  174.         }
  175.         else if(filtro.getCodici()!=null && !filtro.getCodici().isEmpty()) {
  176.             if(filtro.getCodici().size()==1) {
  177.                 search.setEsitoDettaglio(filtro.getCodici().get(0));
  178.             }
  179.             else {
  180.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Con il tipo di esito indicato '"+tipo.toString()+"' puรฒ essere indicato solamente un codice");
  181.             }
  182.         }
  183.     }
  184.     public static final void overrideFiltroEsito(FiltroEsito filtro, TransazioniSearchForm search,
  185.             MonitoraggioEnv env) {
  186.         if (filtro == null)
  187.             return;

  188.         if (filtro != null) {
  189.            
  190.             EsitoTransazioneFullSearchEnum tipo = CheckNotNull.getEsitoTransazione(filtro);
  191.            
  192.             switch (tipo) {
  193.             case QUALSIASI:
  194.                 search.setEsitoGruppo(EsitoUtils.ALL_VALUE);
  195.                 setEsitoCodice(tipo, filtro, search);
  196.                 if(filtro.isEscludiScartate()!=null) {
  197.                     search.setEscludiRichiesteScartate(filtro.isEscludiScartate());
  198.                 }
  199.                 break;
  200.             case OK:
  201.                 search.setEsitoGruppo(EsitoUtils.ALL_OK_VALUE);
  202.                 setEsitoCodice(tipo, filtro, search);
  203.                 break;
  204.             case FAULT:
  205.                 search.setEsitoGruppo(EsitoUtils.ALL_FAULT_APPLICATIVO_VALUE);
  206.                 setEsitoCodice(tipo, filtro, search);
  207.                 break;
  208.             case FALLITE:
  209.                 search.setEsitoGruppo(EsitoUtils.ALL_ERROR_VALUE);
  210.                 setEsitoCodice(tipo, filtro, search);
  211.                 if(filtro.isEscludiScartate()!=null) {
  212.                     search.setEscludiRichiesteScartate(filtro.isEscludiScartate());
  213.                 }
  214.                 break;
  215.             case FALLITE_E_FAULT:
  216.                 search.setEsitoGruppo(EsitoUtils.ALL_ERROR_FAULT_APPLICATIVO_VALUE);
  217.                 setEsitoCodice(tipo, filtro, search);
  218.                 if(filtro.isEscludiScartate()!=null) {
  219.                     search.setEscludiRichiesteScartate(filtro.isEscludiScartate());
  220.                 }
  221.                 break;
  222.             case ERRORI_CONSEGNA:
  223.                 search.setEsitoGruppo(EsitoUtils.ALL_ERROR_CONSEGNA_VALUE);
  224.                 setEsitoCodice(tipo, filtro, search);
  225.                 break;
  226.             case RICHIESTE_SCARTATE:
  227.                 search.setEsitoGruppo(EsitoUtils.ALL_ERROR_RICHIESTE_SCARTATE_VALUE);
  228.                 setEsitoCodice(tipo, filtro, search);
  229.                 break;
  230.             case PERSONALIZZATO:
  231.                 search.setEsitoGruppo(EsitoUtils.ALL_PERSONALIZZATO_VALUE);
  232.                
  233.                 if(filtro.getCodice()==null && (filtro.getCodici()==null || filtro.getCodici().isEmpty())) {
  234.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("Con il tipo di esito indicato '"+tipo.toString()+"' deve essere indicato almeno un codice");
  235.                 }
  236.                 List<Integer> dettaglioEsito = filtro.getCodici();
  237.                 if(dettaglioEsito==null || dettaglioEsito.isEmpty()) {
  238.                     dettaglioEsito = new ArrayList<Integer>();
  239.                     dettaglioEsito.add(filtro.getCodice());
  240.                 }
  241.                 search.setEsitoDettaglioPersonalizzato(dettaglioEsito.toArray(new Integer[1]));

  242.                 break;
  243.             }
  244.         }

  245.     }

  246.     public static final void overrideRicercaBaseTransazione(RicercaBaseTransazione body, TransazioniSearchForm search,
  247.             MonitoraggioEnv env) throws Exception {
  248.         if (body == null)
  249.             return;
  250.        
  251.         if (body.getAzione() != null && body.getApi() == null) {
  252.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Se viene specificato il filtro 'azione' รจ necessario specificare anche il filtro Api");
  253.         }
  254.        
  255.         search.setGruppo(body.getTag());

  256.         if(body.getApi()!=null && body.getApi().getApiImplementata()!=null) {
  257.             search.setApi(ReportisticaHelper.toUriApiImplementata(body.getApi().getApiImplementata(), env));
  258.         }
  259.        
  260.         switch (body.getTipo()) {
  261.         case EROGAZIONE:
  262.             IDSoggetto idSoggettoLocale = new IDSoggetto(env.tipoSoggetto, env.nomeSoggettoLocale);
  263.             TransazioniHelper.overrideFiltroApiBase(body.getApi(), body.getAzione(), idSoggettoLocale, search, env);
  264.             break;
  265.         case FRUIZIONE:
  266.             TransazioniHelper.overrideFiltroFruizione(body.getApi(),body.getAzione(), search, env);
  267.             break;
  268.         case QUALSIASI:
  269.             TransazioniHelper.overrideFiltroQualsiasi(body.getApi(), body.getAzione(), search, env);
  270.             break;
  271.         }

  272.         TransazioniHelper.overrideFiltroEsito(body.getEsito(), search, env);
  273.         search.setEvento(body.getEvento());
  274.         search.setClusterId(body.getIdCluster());
  275.     }
  276.    
  277.    
  278.     public static final void overrideFiltroMittente(RicercaIntervalloTemporale body, TransazioniSearchForm search,
  279.             MonitoraggioEnv env) {
  280.         if (body == null)
  281.             return;

  282.         // Filtraggio Mittente
  283.        
  284.         OneOfRicercaIntervalloTemporaleMittente fMittente = body.getMittente();
  285.         if (fMittente == null)
  286.             return;
  287.        
  288.         final String tipo_soggetto = env.tipoSoggetto;
  289.         switch (body.getTipo()) {
  290.         case FRUIZIONE: {
  291.            
  292.             switch (fMittente.getIdentificazione()) {
  293.            
  294.             case EROGAZIONE_SOGGETTO: {
  295.                 throw FaultCode.RICHIESTA_NON_VALIDA
  296.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  297.                             + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.FRUIZIONE.toString()+"'");
  298.             }
  299.            
  300.             case FRUIZIONE_APPLICATIVO: {
  301.                
  302.                 if(! (fMittente instanceof FiltroMittenteFruizioneApplicativo)) {
  303.                     throw FaultCode.RICHIESTA_NON_VALIDA
  304.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  305.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteFruizioneApplicativo.class.getName()+")");
  306.                 }
  307.                 FiltroMittenteFruizioneApplicativo fAppl = (FiltroMittenteFruizioneApplicativo) fMittente;
  308.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_APPLICATIVO);
  309.                 if(fAppl.getTipoIdentificazioneApplicativo()!=null) {
  310.                     switch (fAppl.getTipoIdentificazioneApplicativo()) {
  311.                     case TRASPORTO:
  312.                         search.setIdentificazione(Costanti.IDENTIFICAZIONE_TRASPORTO_KEY);
  313.                         break;
  314.                     case TOKEN:
  315.                         search.setIdentificazione(Costanti.IDENTIFICAZIONE_TOKEN_KEY);
  316.                         break;
  317.                     }
  318.                 }
  319.                 else {
  320.                     search.setIdentificazione(Costanti.IDENTIFICAZIONE_TRASPORTO_KEY);
  321.                 }
  322.                 search.setServizioApplicativo(fAppl.getApplicativo());
  323.                
  324.                 search.setTipoNomeMittente(new IDSoggetto(tipo_soggetto, env.nomeSoggettoLocale).toString());
  325.                
  326.                 break;
  327.             }
  328.            
  329.             case EROGAZIONE_APPLICATIVO: {
  330.                 throw FaultCode.RICHIESTA_NON_VALIDA
  331.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  332.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.FRUIZIONE.toString()+"'");
  333.             }
  334.            
  335.             case IDENTIFICATIVO_AUTENTICATO: {
  336.                
  337.                 if(! (fMittente instanceof FiltroMittenteIdAutenticato)) {
  338.                     throw FaultCode.RICHIESTA_NON_VALIDA
  339.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  340.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIdAutenticato.class.getName()+")");
  341.                 }
  342.                 FiltroMittenteIdAutenticato fIdAutenticato = (FiltroMittenteIdAutenticato) fMittente;
  343.                 TransazioniHelper.overrideFiltroMittenteIdApplicativo(fIdAutenticato, search, env);
  344.                 break;
  345.             }

  346.             case EROGAZIONE_TOKEN_INFO: {
  347.                 throw FaultCode.RICHIESTA_NON_VALIDA
  348.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  349.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.FRUIZIONE.toString()+"'");
  350.             }
  351.            
  352.             case TOKEN_INFO: {
  353.                 if(! (fMittente instanceof FiltroMittenteTokenClaim)) {
  354.                     throw FaultCode.RICHIESTA_NON_VALIDA
  355.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  356.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteTokenClaim.class.getName()+")");
  357.                 }
  358.                 FiltroMittenteTokenClaim fClaim = (FiltroMittenteTokenClaim) fMittente;
  359.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_TOKEN_INFO);
  360.                 search.setTokenClaim(Enums.toTipoCredenzialeMittente(fClaim.getClaim()).getRawValue());
  361.                 search.setMittenteMatchingType( (BooleanUtils.isTrue(fClaim.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  362.                 search.setMittenteCaseSensitiveType( (BooleanUtils.isTrue(fClaim.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE : CaseSensitiveMatch.INSENSITIVE).toString());
  363.                 search.setValoreRiconoscimento(fClaim.getId());
  364.                 break;
  365.             }
  366.                
  367.             case INDIRIZZO_IP: {
  368.                
  369.                 if(! (fMittente instanceof FiltroMittenteIndirizzoIP)) {
  370.                     throw FaultCode.RICHIESTA_NON_VALIDA
  371.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  372.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIndirizzoIP.class.getName()+")");
  373.                 }
  374.                 FiltroMittenteIndirizzoIP fIndirizzoIP = (FiltroMittenteIndirizzoIP) fMittente;
  375.                 TransazioniHelper.overrideFiltroMittenteIndirizzoIP(fIndirizzoIP, search, env);
  376.                 break;
  377.             }
  378.                
  379.             }
  380.            
  381.             break;
  382.         }

  383.         case EROGAZIONE: {
  384.            
  385.             switch (fMittente.getIdentificazione()) {

  386.             case EROGAZIONE_SOGGETTO: {
  387.                
  388.                 if(! (fMittente instanceof FiltroMittenteErogazioneSoggetto)) {
  389.                     throw FaultCode.RICHIESTA_NON_VALIDA
  390.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  391.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteErogazioneSoggetto.class.getName()+")");
  392.                 }
  393.                 FiltroMittenteErogazioneSoggetto fSogg = (FiltroMittenteErogazioneSoggetto) fMittente;
  394.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_SOGGETTO);
  395.                 search.setTipoNomeMittente(new IDSoggetto(tipo_soggetto, fSogg.getSoggetto()).toString());
  396.                 break;
  397.             }
  398.            
  399.             case FRUIZIONE_APPLICATIVO: {
  400.                 throw FaultCode.RICHIESTA_NON_VALIDA
  401.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  402.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.EROGAZIONE.toString()+"'");
  403.             }
  404.            
  405.             case EROGAZIONE_APPLICATIVO: {
  406.                
  407.                 if(! (fMittente instanceof FiltroMittenteErogazioneApplicativo)) {
  408.                     throw FaultCode.RICHIESTA_NON_VALIDA
  409.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  410.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteErogazioneApplicativo.class.getName()+")");
  411.                 }
  412.                 FiltroMittenteErogazioneApplicativo fAppl = (FiltroMittenteErogazioneApplicativo) fMittente;
  413.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_APPLICATIVO);
  414.                 if(fAppl.getTipoIdentificazioneApplicativo()!=null) {
  415.                     switch (fAppl.getTipoIdentificazioneApplicativo()) {
  416.                     case TRASPORTO:
  417.                         search.setIdentificazione(Costanti.IDENTIFICAZIONE_TRASPORTO_KEY);
  418.                         break;
  419.                     case TOKEN:
  420.                         search.setIdentificazione(Costanti.IDENTIFICAZIONE_TOKEN_KEY);
  421.                         break;
  422.                     }
  423.                 }
  424.                 else {
  425.                     search.setIdentificazione(Costanti.IDENTIFICAZIONE_TRASPORTO_KEY);
  426.                 }
  427.                 search.setServizioApplicativo(fAppl.getApplicativo());
  428.                 search.setTipoNomeMittente(new IDSoggetto(tipo_soggetto, fAppl.getSoggetto()).toString());
  429.                 break;
  430.             }
  431.             case IDENTIFICATIVO_AUTENTICATO: {
  432.                
  433.                 if(! (fMittente instanceof FiltroMittenteIdAutenticato)) {
  434.                     throw FaultCode.RICHIESTA_NON_VALIDA
  435.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  436.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIdAutenticato.class.getName()+")");
  437.                 }
  438.                 FiltroMittenteIdAutenticato fIdAutenticato = (FiltroMittenteIdAutenticato) fMittente;
  439.                 TransazioniHelper.overrideFiltroMittenteIdApplicativo(fIdAutenticato, search, env);
  440.                 break;
  441.             }

  442.             case EROGAZIONE_TOKEN_INFO: {
  443.                
  444.                 if(! (fMittente instanceof FiltroMittenteTokenClaimSoggetto)) {
  445.                     throw FaultCode.RICHIESTA_NON_VALIDA
  446.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  447.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteTokenClaimSoggetto.class.getName()+")");
  448.                 }
  449.                 FiltroMittenteTokenClaimSoggetto fClaim = (FiltroMittenteTokenClaimSoggetto) fMittente;
  450.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_TOKEN_INFO);
  451.                 search.setTokenClaim(Enums.toTipoCredenzialeMittente(fClaim.getClaim()).getRawValue());
  452.                 search.setMittenteMatchingType( (BooleanUtils.isTrue(fClaim.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  453.                 search.setMittenteCaseSensitiveType( (BooleanUtils.isTrue(fClaim.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE : CaseSensitiveMatch.INSENSITIVE).toString());
  454.                 search.setValoreRiconoscimento(fClaim.getId());
  455.                 if (!StringUtils.isEmpty(fClaim.getSoggetto()))
  456.                     search.setTipoNomeMittente(new IDSoggetto(tipo_soggetto, fClaim.getSoggetto()).toString());
  457.                 break;
  458.             }
  459.            
  460.             case TOKEN_INFO: {
  461.                
  462.                 if(! (fMittente instanceof FiltroMittenteTokenClaim)) {
  463.                     throw FaultCode.RICHIESTA_NON_VALIDA
  464.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  465.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteTokenClaim.class.getName()+")");
  466.                 }
  467.                 FiltroMittenteTokenClaim fClaim = (FiltroMittenteTokenClaim) fMittente;
  468.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_TOKEN_INFO);
  469.                 search.setTokenClaim(Enums.toTipoCredenzialeMittente(fClaim.getClaim()).getRawValue());
  470.                 search.setMittenteMatchingType( (BooleanUtils.isTrue(fClaim.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  471.                 search.setMittenteCaseSensitiveType( (BooleanUtils.isTrue(fClaim.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE : CaseSensitiveMatch.INSENSITIVE).toString());
  472.                 search.setValoreRiconoscimento(fClaim.getId());
  473.                 break;
  474.             }
  475.            
  476.             case INDIRIZZO_IP: {

  477.                 if(! (fMittente instanceof FiltroMittenteIndirizzoIP)) {
  478.                     throw FaultCode.RICHIESTA_NON_VALIDA
  479.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  480.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIndirizzoIP.class.getName()+")");
  481.                 }
  482.                 FiltroMittenteIndirizzoIP fIndirizzoIP = (FiltroMittenteIndirizzoIP) fMittente;
  483.                 TransazioniHelper.overrideFiltroMittenteIndirizzoIP(fIndirizzoIP, search, env);
  484.                 break;
  485.             }
  486.            
  487.             }
  488.             break;
  489.         }
  490.        
  491.         case QUALSIASI: {

  492.             switch (fMittente.getIdentificazione()) {
  493.            
  494.             case EROGAZIONE_SOGGETTO: {
  495.                 throw FaultCode.RICHIESTA_NON_VALIDA
  496.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  497.                             + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.QUALSIASI.toString()+"'");
  498.             }
  499.            
  500.             case FRUIZIONE_APPLICATIVO: {
  501.                 throw FaultCode.RICHIESTA_NON_VALIDA
  502.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  503.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.QUALSIASI.toString()+"'");
  504.             }
  505.            
  506.             case EROGAZIONE_APPLICATIVO: {
  507.                 throw FaultCode.RICHIESTA_NON_VALIDA
  508.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  509.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.QUALSIASI.toString()+"'");
  510.             }
  511.            
  512.             case IDENTIFICATIVO_AUTENTICATO: {
  513.                
  514.                 if(! (fMittente instanceof FiltroMittenteIdAutenticato)) {
  515.                     throw FaultCode.RICHIESTA_NON_VALIDA
  516.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  517.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIdAutenticato.class.getName()+")");
  518.                 }
  519.                 FiltroMittenteIdAutenticato fIdAutenticato = (FiltroMittenteIdAutenticato) fMittente;
  520.                 TransazioniHelper.overrideFiltroMittenteIdApplicativo(fIdAutenticato, search, env);
  521.                 break;
  522.             }

  523.             case EROGAZIONE_TOKEN_INFO: {
  524.                 throw FaultCode.RICHIESTA_NON_VALIDA
  525.                 .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  526.                         + "non utilizzabile in una ricerca di transazioni con il criterio ruolo impostato al valore '"+FiltroRicercaRuoloTransazioneEnum.QUALSIASI.toString()+"'");
  527.             }
  528.            
  529.             case TOKEN_INFO: {
  530.                
  531.                 if(! (fMittente instanceof FiltroMittenteTokenClaim)) {
  532.                     throw FaultCode.RICHIESTA_NON_VALIDA
  533.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  534.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteTokenClaim.class.getName()+")");
  535.                 }
  536.                 FiltroMittenteTokenClaim fClaim = (FiltroMittenteTokenClaim) fMittente;
  537.                 search.setRiconoscimento(Costanti.VALUE_TIPO_RICONOSCIMENTO_TOKEN_INFO);
  538.                 search.setTokenClaim(Enums.toTipoCredenzialeMittente(fClaim.getClaim()).getRawValue());
  539.                 search.setMittenteMatchingType( (BooleanUtils.isTrue(fClaim.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  540.                 search.setMittenteCaseSensitiveType( (BooleanUtils.isTrue(fClaim.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE : CaseSensitiveMatch.INSENSITIVE).toString());
  541.                 search.setValoreRiconoscimento(fClaim.getId());
  542.                 break;
  543.             }
  544.            
  545.             case INDIRIZZO_IP: {
  546.                
  547.                 if(! (fMittente instanceof FiltroMittenteIndirizzoIP)) {
  548.                     throw FaultCode.RICHIESTA_NON_VALIDA
  549.                     .toException("Identificazione '"+fMittente.getIdentificazione().toString()+"' "
  550.                             + "non utilizzabile con il tipo di filtro mittente utilizzato '"+fMittente.getClass().getName()+"' (atteso: "+FiltroMittenteIndirizzoIP.class.getName()+")");
  551.                 }
  552.                 FiltroMittenteIndirizzoIP fIndirizzoIP = (FiltroMittenteIndirizzoIP) fMittente;
  553.                 TransazioniHelper.overrideFiltroMittenteIndirizzoIP(fIndirizzoIP, search, env);
  554.                 break;
  555.             }
  556.            
  557.             }
  558.             break;
  559.         }
  560.        
  561.         }
  562.     }

  563.     /**
  564.      * Effettua la ricerca delle transazioni dato un oggetto TransazioniSearchForm correttamente popolato
  565.      */
  566.     public static final ListaTransazioni searchTransazioni(TransazioniSearchForm search, Integer offset, Integer limit,
  567.             String sort, MonitoraggioEnv env) throws UtilsException, InstantiationException, IllegalAccessException {
  568.         DBManager dbManager = DBManager.getInstance();
  569.         Connection connection = null;
  570.         try {
  571.             connection = dbManager.getConnectionTracce();
  572.             ServerProperties serverProperties = ServerProperties.getInstance();
  573.             ServiceManagerProperties smp = dbManager.getServiceManagerPropertiesTracce();
  574.             TransazioniService transazioniService = new TransazioniService(connection, true, smp,
  575.                     LoggerProperties.getLoggerDAO());
  576.             transazioniService.setSearch(search);

  577.             List<TransazioneBean> listTransazioniDB = transazioniService.findAll(Converter.toOffset(offset),
  578.                     Converter.toLimit(limit), Converter.toSortOrder(sort), Converter.toSortField(sort));
  579.             if(listTransazioniDB!=null && !listTransazioniDB.isEmpty()) {
  580.                 for (TransazioneBean transazioneBean : listTransazioniDB) {
  581.                     if(transazioneBean.getGruppiRawValue()!=null && !"".equals(transazioneBean.getGruppiRawValue())) {
  582.                         try {
  583.                             transazioniService.normalizeInfoTransazioniFromCredenzialiMittenteGruppi(transazioneBean, transazioneBean);
  584.                         }catch(Exception e) {
  585.                             throw new UtilsException(e.getMessage(),e);
  586.                         }
  587.                     }
  588.                    
  589.                     // finisce in principal
  590.                     if(transazioneBean.getTrasportoMittenteLabel()==null) {
  591.                         if(transazioneBean.getTrasportoMittente()!=null && !"".equals(transazioneBean.getTrasportoMittente())) {
  592.                             try {
  593.                                 transazioniService.normalizeInfoTransazioniFromCredenzialiMittenteTrasporto(transazioneBean, transazioneBean);
  594.                             }catch(Exception e) {
  595.                                 throw new UtilsException(e.getMessage(),e);
  596.                             }
  597.                         }
  598.                     }
  599.                    
  600.                     // finisce in utente
  601.                     if(transazioneBean.getTokenUsernameLabel()==null) {
  602.                         if(transazioneBean.getTokenUsername()!=null && !"".equals(transazioneBean.getTokenUsername())) {
  603.                             try {
  604.                                 transazioniService.normalizeInfoTransazioniFromCredenzialiMittenteTokenUsername(transazioneBean, transazioneBean);
  605.                             }catch(Exception e) {
  606.                                 throw new UtilsException(e.getMessage(),e);
  607.                             }
  608.                         }
  609.                     }
  610.                    
  611.                     // finisce in client
  612.                     if(transazioneBean.getTokenClientIdLabel()==null) {
  613.                         if(transazioneBean.getTokenClientId()!=null && !"".equals(transazioneBean.getTokenClientId())) {
  614.                             try {
  615.                                 transazioniService.normalizeInfoTransazioniFromCredenzialiMittenteTokenClientID(transazioneBean, transazioneBean);
  616.                             }catch(Exception e) {
  617.                                 throw new UtilsException(e.getMessage(),e);
  618.                             }
  619.                         }
  620.                     }
  621.                    
  622.                     // finisce in indirizzoClient e indirizzoClientInoltrato
  623.                     if(transazioneBean.getTransportClientAddressLabel()==null && transazioneBean.getSocketClientAddressLabel()==null) {
  624.                         if(transazioneBean.getClientAddress()!=null && !"".equals(transazioneBean.getClientAddress())) {
  625.                             try {
  626.                                 transazioniService.normalizeInfoTransazioniFromCredenzialiMittenteClientAddress(transazioneBean, transazioneBean);
  627.                             }catch(Exception e) {
  628.                                 throw new UtilsException(e.getMessage(),e);
  629.                             }
  630.                         }
  631.                     }
  632.                 }
  633.             }
  634.            
  635.             ListaTransazioni ret = ListaUtils.costruisciLista(env.context.getUriInfo(),
  636.                     Converter.toOffset(offset), Converter.toLimit(limit),
  637.                     listTransazioniDB != null ? listTransazioniDB.size() : 0, ListaTransazioni.class);

  638.             if (serverProperties.isFindall404() && (listTransazioniDB == null || listTransazioniDB.isEmpty()))
  639.                 throw FaultCode.NOT_FOUND
  640.                         .toException("Nessuna transazione trovata corrispondente ai criteri di ricerca");

  641.             if (listTransazioniDB != null && !listTransazioniDB.isEmpty()) {
  642.                 listTransazioniDB.forEach(transazioneDB -> {
  643.                     try {
  644.                         ret.addItemsItem(Converter.toItemTransazione(transazioneDB, env.log));
  645.                     } catch (Exception e) {
  646.                         throw new RuntimeException(e.getMessage(), e);
  647.                     }
  648.                 });
  649.             }

  650.             env.context.getLogger().info("Invocazione completata con successo");
  651.             return ret;
  652.         } finally {
  653.             dbManager.releaseConnectionTracce(connection);
  654.         }
  655.     }
  656.    
  657.    
  658.     public static final ListaTransazioni findAllTransazioniByIdApplicativo(RicercaIdApplicativo body, MonitoraggioEnv env) throws Exception {
  659.         SearchFormUtilities searchFormUtilities = new SearchFormUtilities();
  660.         TransazioniSearchForm search = searchFormUtilities.getIdApplicativoSearchForm(env.context, env.profilo, env.nomeSoggettoLocale,
  661.                 body.getTipo(), body.getIntervalloTemporale().getDataInizio(), body.getIntervalloTemporale().getDataFine());
  662.        
  663.         TransazioniHelper.overrideRicercaBaseTransazione(body, search, env);

  664.         FiltroRicercaId filtro = body.getIdApplicativo();
  665.         search.setCorrelazioneApplicativaCaseSensitiveType((BooleanUtils.isTrue(filtro.isCaseSensitive()) ? CaseSensitiveMatch.SENSITIVE : CaseSensitiveMatch.INSENSITIVE).toString() );
  666.         search.setCorrelazioneApplicativaMatchingType((BooleanUtils.isTrue(filtro.isRicercaEsatta()) ? TipoMatch.EQUALS : TipoMatch.LIKE).toString());
  667.         search.setIdCorrelazioneApplicativa(filtro.getId());            
  668.        
  669.         ListaTransazioni ret = TransazioniHelper.searchTransazioni(search, body.getOffset(), body.getLimit(), body.getSort(), env);
  670.         return ret;
  671.     }
  672.    
  673.    
  674.     public static final ListaTransazioni findAllTransazioni(RicercaIntervalloTemporale body, MonitoraggioEnv env) throws Exception {
  675.         SearchFormUtilities searchFormUtilities = new SearchFormUtilities();
  676.         TransazioniSearchForm search = searchFormUtilities.getAndamentoTemporaleSearchForm(env.context, env.profilo, env.nomeSoggettoLocale,
  677.                 body.getTipo(), body.getIntervalloTemporale().getDataInizio(), body.getIntervalloTemporale().getDataFine());
  678.        
  679.         TransazioniHelper.overrideRicercaBaseTransazione(body, search, env);
  680.         TransazioniHelper.overrideFiltroMittente(body, search, env);
  681.        
  682.         return TransazioniHelper.searchTransazioni(search, body.getOffset(), body.getLimit(), body.getSort(), env);
  683.     }
  684. }