ConfigurazioneRicercaFieldConverter.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.monitor.engine.config.ricerche.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.monitor.engine.config.ricerche.ConfigurazioneRicerca;


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

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


  43.     @Override
  44.     public IModel<?> getRootModel() throws ExpressionException {
  45.         return ConfigurazioneRicerca.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(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA)){
  61.             if(appendTablePrefix){
  62.                 return this.toAliasTable(field)+".id";
  63.             }else{
  64.                 return "id";
  65.             }
  66.         }
  67.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.ACCORDO)){
  68.             if(appendTablePrefix){
  69.                 return this.toAliasTable(field)+".accordo";
  70.             }else{
  71.                 return "accordo";
  72.             }
  73.         }
  74.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.TIPO_SOGGETTO_REFERENTE)){
  75.             if(appendTablePrefix){
  76.                 return this.toAliasTable(field)+".tipo_soggetto_referente";
  77.             }else{
  78.                 return "tipo_soggetto_referente";
  79.             }
  80.         }
  81.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.NOME_SOGGETTO_REFERENTE)){
  82.             if(appendTablePrefix){
  83.                 return this.toAliasTable(field)+".nome_soggetto_referente";
  84.             }else{
  85.                 return "nome_soggetto_referente";
  86.             }
  87.         }
  88.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.VERSIONE)){
  89.             if(appendTablePrefix){
  90.                 return this.toAliasTable(field)+".versione";
  91.             }else{
  92.                 return "versione";
  93.             }
  94.         }
  95.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.SERVIZIO)){
  96.             if(appendTablePrefix){
  97.                 return this.toAliasTable(field)+".servizio";
  98.             }else{
  99.                 return "servizio";
  100.             }
  101.         }
  102.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.AZIONE)){
  103.             if(appendTablePrefix){
  104.                 return this.toAliasTable(field)+".azione";
  105.             }else{
  106.                 return "azione";
  107.             }
  108.         }
  109.         if(field.equals(ConfigurazioneRicerca.model().ENABLED)){
  110.             if(appendTablePrefix){
  111.                 return this.toAliasTable(field)+".enabled";
  112.             }else{
  113.                 return "enabled";
  114.             }
  115.         }
  116.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.TIPO)){
  117.             if(appendTablePrefix){
  118.                 return this.toAliasTable(field)+".tipo";
  119.             }else{
  120.                 return "tipo";
  121.             }
  122.         }
  123.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.CLASS_NAME)){
  124.             if(appendTablePrefix){
  125.                 return this.toAliasTable(field)+".class_name";
  126.             }else{
  127.                 return "class_name";
  128.             }
  129.         }
  130.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.DESCRIZIONE)){
  131.             if(appendTablePrefix){
  132.                 return this.toAliasTable(field)+".descrizione";
  133.             }else{
  134.                 return "descrizione";
  135.             }
  136.         }
  137.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.LABEL)){
  138.             if(appendTablePrefix){
  139.                 return this.toAliasTable(field)+".label";
  140.             }else{
  141.                 return "label";
  142.             }
  143.         }
  144.         if(field.equals(ConfigurazioneRicerca.model().LABEL)){
  145.             if(appendTablePrefix){
  146.                 return this.toAliasTable(field)+".label";
  147.             }else{
  148.                 return "label";
  149.             }
  150.         }


  151.         return super.toColumn(field,returnAlias,appendTablePrefix);
  152.        
  153.     }
  154.    
  155.     @Override
  156.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  157.        
  158.         // In the case of table with alias, using parameter returnAlias​​,
  159.         // it is possible to drive the choice whether to return only the alias or
  160.         // the full definition of the table containing the alias
  161.        
  162.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_RICERCA)){
  163.             return this.toTable(ConfigurazioneRicerca.model(), returnAlias);
  164.         }
  165.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.ACCORDO)){
  166.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  167.         }
  168.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.TIPO_SOGGETTO_REFERENTE)){
  169.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  170.         }
  171.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.NOME_SOGGETTO_REFERENTE)){
  172.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  173.         }
  174.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.VERSIONE)){
  175.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  176.         }
  177.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.SERVIZIO)){
  178.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  179.         }
  180.         if(field.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.AZIONE)){
  181.             return this.toTable(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE, returnAlias);
  182.         }
  183.         if(field.equals(ConfigurazioneRicerca.model().ENABLED)){
  184.             return this.toTable(ConfigurazioneRicerca.model(), returnAlias);
  185.         }
  186.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.TIPO)){
  187.             return this.toTable(ConfigurazioneRicerca.model().PLUGIN, returnAlias);
  188.         }
  189.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.CLASS_NAME)){
  190.             return this.toTable(ConfigurazioneRicerca.model().PLUGIN, returnAlias);
  191.         }
  192.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.DESCRIZIONE)){
  193.             return this.toTable(ConfigurazioneRicerca.model().PLUGIN, returnAlias);
  194.         }
  195.         if(field.equals(ConfigurazioneRicerca.model().PLUGIN.LABEL)){
  196.             return this.toTable(ConfigurazioneRicerca.model().PLUGIN, returnAlias);
  197.         }
  198.         if(field.equals(ConfigurazioneRicerca.model().LABEL)){
  199.             return this.toTable(ConfigurazioneRicerca.model(), returnAlias);
  200.         }


  201.         return super.toTable(field,returnAlias);
  202.        
  203.     }

  204.     @Override
  205.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  206.        
  207.         // In the case of table with alias, using parameter returnAlias​​,
  208.         // it is possible to drive the choice whether to return only the alias or
  209.         // the full definition of the table containing the alias
  210.        
  211.         if(model.equals(ConfigurazioneRicerca.model())){
  212.             return "ricerche_personalizzate";
  213.         }
  214.         if(model.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE)){
  215.             return "plugins_conf_azioni";
  216.         }
  217.         if(model.equals(ConfigurazioneRicerca.model().ID_CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO)){
  218.             return "plugins_conf_servizi";
  219.         }
  220.         if(model.equals(ConfigurazioneRicerca.model().PLUGIN)){
  221.             return "plugins";
  222.         }


  223.         return super.toTable(model,returnAlias);
  224.        
  225.     }

  226. }