AccordoServizioParteComuneGruppoFieldConverter.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.AccordoServizioParteComuneGruppo;
  27. import org.openspcoop2.core.constants.CostantiDB;


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

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


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return AccordoServizioParteComuneGruppo.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(AccordoServizioParteComuneGruppo.model().ID_GRUPPO.NOME)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".nome";
  64.             }else{
  65.                 return "nome";
  66.             }
  67.         }
  68.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.NOME)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".nome";
  71.             }else{
  72.                 return "nome";
  73.             }
  74.         }
  75.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.TIPO)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".tipo_soggetto";
  78.             }else{
  79.                 return "tipo_soggetto";
  80.             }
  81.         }
  82.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.NOME)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".nome_soggetto";
  85.             }else{
  86.                 return "nome_soggetto";
  87.             }
  88.         }
  89.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.VERSIONE)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".versione";
  92.             }else{
  93.                 return "versione";
  94.             }
  95.         }
  96.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.SERVICE_BINDING)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".service_binding";
  99.             }else{
  100.                 return "service_binding";
  101.             }
  102.         }


  103.         return super.toColumn(field,returnAlias,appendTablePrefix);
  104.        
  105.     }
  106.    
  107.     @Override
  108.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  109.        
  110.         // In the case of table with alias, using parameter returnAlias​​,
  111.         // it is possible to drive the choice whether to return only the alias or
  112.         // the full definition of the table containing the alias
  113.        
  114.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_GRUPPO.NOME)){
  115.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_GRUPPO, returnAlias);
  116.         }
  117.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.NOME)){
  118.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  119.         }
  120.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.TIPO)){
  121.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  122.         }
  123.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.NOME)){
  124.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  125.         }
  126.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.VERSIONE)){
  127.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  128.         }
  129.         if(field.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.SERVICE_BINDING)){
  130.             return this.toTable(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  131.         }


  132.         return super.toTable(field,returnAlias);
  133.        
  134.     }

  135.     @Override
  136.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  137.        
  138.         // In the case of table with alias, using parameter returnAlias​​,
  139.         // it is possible to drive the choice whether to return only the alias or
  140.         // the full definition of the table containing the alias
  141.        
  142.         if(model.equals(AccordoServizioParteComuneGruppo.model())){
  143.             return CostantiDB.ACCORDI_GRUPPI;
  144.         }
  145.         if(model.equals(AccordoServizioParteComuneGruppo.model().ID_GRUPPO)){
  146.             return CostantiDB.GRUPPI;
  147.         }
  148.         if(model.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE)){
  149.             return CostantiDB.ACCORDI;
  150.         }
  151.         if(model.equals(AccordoServizioParteComuneGruppo.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO)){
  152.             return CostantiDB.SOGGETTI;
  153.         }


  154.         return super.toTable(model,returnAlias);
  155.        
  156.     }

  157. }