PluginFieldConverter.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.core.constants.CostantiDB;
  22. import org.openspcoop2.generic_project.beans.IField;
  23. import org.openspcoop2.generic_project.beans.IModel;
  24. import org.openspcoop2.generic_project.exception.ExpressionException;
  25. import org.openspcoop2.generic_project.expression.impl.sql.AbstractSQLFieldConverter;
  26. import org.openspcoop2.utils.TipiDatabase;

  27. import org.openspcoop2.core.plugins.Plugin;


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

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


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return Plugin.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(Plugin.model().TIPO_PLUGIN)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".tipo_plugin";
  64.             }else{
  65.                 return "tipo_plugin";
  66.             }
  67.         }
  68.         if(field.equals(Plugin.model().CLASS_NAME)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".class_name";
  71.             }else{
  72.                 return "class_name";
  73.             }
  74.         }
  75.         if(field.equals(Plugin.model().TIPO)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".tipo";
  78.             }else{
  79.                 return "tipo";
  80.             }
  81.         }
  82.         if(field.equals(Plugin.model().DESCRIZIONE)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".descrizione";
  85.             }else{
  86.                 return "descrizione";
  87.             }
  88.         }
  89.         if(field.equals(Plugin.model().LABEL)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".label";
  92.             }else{
  93.                 return "label";
  94.             }
  95.         }
  96.         if(field.equals(Plugin.model().STATO)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".stato";
  99.             }else{
  100.                 return "stato";
  101.             }
  102.         }
  103.         if(field.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.URI_ACCORDO)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".uri_accordo";
  106.             }else{
  107.                 return "uri_accordo";
  108.             }
  109.         }
  110.         if(field.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.SERVIZIO)){
  111.             if(appendTablePrefix){
  112.                 return this.toAliasTable(field)+".servizio";
  113.             }else{
  114.                 return "servizio";
  115.             }
  116.         }
  117.         if(field.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA.AZIONE)){
  118.             if(appendTablePrefix){
  119.                 return this.toAliasTable(field)+".azione";
  120.             }else{
  121.                 return "azione";
  122.             }
  123.         }
  124.         if(field.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.NOME)){
  125.             if(appendTablePrefix){
  126.                 return this.toAliasTable(field)+".nome";
  127.             }else{
  128.                 return "nome";
  129.             }
  130.         }
  131.         if(field.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.VALORE)){
  132.             if(appendTablePrefix){
  133.                 return this.toAliasTable(field)+".valore";
  134.             }else{
  135.                 return "valore";
  136.             }
  137.         }


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


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

  185.     @Override
  186.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  187.        
  188.         // In the case of table with alias, using parameter returnAlias​​,
  189.         // it is possible to drive the choice whether to return only the alias or
  190.         // the full definition of the table containing the alias
  191.        
  192.         if(model.equals(Plugin.model())){
  193.             return CostantiDB.REGISTRO_CLASSI;
  194.         }
  195.         if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA)){
  196.             return CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_SERVIZIO;
  197.         }
  198.         if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA)){
  199.             return CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_AZIONE;
  200.         }
  201.         if(model.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA)){
  202.             return CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_PROPRIETA;
  203.         }


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

  207. }