FruitoreFieldConverter.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.commons.search.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.commons.search.Fruitore;
  27. import org.openspcoop2.core.constants.CostantiDB;


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

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


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return Fruitore.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(Fruitore.model().ID_FRUITORE.TIPO)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".tipo_soggetto";
  64.             }else{
  65.                 return "tipo_soggetto";
  66.             }
  67.         }
  68.         if(field.equals(Fruitore.model().ID_FRUITORE.NOME)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".nome_soggetto";
  71.             }else{
  72.                 return "nome_soggetto";
  73.             }
  74.         }
  75.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.TIPO)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".tipo_servizio";
  78.             }else{
  79.                 return "tipo_servizio";
  80.             }
  81.         }
  82.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.NOME)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".nome_servizio";
  85.             }else{
  86.                 return "nome_servizio";
  87.             }
  88.         }
  89.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.VERSIONE)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".versione_servizio";
  92.             }else{
  93.                 return "versione_servizio";
  94.             }
  95.         }
  96.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE.TIPO)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".tipo_soggetto";
  99.             }else{
  100.                 return "tipo_soggetto";
  101.             }
  102.         }
  103.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE.NOME)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".nome_soggetto";
  106.             }else{
  107.                 return "nome_soggetto";
  108.             }
  109.         }
  110.         if(field.equals(Fruitore.model().ORA_REGISTRAZIONE)){
  111.             if(appendTablePrefix){
  112.                 return this.toAliasTable(field)+".ora_registrazione";
  113.             }else{
  114.                 return "ora_registrazione";
  115.             }
  116.         }


  117.         return super.toColumn(field,returnAlias,appendTablePrefix);
  118.        
  119.     }
  120.    
  121.     @Override
  122.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  123.        
  124.         // In the case of table with alias, using parameter returnAlias​​,
  125.         // it is possible to drive the choice whether to return only the alias or
  126.         // the full definition of the table containing the alias
  127.        
  128.         if(field.equals(Fruitore.model().ID_FRUITORE.TIPO)){
  129.             return this.toTable(Fruitore.model().ID_FRUITORE, returnAlias);
  130.         }
  131.         if(field.equals(Fruitore.model().ID_FRUITORE.NOME)){
  132.             return this.toTable(Fruitore.model().ID_FRUITORE, returnAlias);
  133.         }
  134.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.TIPO)){
  135.             return this.toTable(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA, returnAlias);
  136.         }
  137.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.NOME)){
  138.             return this.toTable(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA, returnAlias);
  139.         }
  140.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.VERSIONE)){
  141.             return this.toTable(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA, returnAlias);
  142.         }
  143.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE.TIPO)){
  144.             return this.toTable(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE, returnAlias);
  145.         }
  146.         if(field.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE.NOME)){
  147.             return this.toTable(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE, returnAlias);
  148.         }
  149.         if(field.equals(Fruitore.model().ORA_REGISTRAZIONE)){
  150.             return this.toTable(Fruitore.model(), returnAlias);
  151.         }


  152.         return super.toTable(field,returnAlias);
  153.        
  154.     }

  155.     @Override
  156.     public String toTable(IModel<?> model,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(model.equals(Fruitore.model())){
  163.             return CostantiDB.SERVIZI_FRUITORI;
  164.         }
  165.         if(model.equals(Fruitore.model().ID_FRUITORE)){
  166.             if(returnAlias){
  167.                 return "sfr";
  168.             }else{
  169.                 return CostantiDB.SOGGETTI+" sfr";
  170.             }
  171.         }
  172.         if(model.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA)){
  173.             return CostantiDB.SERVIZI;
  174.         }
  175.         if(model.equals(Fruitore.model().ID_ACCORDO_SERVIZIO_PARTE_SPECIFICA.ID_EROGATORE)){
  176.             if(returnAlias){
  177.                 return "ser";
  178.             }else{
  179.                 return CostantiDB.SOGGETTI+" ser";
  180.             }
  181.         }


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

  185. }