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


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

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


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


  110.         return super.toColumn(field,returnAlias,appendTablePrefix);
  111.        
  112.     }
  113.    
  114.     @Override
  115.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  116.        
  117.         // In the case of table with alias, using parameter returnAlias​​,
  118.         // it is possible to drive the choice whether to return only the alias or
  119.         // the full definition of the table containing the alias
  120.        
  121.         if(field.equals(Operation.model().NOME)){
  122.             return this.toTable(Operation.model(), returnAlias);
  123.         }
  124.         if(field.equals(Operation.model().ID_PORT_TYPE.NOME)){
  125.             return this.toTable(Operation.model().ID_PORT_TYPE, returnAlias);
  126.         }
  127.         if(field.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.NOME)){
  128.             return this.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  129.         }
  130.         if(field.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.TIPO)){
  131.             return this.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  132.         }
  133.         if(field.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO.NOME)){
  134.             return this.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO, returnAlias);
  135.         }
  136.         if(field.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.VERSIONE)){
  137.             return this.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  138.         }
  139.         if(field.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.SERVICE_BINDING)){
  140.             return this.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE, returnAlias);
  141.         }


  142.         return super.toTable(field,returnAlias);
  143.        
  144.     }

  145.     @Override
  146.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  147.        
  148.         // In the case of table with alias, using parameter returnAlias​​,
  149.         // it is possible to drive the choice whether to return only the alias or
  150.         // the full definition of the table containing the alias
  151.        
  152.         if(model.equals(Operation.model())){
  153.             return CostantiDB.PORT_TYPE_AZIONI;
  154.         }
  155.         if(model.equals(Operation.model().ID_PORT_TYPE)){
  156.             return CostantiDB.PORT_TYPE;
  157.         }
  158.         if(model.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE)){
  159.             return CostantiDB.ACCORDI;
  160.         }
  161.         if(model.equals(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO)){
  162.             return CostantiDB.SOGGETTI;
  163.         }


  164.         return super.toTable(model,returnAlias);
  165.        
  166.     }

  167. }