TracciamentoCompatibilitaFiltroEsiti.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.config.utils;

  21. import org.openspcoop2.core.config.TracciamentoConfigurazione;

  22. /**
  23.  * TracciamentoCompatibilitaFiltroEsiti
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class TracciamentoCompatibilitaFiltroEsiti {

  30.     private TracciamentoConfigurazione database;
  31.     private TracciamentoConfigurazione filetrace;
  32.    
  33.     public  TracciamentoCompatibilitaFiltroEsiti(TracciamentoConfigurazione database, TracciamentoConfigurazione filetrace) {
  34.         this.database = database;
  35.         this.filetrace = filetrace;
  36.     }
  37.    
  38.     // METODI SPECIFICI DATABASE
  39.    
  40.     public boolean isTracciamentoDBEnabled() {
  41.         if (this.database==null
  42.                 || this.database.getStato()==null) {
  43.             return true; // default
  44.         }
  45.         return !org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.DISABILITATO.equals(this.database.getStato());
  46.     }
  47.    
  48.     public boolean isTracciamentoDBRequestInEnabledBloccante() {
  49.         return this.database!=null &&
  50.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  51.                 this.database.getRequestIn()!=null &&
  52.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.database.getRequestIn());
  53.     }
  54.     public boolean isTracciamentoDBRequestInEnabledNonBloccante() {
  55.         return this.database!=null &&
  56.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  57.                 this.database.getRequestIn()!=null &&
  58.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.database.getRequestIn());
  59.     }
  60.    
  61.     public boolean isTracciamentoDBRequestOutEnabledBloccante() {
  62.         return this.database!=null &&
  63.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  64.                 this.database.getRequestOut()!=null &&
  65.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.database.getRequestOut());
  66.     }
  67.     public boolean isTracciamentoDBRequestOutEnabledNonBloccante() {
  68.         return this.database!=null &&
  69.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  70.                 this.database.getRequestOut()!=null &&
  71.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.database.getRequestOut());
  72.     }
  73.    
  74.     public boolean isTracciamentoDBResponseOutEnabledBloccante() {
  75.         return this.database!=null &&
  76.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  77.                 this.database.getResponseOut()!=null &&
  78.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.database.getResponseOut());
  79.     }
  80.     public boolean isTracciamentoDBResponseOutEnabledNonBloccante() {
  81.         return this.database!=null &&
  82.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.database.getStato()) &&
  83.                 this.database.getResponseOut()!=null &&
  84.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.database.getResponseOut());
  85.     }
  86.    
  87.     public boolean isTracciamentoDBResponseOutCompleteEnabled() {
  88.         if (this.database==null ||
  89.                 this.database.getStato()==null) {
  90.             return true; // default
  91.         }
  92.         switch (this.database.getStato()) {
  93.         case ABILITATO:
  94.         case CONFIGURAZIONE_ESTERNA: // abilitato; non esiste una configurazione su proprietà
  95.             return true;
  96.         case DISABILITATO:
  97.             return false;
  98.         case PERSONALIZZATO:
  99.             return (
  100.                     this.database.getResponseOutComplete()==null // default
  101.                     ||
  102.                     org.openspcoop2.core.config.constants.StatoFunzionalita.ABILITATO.equals(this.database.getResponseOutComplete())
  103.                 );
  104.         }
  105.         return true;
  106.     }
  107.    
  108.     public boolean isFilterDBEnabled() {
  109.         if(!this.isTracciamentoDBEnabled()) {
  110.             return false;
  111.         }
  112.         if (this.database==null) {
  113.             return true; // default
  114.         }
  115.         if (this.database.getFiltroEsiti()==null) {
  116.             return true; // default
  117.         }
  118.         if(org.openspcoop2.core.config.constants.StatoFunzionalita.DISABILITATO.equals(this.database.getFiltroEsiti())) {
  119.             return false;
  120.         }
  121.        
  122.         // se e' abilitata la registrazione iniziale, non può essere effettuato alcun filtro sull'esito.
  123.         // gli altri filtri invece possono essere sensati, a patto che non sia già stata effettuata una registrazione
  124.         // nel contesto, prima di fare lo skip, verrà verificato se è già stata attuata una registrazione
  125.         return !isTracciamentoDBRequestInEnabledBloccante() && !isTracciamentoDBRequestInEnabledNonBloccante();
  126.     }
  127.    
  128.    
  129.     // METODI SPECIFICI FILETRACE
  130.    
  131.     public boolean isTracciamentoFileTraceEnabled() {
  132.         if (this.filetrace==null
  133.                 || this.filetrace.getStato()==null) {
  134.             return true; // default: verrò consultata la configurazione su file di proprietà
  135.         }
  136.         return !org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.DISABILITATO.equals(this.filetrace.getStato());
  137.     }
  138.     public boolean isTracciamentoFileTraceEnabledByExternalProperties() {
  139.         if (this.filetrace==null
  140.                 || this.filetrace.getStato()==null) {
  141.             return true; // default: verrò consultata la configurazione su file di proprietà
  142.         }
  143.         return org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.CONFIGURAZIONE_ESTERNA.equals(this.filetrace.getStato());
  144.     }
  145.    
  146.     public boolean isTracciamentoFileTraceRequestInEnabledBloccante() {
  147.         return this.filetrace!=null &&
  148.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  149.                 this.filetrace.getRequestIn()!=null &&
  150.                 (org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.filetrace.getRequestIn()));
  151.     }
  152.     public boolean isTracciamentoFileTraceRequestInEnabledNonBloccante() {
  153.         return this.filetrace!=null &&
  154.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  155.                 this.filetrace.getRequestIn()!=null &&
  156.                 (org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.filetrace.getRequestIn()));
  157.     }
  158.    
  159.     public boolean isTracciamentoFileTraceRequestOutEnabledBloccante() {
  160.         return this.filetrace!=null &&
  161.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  162.                 this.filetrace.getRequestOut()!=null &&
  163.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.filetrace.getRequestOut());
  164.     }
  165.     public boolean isTracciamentoFileTraceRequestOutEnabledNonBloccante() {
  166.         return this.filetrace!=null &&
  167.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  168.                 this.filetrace.getRequestOut()!=null &&
  169.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.filetrace.getRequestOut());
  170.     }
  171.    
  172.     public boolean isTracciamentoFileTraceResponseOutEnabledBloccante() {
  173.         return this.filetrace!=null &&
  174.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  175.                 this.filetrace.getResponseOut()!=null &&
  176.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.ABILITATO.equals(this.filetrace.getResponseOut());
  177.     }
  178.     public boolean isTracciamentoFileTraceResponseOutEnabledNonBloccante() {
  179.         return this.filetrace!=null &&
  180.                 org.openspcoop2.core.config.constants.StatoFunzionalitaConPersonalizzazione.PERSONALIZZATO.equals(this.filetrace.getStato()) &&
  181.                 this.filetrace.getResponseOut()!=null &&
  182.                 org.openspcoop2.core.config.constants.StatoFunzionalitaBloccante.NON_BLOCCANTE.equals(this.filetrace.getResponseOut());
  183.     }
  184.    
  185.     public boolean isTracciamentoFileTraceResponseOutCompleteEnabled() {
  186.         if (this.filetrace==null ||
  187.                 this.filetrace.getStato()==null) {
  188.             return false; // default
  189.         }
  190.         switch (this.filetrace.getStato()) {
  191.         case ABILITATO:
  192.         case CONFIGURAZIONE_ESTERNA: // si assume per default abilitato se è abilitato via file esterno
  193.             return true;
  194.         case DISABILITATO:
  195.             return false;
  196.         case PERSONALIZZATO:
  197.             return (
  198.                     this.filetrace.getResponseOutComplete()==null // default
  199.                     ||
  200.                     org.openspcoop2.core.config.constants.StatoFunzionalita.ABILITATO.equals(this.filetrace.getResponseOutComplete())
  201.                 );
  202.         }
  203.         return true;
  204.     }
  205.    
  206.     public boolean isFilterFileTraceEnabled() {
  207.         if(!this.isTracciamentoFileTraceEnabled()) {
  208.             return false;
  209.         }
  210.         if (this.filetrace==null) {
  211.             return false; // default
  212.         }
  213.         if (this.filetrace.getFiltroEsiti()==null) {
  214.             return false; // default
  215.         }
  216.         if(org.openspcoop2.core.config.constants.StatoFunzionalita.DISABILITATO.equals(this.filetrace.getFiltroEsiti())) {
  217.             return false;
  218.         }

  219.         // se e' abilitata la registrazione iniziale, non può essere effettuato alcun filtro sull'esito.
  220.         // gli altri filtri invece possono essere sensati, a patto che non sia già stata effettuata una registrazione
  221.         // nel contesto, prima di fare lo skip, verrà verificato se è già stata attuata una registrazione
  222.         return !isTracciamentoFileTraceRequestInEnabledBloccante() && !isTracciamentoFileTraceRequestInEnabledNonBloccante();
  223.     }

  224.    
  225.    
  226.    
  227.     // METODI GENERICI
  228.    

  229.     public boolean isTracciamentoEnabled() {
  230.         return this.isTracciamentoDBEnabled() || this.isTracciamentoFileTraceEnabled();
  231.     }
  232.    
  233.     public boolean isTracciamentoRequestInEnabledBloccante() {
  234.         return this.isTracciamentoDBRequestInEnabledBloccante() || this.isTracciamentoFileTraceRequestInEnabledBloccante();
  235.     }
  236.     public boolean isTracciamentoRequestInEnabledNonBloccante() {
  237.         return this.isTracciamentoDBRequestInEnabledNonBloccante() || this.isTracciamentoFileTraceRequestInEnabledNonBloccante();
  238.     }
  239.     @SuppressWarnings("unused")
  240.     private boolean isTracciamentoRequestInEnabled() {
  241.         return isTracciamentoRequestInEnabledBloccante() || isTracciamentoRequestInEnabledNonBloccante();
  242.     }
  243.    
  244.     public boolean isTracciamentoRequestOutEnabledBloccante() {
  245.         return this.isTracciamentoDBRequestOutEnabledBloccante() || this.isTracciamentoFileTraceRequestOutEnabledBloccante();
  246.     }
  247.     public boolean isTracciamentoRequestOutEnabledNonBloccante() {
  248.         return this.isTracciamentoDBRequestOutEnabledNonBloccante() || this.isTracciamentoFileTraceRequestOutEnabledNonBloccante();
  249.     }
  250.     @SuppressWarnings("unused")
  251.     private boolean isTracciamentoRequestOutEnabled() {
  252.         return isTracciamentoRequestOutEnabledBloccante() || isTracciamentoRequestOutEnabledNonBloccante();
  253.     }
  254.    
  255.     public boolean isTracciamentoResponseOutEnabledBloccante() {
  256.         return this.isTracciamentoDBResponseOutEnabledBloccante() || this.isTracciamentoFileTraceResponseOutEnabledBloccante();
  257.     }
  258.     public boolean isTracciamentoResponseOutEnabledNonBloccante() {
  259.         return this.isTracciamentoDBResponseOutEnabledNonBloccante() || this.isTracciamentoFileTraceResponseOutEnabledNonBloccante();
  260.     }
  261.     @SuppressWarnings("unused")
  262.     private boolean isTracciamentoResponseOutEnabled() {
  263.         return isTracciamentoResponseOutEnabledBloccante() || isTracciamentoResponseOutEnabledNonBloccante();
  264.     }
  265.    
  266.     public boolean isTracciamentoResponseOutCompleteEnabled() {
  267.         return this.isTracciamentoDBResponseOutCompleteEnabled() || this.isTracciamentoFileTraceResponseOutCompleteEnabled();
  268.     }
  269.    
  270.     public boolean isFilterEnabled() {
  271.         return this.isFilterDBEnabled() || this.isFilterFileTraceEnabled();
  272.     }
  273.     public String getWarningMessageFilter() {
  274.         boolean dbCase = false;
  275.         boolean filetraceCase = false;
  276.         if(this.isFilterDBEnabled() &&
  277.             (
  278.                     this.isTracciamentoDBRequestOutEnabledBloccante() || this.isTracciamentoDBRequestOutEnabledNonBloccante()
  279.                     ||
  280.                     this.isTracciamentoDBResponseOutEnabledBloccante() || this.isTracciamentoDBResponseOutEnabledNonBloccante()
  281.             )
  282.         ) {
  283.             dbCase = true;
  284.         }
  285.         if(this.isFilterFileTraceEnabled() &&
  286.             (
  287.                     this.isTracciamentoFileTraceRequestOutEnabledBloccante() ||  this.isTracciamentoFileTraceRequestOutEnabledNonBloccante()
  288.                     ||
  289.                     this.isTracciamentoFileTraceResponseOutEnabledBloccante() || this.isTracciamentoFileTraceResponseOutEnabledNonBloccante()
  290.             )
  291.         ) {
  292.             filetraceCase = true;
  293.         }
  294.        
  295.         String posizione = null;
  296.         if(dbCase && !filetraceCase) {
  297.             posizione = " su database";
  298.         }
  299.         else if(!dbCase && filetraceCase) {
  300.             posizione = " tramite filetrace";
  301.         }
  302.         else if(dbCase
  303.                 //&& filetrace
  304.                 ) {
  305.             posizione = "";
  306.         }
  307.        
  308.         if(posizione!=null) {
  309.             return "La registrazione"+posizione+", attiva per la fase di consegna di una richiesta e/o di una risposta,<br/>non consente di filtrare esiti relativi ad errori di consegna o di processamento della risposta.";
  310.         }
  311.        
  312.         return null;
  313.     }
  314.    
  315. }