ConfigurazioneFiltroFieldConverter.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.plugins.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.plugins.ConfigurazioneFiltro;


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

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


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


  53.     @Override
  54.     public String toColumn(IField field,boolean returnAlias,boolean appendTablePrefix) throws ExpressionException {
  55.        
  56.         // In the case of columns with alias, using parameter returnAlias​​,
  57.         // it is possible to drive the choice whether to return only the alias or
  58.         // the full definition of the column containing the alias
  59.        
  60.         if(field.equals(ConfigurazioneFiltro.model().NOME)){
  61.             if(appendTablePrefix){
  62.                 return this.toAliasTable(field)+".nome";
  63.             }else{
  64.                 return "nome";
  65.             }
  66.         }
  67.         if(field.equals(ConfigurazioneFiltro.model().DESCRIZIONE)){
  68.             if(appendTablePrefix){
  69.                 return this.toAliasTable(field)+".descrizione";
  70.             }else{
  71.                 return "descrizione";
  72.             }
  73.         }
  74.         if(field.equals(ConfigurazioneFiltro.model().TIPO_MITTENTE)){
  75.             if(appendTablePrefix){
  76.                 return this.toAliasTable(field)+".tipo_mittente";
  77.             }else{
  78.                 return "tipo_mittente";
  79.             }
  80.         }
  81.         if(field.equals(ConfigurazioneFiltro.model().NOME_MITTENTE)){
  82.             if(appendTablePrefix){
  83.                 return this.toAliasTable(field)+".nome_mittente";
  84.             }else{
  85.                 return "nome_mittente";
  86.             }
  87.         }
  88.         if(field.equals(ConfigurazioneFiltro.model().IDPORTA_MITTENTE)){
  89.             if(appendTablePrefix){
  90.                 return this.toAliasTable(field)+".idporta_mittente";
  91.             }else{
  92.                 return "idporta_mittente";
  93.             }
  94.         }
  95.         if(field.equals(ConfigurazioneFiltro.model().TIPO_DESTINATARIO)){
  96.             if(appendTablePrefix){
  97.                 return this.toAliasTable(field)+".tipo_destinatario";
  98.             }else{
  99.                 return "tipo_destinatario";
  100.             }
  101.         }
  102.         if(field.equals(ConfigurazioneFiltro.model().NOME_DESTINATARIO)){
  103.             if(appendTablePrefix){
  104.                 return this.toAliasTable(field)+".nome_destinatario";
  105.             }else{
  106.                 return "nome_destinatario";
  107.             }
  108.         }
  109.         if(field.equals(ConfigurazioneFiltro.model().IDPORTA_DESTINATARIO)){
  110.             if(appendTablePrefix){
  111.                 return this.toAliasTable(field)+".idporta_destinatario";
  112.             }else{
  113.                 return "idporta_destinatario";
  114.             }
  115.         }
  116.         if(field.equals(ConfigurazioneFiltro.model().TIPO_SERVIZIO)){
  117.             if(appendTablePrefix){
  118.                 return this.toAliasTable(field)+".tipo_servizio";
  119.             }else{
  120.                 return "tipo_servizio";
  121.             }
  122.         }
  123.         if(field.equals(ConfigurazioneFiltro.model().NOME_SERVIZIO)){
  124.             if(appendTablePrefix){
  125.                 return this.toAliasTable(field)+".nome_servizio";
  126.             }else{
  127.                 return "nome_servizio";
  128.             }
  129.         }
  130.         if(field.equals(ConfigurazioneFiltro.model().VERSIONE_SERVIZIO)){
  131.             if(appendTablePrefix){
  132.                 return this.toAliasTable(field)+".versione_servizio";
  133.             }else{
  134.                 return "versione_servizio";
  135.             }
  136.         }
  137.         if(field.equals(ConfigurazioneFiltro.model().AZIONE)){
  138.             if(appendTablePrefix){
  139.                 return this.toAliasTable(field)+".azione";
  140.             }else{
  141.                 return "azione";
  142.             }
  143.         }


  144.         return super.toColumn(field,returnAlias,appendTablePrefix);
  145.        
  146.     }
  147.    
  148.     @Override
  149.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  150.        
  151.         // In the case of table with alias, using parameter returnAlias​​,
  152.         // it is possible to drive the choice whether to return only the alias or
  153.         // the full definition of the table containing the alias
  154.        
  155.         if(field.equals(ConfigurazioneFiltro.model().NOME)){
  156.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  157.         }
  158.         if(field.equals(ConfigurazioneFiltro.model().DESCRIZIONE)){
  159.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  160.         }
  161.         if(field.equals(ConfigurazioneFiltro.model().TIPO_MITTENTE)){
  162.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  163.         }
  164.         if(field.equals(ConfigurazioneFiltro.model().NOME_MITTENTE)){
  165.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  166.         }
  167.         if(field.equals(ConfigurazioneFiltro.model().IDPORTA_MITTENTE)){
  168.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  169.         }
  170.         if(field.equals(ConfigurazioneFiltro.model().TIPO_DESTINATARIO)){
  171.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  172.         }
  173.         if(field.equals(ConfigurazioneFiltro.model().NOME_DESTINATARIO)){
  174.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  175.         }
  176.         if(field.equals(ConfigurazioneFiltro.model().IDPORTA_DESTINATARIO)){
  177.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  178.         }
  179.         if(field.equals(ConfigurazioneFiltro.model().TIPO_SERVIZIO)){
  180.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  181.         }
  182.         if(field.equals(ConfigurazioneFiltro.model().NOME_SERVIZIO)){
  183.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  184.         }
  185.         if(field.equals(ConfigurazioneFiltro.model().VERSIONE_SERVIZIO)){
  186.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  187.         }
  188.         if(field.equals(ConfigurazioneFiltro.model().AZIONE)){
  189.             return this.toTable(ConfigurazioneFiltro.model(), returnAlias);
  190.         }


  191.         return super.toTable(field,returnAlias);
  192.        
  193.     }

  194.     @Override
  195.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  196.        
  197.         // In the case of table with alias, using parameter returnAlias​​,
  198.         // it is possible to drive the choice whether to return only the alias or
  199.         // the full definition of the table containing the alias
  200.        
  201.         if(model.equals(ConfigurazioneFiltro.model())){
  202.             return "plugins_conf_filtri";
  203.         }


  204.         return super.toTable(model,returnAlias);
  205.        
  206.     }

  207. }