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


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

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


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return AccordoServizioParteSpecifica.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(AccordoServizioParteSpecifica.model().TIPO)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".tipo_servizio";
  64.             }else{
  65.                 return "tipo_servizio";
  66.             }
  67.         }
  68.         if(field.equals(AccordoServizioParteSpecifica.model().NOME)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".nome_servizio";
  71.             }else{
  72.                 return "nome_servizio";
  73.             }
  74.         }
  75.         if(field.equals(AccordoServizioParteSpecifica.model().VERSIONE)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".versione_servizio";
  78.             }else{
  79.                 return "versione_servizio";
  80.             }
  81.         }
  82.         if(field.equals(AccordoServizioParteSpecifica.model().PORT_TYPE)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".port_type";
  85.             }else{
  86.                 return "port_type";
  87.             }
  88.         }
  89.         if(field.equals(AccordoServizioParteSpecifica.model().ID_EROGATORE.TIPO)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".tipo_soggetto";
  92.             }else{
  93.                 return "tipo_soggetto";
  94.             }
  95.         }
  96.         if(field.equals(AccordoServizioParteSpecifica.model().ID_EROGATORE.NOME)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".nome_soggetto";
  99.             }else{
  100.                 return "nome_soggetto";
  101.             }
  102.         }
  103.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.NOME)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".nome";
  106.             }else{
  107.                 return "nome";
  108.             }
  109.         }
  110.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.TIPO)){
  111.             if(appendTablePrefix){
  112.                 return this.toAliasTable(field)+".tipo_soggetto";
  113.             }else{
  114.                 return "tipo_soggetto";
  115.             }
  116.         }
  117.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.NOME)){
  118.             if(appendTablePrefix){
  119.                 return this.toAliasTable(field)+".nome_soggetto";
  120.             }else{
  121.                 return "nome_soggetto";
  122.             }
  123.         }
  124.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.VERSIONE)){
  125.             if(appendTablePrefix){
  126.                 return this.toAliasTable(field)+".versione";
  127.             }else{
  128.                 return "versione";
  129.             }
  130.         }
  131.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.SERVICE_BINDING)){
  132.             if(appendTablePrefix){
  133.                 return this.toAliasTable(field)+".service_binding";
  134.             }else{
  135.                 return "service_binding";
  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(AccordoServizioParteSpecifica.model().TIPO)){
  150.             return this.toTable(AccordoServizioParteSpecifica.model(), returnAlias);
  151.         }
  152.         if(field.equals(AccordoServizioParteSpecifica.model().NOME)){
  153.             return this.toTable(AccordoServizioParteSpecifica.model(), returnAlias);
  154.         }
  155.         if(field.equals(AccordoServizioParteSpecifica.model().VERSIONE)){
  156.             return this.toTable(AccordoServizioParteSpecifica.model(), returnAlias);
  157.         }
  158.         if(field.equals(AccordoServizioParteSpecifica.model().PORT_TYPE)){
  159.             return this.toTable(AccordoServizioParteSpecifica.model(), returnAlias);
  160.         }
  161.         if(field.equals(AccordoServizioParteSpecifica.model().ID_EROGATORE.TIPO)){
  162.             return this.toTable(AccordoServizioParteSpecifica.model().ID_EROGATORE, returnAlias);
  163.         }
  164.         if(field.equals(AccordoServizioParteSpecifica.model().ID_EROGATORE.NOME)){
  165.             return this.toTable(AccordoServizioParteSpecifica.model().ID_EROGATORE, returnAlias);
  166.         }
  167.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.NOME)){
  168.             return this.toTable(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  169.         }
  170.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.TIPO)){
  171.             return this.toTable(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  172.         }
  173.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.NOME)){
  174.             return this.toTable(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  175.         }
  176.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.VERSIONE)){
  177.             return this.toTable(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  178.         }
  179.         if(field.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.SERVICE_BINDING)){
  180.             return this.toTable(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE, 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(AccordoServizioParteSpecifica.model())){
  193.             return CostantiDB.SERVIZI;
  194.         }
  195.         if(model.equals(AccordoServizioParteSpecifica.model().ID_EROGATORE)){
  196.             if(returnAlias){
  197.                 return "sogerog";
  198.             }else{
  199.                 return CostantiDB.SOGGETTI+" sogerog";
  200.             }
  201.         }
  202.         if(model.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE)){
  203.             return CostantiDB.ACCORDI;
  204.         }
  205.         if(model.equals(AccordoServizioParteSpecifica.model().ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO)){
  206.             if(returnAlias){
  207.                 return "sogref";
  208.             }else{
  209.                 return CostantiDB.SOGGETTI+" sogref";
  210.             }
  211.         }


  212.         return super.toTable(model,returnAlias);
  213.        
  214.     }

  215. }