ConfigurazioneGeneraleFieldConverter.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.controllo_traffico.dao.jdbc.converter;

  21. import org.openspcoop2.generic_project.beans.IField;
  22. import org.openspcoop2.generic_project.beans.IModel;
  23. import org.openspcoop2.generic_project.exception.ExpressionException;
  24. import org.openspcoop2.generic_project.expression.impl.sql.AbstractSQLFieldConverter;
  25. import org.openspcoop2.utils.TipiDatabase;
  26. import org.openspcoop2.core.constants.CostantiDB;
  27. import org.openspcoop2.core.controllo_traffico.ConfigurazioneGenerale;


  28. /**    
  29.  * ConfigurazioneGeneraleFieldConverter
  30.  *
  31.  * @author Poli Andrea (poli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class ConfigurazioneGeneraleFieldConverter extends AbstractSQLFieldConverter {

  36.     private TipiDatabase databaseType;
  37.    
  38.     public ConfigurazioneGeneraleFieldConverter(String databaseType){
  39.         this.databaseType = TipiDatabase.toEnumConstant(databaseType);
  40.     }
  41.     public ConfigurazioneGeneraleFieldConverter(TipiDatabase databaseType){
  42.         this.databaseType = databaseType;
  43.     }


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return ConfigurazioneGenerale.model();
  47.     }
  48.    
  49.     @Override
  50.     public TipiDatabase getDatabaseType() throws ExpressionException {
  51.         return this.databaseType;
  52.     }
  53.    


  54.     @Override
  55.     public String toColumn(IField field,boolean returnAlias,boolean appendTablePrefix) throws ExpressionException {
  56.        
  57.         // In the case of columns with alias, using parameter returnAlias​​,
  58.         // it is possible to drive the choice whether to return only the alias or
  59.         // the full definition of the column containing the alias
  60.        
  61.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_ENABLED)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".max_threads_enabled";
  64.             }else{
  65.                 return "max_threads_enabled";
  66.             }
  67.         }
  68.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_WARNING_ONLY)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".max_threads_warning_only";
  71.             }else{
  72.                 return "max_threads_warning_only";
  73.             }
  74.         }
  75.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_SOGLIA)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".max_threads";
  78.             }else{
  79.                 return "max_threads";
  80.             }
  81.         }
  82.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_TIPO_ERRORE)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".max_threads_tipo_errore";
  85.             }else{
  86.                 return "max_threads_tipo_errore";
  87.             }
  88.         }
  89.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_TIPO_ERRORE_INCLUDI_DESCRIZIONE)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".max_threads_includi_errore";
  92.             }else{
  93.                 return "max_threads_includi_errore";
  94.             }
  95.         }
  96.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_CONGESTIONE_ENABLED)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".cc_enabled";
  99.             }else{
  100.                 return "cc_enabled";
  101.             }
  102.         }
  103.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_CONGESTIONE_THRESHOLD)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".cc_threshold";
  106.             }else{
  107.                 return "cc_threshold";
  108.             }
  109.         }
  110.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.CONNECTION_TIMEOUT)){
  111.             if(appendTablePrefix){
  112.                 return this.toAliasTable(field)+".pd_connection_timeout";
  113.             }else{
  114.                 return "pd_connection_timeout";
  115.             }
  116.         }
  117.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.READ_TIMEOUT)){
  118.             if(appendTablePrefix){
  119.                 return this.toAliasTable(field)+".pd_read_timeout";
  120.             }else{
  121.                 return "pd_read_timeout";
  122.             }
  123.         }
  124.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.TEMPO_MEDIO_RISPOSTA)){
  125.             if(appendTablePrefix){
  126.                 return this.toAliasTable(field)+".pd_avg_time";
  127.             }else{
  128.                 return "pd_avg_time";
  129.             }
  130.         }
  131.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.CONNECTION_TIMEOUT)){
  132.             if(appendTablePrefix){
  133.                 return this.toAliasTable(field)+".pa_connection_timeout";
  134.             }else{
  135.                 return "pa_connection_timeout";
  136.             }
  137.         }
  138.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.READ_TIMEOUT)){
  139.             if(appendTablePrefix){
  140.                 return this.toAliasTable(field)+".pa_read_timeout";
  141.             }else{
  142.                 return "pa_read_timeout";
  143.             }
  144.         }
  145.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.TEMPO_MEDIO_RISPOSTA)){
  146.             if(appendTablePrefix){
  147.                 return this.toAliasTable(field)+".pa_avg_time";
  148.             }else{
  149.                 return "pa_avg_time";
  150.             }
  151.         }
  152.         if(field.equals(ConfigurazioneGenerale.model().RATE_LIMITING.TIPO_ERRORE)){
  153.             if(appendTablePrefix){
  154.                 return this.toAliasTable(field)+".rt_tipo_errore";
  155.             }else{
  156.                 return "rt_tipo_errore";
  157.             }
  158.         }
  159.         if(field.equals(ConfigurazioneGenerale.model().RATE_LIMITING.TIPO_ERRORE_INCLUDI_DESCRIZIONE)){
  160.             if(appendTablePrefix){
  161.                 return this.toAliasTable(field)+".rt_includi_errore";
  162.             }else{
  163.                 return "rt_includi_errore";
  164.             }
  165.         }
  166.         if(field.equals(ConfigurazioneGenerale.model().CACHE.CACHE)){
  167.             if(appendTablePrefix){
  168.                 return this.toAliasTable(field)+".cache";
  169.             }else{
  170.                 return "cache";
  171.             }
  172.         }
  173.         if(field.equals(ConfigurazioneGenerale.model().CACHE.SIZE)){
  174.             if(appendTablePrefix){
  175.                 return this.toAliasTable(field)+".cache_size";
  176.             }else{
  177.                 return "cache_size";
  178.             }
  179.         }
  180.         if(field.equals(ConfigurazioneGenerale.model().CACHE.ALGORITHM)){
  181.             if(appendTablePrefix){
  182.                 return this.toAliasTable(field)+".cache_algorithm";
  183.             }else{
  184.                 return "cache_algorithm";
  185.             }
  186.         }
  187.         if(field.equals(ConfigurazioneGenerale.model().CACHE.IDLE_TIME)){
  188.             if(appendTablePrefix){
  189.                 return this.toAliasTable(field)+".cache_idle_time";
  190.             }else{
  191.                 return "cache_idle_time";
  192.             }
  193.         }
  194.         if(field.equals(ConfigurazioneGenerale.model().CACHE.LIFE_TIME)){
  195.             if(appendTablePrefix){
  196.                 return this.toAliasTable(field)+".cache_life_time";
  197.             }else{
  198.                 return "cache_life_time";
  199.             }
  200.         }


  201.         return super.toColumn(field,returnAlias,appendTablePrefix);
  202.        
  203.     }
  204.    
  205.     @Override
  206.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  207.        
  208.         // In the case of table with alias, using parameter returnAlias​​,
  209.         // it is possible to drive the choice whether to return only the alias or
  210.         // the full definition of the table containing the alias
  211.        
  212.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_ENABLED)){
  213.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  214.         }
  215.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_WARNING_ONLY)){
  216.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  217.         }
  218.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_SOGLIA)){
  219.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  220.         }
  221.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_TIPO_ERRORE)){
  222.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  223.         }
  224.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_MAX_THREADS_TIPO_ERRORE_INCLUDI_DESCRIZIONE)){
  225.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  226.         }
  227.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_CONGESTIONE_ENABLED)){
  228.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  229.         }
  230.         if(field.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO.CONTROLLO_CONGESTIONE_THRESHOLD)){
  231.             return this.toTable(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO, returnAlias);
  232.         }
  233.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.CONNECTION_TIMEOUT)){
  234.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE, returnAlias);
  235.         }
  236.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.READ_TIMEOUT)){
  237.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE, returnAlias);
  238.         }
  239.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE.TEMPO_MEDIO_RISPOSTA)){
  240.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE, returnAlias);
  241.         }
  242.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.CONNECTION_TIMEOUT)){
  243.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE, returnAlias);
  244.         }
  245.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.READ_TIMEOUT)){
  246.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE, returnAlias);
  247.         }
  248.         if(field.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE.TEMPO_MEDIO_RISPOSTA)){
  249.             return this.toTable(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE, returnAlias);
  250.         }
  251.         if(field.equals(ConfigurazioneGenerale.model().RATE_LIMITING.TIPO_ERRORE)){
  252.             return this.toTable(ConfigurazioneGenerale.model().RATE_LIMITING, returnAlias);
  253.         }
  254.         if(field.equals(ConfigurazioneGenerale.model().RATE_LIMITING.TIPO_ERRORE_INCLUDI_DESCRIZIONE)){
  255.             return this.toTable(ConfigurazioneGenerale.model().RATE_LIMITING, returnAlias);
  256.         }
  257.         if(field.equals(ConfigurazioneGenerale.model().CACHE.CACHE)){
  258.             return this.toTable(ConfigurazioneGenerale.model().CACHE, returnAlias);
  259.         }
  260.         if(field.equals(ConfigurazioneGenerale.model().CACHE.SIZE)){
  261.             return this.toTable(ConfigurazioneGenerale.model().CACHE, returnAlias);
  262.         }
  263.         if(field.equals(ConfigurazioneGenerale.model().CACHE.ALGORITHM)){
  264.             return this.toTable(ConfigurazioneGenerale.model().CACHE, returnAlias);
  265.         }
  266.         if(field.equals(ConfigurazioneGenerale.model().CACHE.IDLE_TIME)){
  267.             return this.toTable(ConfigurazioneGenerale.model().CACHE, returnAlias);
  268.         }
  269.         if(field.equals(ConfigurazioneGenerale.model().CACHE.LIFE_TIME)){
  270.             return this.toTable(ConfigurazioneGenerale.model().CACHE, returnAlias);
  271.         }


  272.         return super.toTable(field,returnAlias);
  273.        
  274.     }

  275.     @Override
  276.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  277.        
  278.         // In the case of table with alias, using parameter returnAlias​​,
  279.         // it is possible to drive the choice whether to return only the alias or
  280.         // the full definition of the table containing the alias
  281.        
  282.         if(model.equals(ConfigurazioneGenerale.model())){
  283.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  284.         }
  285.         if(model.equals(ConfigurazioneGenerale.model().CONTROLLO_TRAFFICO)){
  286.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  287.         }
  288.         if(model.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_FRUIZIONE)){
  289.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  290.         }
  291.         if(model.equals(ConfigurazioneGenerale.model().TEMPI_RISPOSTA_EROGAZIONE)){
  292.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  293.         }
  294.         if(model.equals(ConfigurazioneGenerale.model().RATE_LIMITING)){
  295.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  296.         }
  297.         if(model.equals(ConfigurazioneGenerale.model().CACHE)){
  298.             return CostantiDB.CONTROLLO_TRAFFICO_CONFIG;
  299.         }


  300.         return super.toTable(model,returnAlias);
  301.        
  302.     }

  303. }