ConfigurazioneServizioFieldConverter.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.ConfigurazioneServizio;


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

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


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


  137.         return super.toColumn(field,returnAlias,appendTablePrefix);
  138.        
  139.     }
  140.    
  141.     @Override
  142.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  143.        
  144.         // In the case of table with alias, using parameter returnAlias​​,
  145.         // it is possible to drive the choice whether to return only the alias or
  146.         // the full definition of the table containing the alias
  147.        
  148.         if(field.equals(ConfigurazioneServizio.model().ACCORDO)){
  149.             return this.toTable(ConfigurazioneServizio.model(), returnAlias);
  150.         }
  151.         if(field.equals(ConfigurazioneServizio.model().TIPO_SOGGETTO_REFERENTE)){
  152.             return this.toTable(ConfigurazioneServizio.model(), returnAlias);
  153.         }
  154.         if(field.equals(ConfigurazioneServizio.model().NOME_SOGGETTO_REFERENTE)){
  155.             return this.toTable(ConfigurazioneServizio.model(), returnAlias);
  156.         }
  157.         if(field.equals(ConfigurazioneServizio.model().VERSIONE)){
  158.             return this.toTable(ConfigurazioneServizio.model(), returnAlias);
  159.         }
  160.         if(field.equals(ConfigurazioneServizio.model().SERVIZIO)){
  161.             return this.toTable(ConfigurazioneServizio.model(), returnAlias);
  162.         }
  163.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.ACCORDO)){
  164.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  165.         }
  166.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.TIPO_SOGGETTO_REFERENTE)){
  167.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  168.         }
  169.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.NOME_SOGGETTO_REFERENTE)){
  170.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  171.         }
  172.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.VERSIONE)){
  173.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  174.         }
  175.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO.SERVIZIO)){
  176.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO, returnAlias);
  177.         }
  178.         if(field.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.AZIONE)){
  179.             return this.toTable(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE, returnAlias);
  180.         }


  181.         return super.toTable(field,returnAlias);
  182.        
  183.     }

  184.     @Override
  185.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  186.        
  187.         // In the case of table with alias, using parameter returnAlias​​,
  188.         // it is possible to drive the choice whether to return only the alias or
  189.         // the full definition of the table containing the alias
  190.        
  191.         if(model.equals(ConfigurazioneServizio.model())){
  192.             return "plugins_conf_servizi";
  193.         }
  194.         if(model.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE)){
  195.             return "plugins_conf_azioni";
  196.         }
  197.         if(model.equals(ConfigurazioneServizio.model().CONFIGURAZIONE_SERVIZIO_AZIONE.ID_CONFIGURAZIONE_SERVIZIO)){
  198.             return "plugins_conf_servizi";
  199.         }


  200.         return super.toTable(model,returnAlias);
  201.        
  202.     }

  203. }