StatistichePdndTracingFieldConverter.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.statistiche.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.constants.CostantiDB;
  27. import org.openspcoop2.core.statistiche.StatistichePdndTracing;


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

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


  45.     @Override
  46.     public IModel<?> getRootModel() throws ExpressionException {
  47.         return StatistichePdndTracing.model();
  48.     }
  49.    
  50.     @Override
  51.     public TipiDatabase getDatabaseType() throws ExpressionException {
  52.         return this.databaseType;
  53.     }
  54.    


  55.     @Override
  56.     public String toColumn(IField field,boolean returnAlias,boolean appendTablePrefix) throws ExpressionException {
  57.        
  58.         // In the case of columns with alias, using parameter returnAlias​​,
  59.         // it is possible to drive the choice whether to return only the alias or
  60.         // the full definition of the column containing the alias
  61.        
  62.         if(field.equals(StatistichePdndTracing.model().DATA_TRACCIAMENTO)){
  63.             if(appendTablePrefix){
  64.                 return this.toAliasTable(field)+".data_tracciamento";
  65.             }else{
  66.                 return "data_tracciamento";
  67.             }
  68.         }
  69.         if(field.equals(StatistichePdndTracing.model().DATA_REGISTRAZIONE)){
  70.             if(appendTablePrefix){
  71.                 return this.toAliasTable(field)+".data_registrazione";
  72.             }else{
  73.                 return "data_registrazione";
  74.             }
  75.         }
  76.         if(field.equals(StatistichePdndTracing.model().DATA_PUBBLICAZIONE)){
  77.             if(appendTablePrefix){
  78.                 return this.toAliasTable(field)+".data_pubblicazione";
  79.             }else{
  80.                 return "data_pubblicazione";
  81.             }
  82.         }
  83.         if(field.equals(StatistichePdndTracing.model().PDD_CODICE)){
  84.             if(appendTablePrefix){
  85.                 return this.toAliasTable(field)+".pdd_codice";
  86.             }else{
  87.                 return "pdd_codice";
  88.             }
  89.         }
  90.         if(field.equals(StatistichePdndTracing.model().CSV)){
  91.             if(appendTablePrefix){
  92.                 return this.toAliasTable(field)+".csv";
  93.             }else{
  94.                 return "csv";
  95.             }
  96.         }
  97.         if(field.equals(StatistichePdndTracing.model().METHOD)){
  98.             if(appendTablePrefix){
  99.                 return this.toAliasTable(field)+".method";
  100.             }else{
  101.                 return "method";
  102.             }
  103.         }
  104.         if(field.equals(StatistichePdndTracing.model().STATO_PDND)){
  105.             if(appendTablePrefix){
  106.                 return this.toAliasTable(field)+".stato_pdnd";
  107.             }else{
  108.                 return "stato_pdnd";
  109.             }
  110.         }
  111.         if(field.equals(StatistichePdndTracing.model().TENTATIVI_PUBBLICAZIONE)){
  112.             if(appendTablePrefix){
  113.                 return this.toAliasTable(field)+".tentativi_pubblicazione";
  114.             }else{
  115.                 return "tentativi_pubblicazione";
  116.             }
  117.         }
  118.         if(field.equals(StatistichePdndTracing.model().FORCE_PUBLISH)){
  119.             if(appendTablePrefix){
  120.                 return this.toAliasTable(field)+".force_publish";
  121.             }else{
  122.                 return "force_publish";
  123.             }
  124.         }
  125.         if(field.equals(StatistichePdndTracing.model().STATO)){
  126.             if(appendTablePrefix){
  127.                 return this.toAliasTable(field)+".stato";
  128.             }else{
  129.                 return "stato";
  130.             }
  131.         }
  132.         if(field.equals(StatistichePdndTracing.model().TRACING_ID)){
  133.             if(appendTablePrefix){
  134.                 return this.toAliasTable(field)+".tracing_id";
  135.             }else{
  136.                 return "tracing_id";
  137.             }
  138.         }
  139.         if(field.equals(StatistichePdndTracing.model().ERROR_DETAILS)){
  140.             if(appendTablePrefix){
  141.                 return this.toAliasTable(field)+".error_details";
  142.             }else{
  143.                 return "error_details";
  144.             }
  145.         }
  146.         if(field.equals(StatistichePdndTracing.model().HISTORY)){
  147.             if(appendTablePrefix){
  148.                 return this.toAliasTable(field)+".history";
  149.             }else{
  150.                 return "history";
  151.             }
  152.         }
  153.         if (field.getFieldName().equals("id") && field.getClassType().equals(StatistichePdndTracing.class)) {
  154.             if(appendTablePrefix){
  155.                 return this.toAliasTable(field)+".id";
  156.             }else{
  157.                 return "id";
  158.             }
  159.         }

  160.         return super.toColumn(field,returnAlias,appendTablePrefix);
  161.        
  162.     }
  163.    
  164.     @Override
  165.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  166.        
  167.         // In the case of table with alias, using parameter returnAlias​​,
  168.         // it is possible to drive the choice whether to return only the alias or
  169.         // the full definition of the table containing the alias
  170.        
  171.         if(field.equals(StatistichePdndTracing.model().DATA_TRACCIAMENTO)){
  172.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  173.         }
  174.         if(field.equals(StatistichePdndTracing.model().DATA_REGISTRAZIONE)){
  175.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  176.         }
  177.         if(field.equals(StatistichePdndTracing.model().DATA_PUBBLICAZIONE)){
  178.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  179.         }
  180.         if(field.equals(StatistichePdndTracing.model().PDD_CODICE)){
  181.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  182.         }
  183.         if(field.equals(StatistichePdndTracing.model().CSV)){
  184.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  185.         }
  186.         if(field.equals(StatistichePdndTracing.model().METHOD)){
  187.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  188.         }
  189.         if(field.equals(StatistichePdndTracing.model().STATO_PDND)){
  190.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  191.         }
  192.         if(field.equals(StatistichePdndTracing.model().TENTATIVI_PUBBLICAZIONE)){
  193.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  194.         }
  195.         if(field.equals(StatistichePdndTracing.model().FORCE_PUBLISH)){
  196.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  197.         }
  198.         if(field.equals(StatistichePdndTracing.model().STATO)){
  199.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  200.         }
  201.         if(field.equals(StatistichePdndTracing.model().TRACING_ID)){
  202.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  203.         }
  204.         if(field.equals(StatistichePdndTracing.model().ERROR_DETAILS)){
  205.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  206.         }
  207.         if(field.equals(StatistichePdndTracing.model().HISTORY)){
  208.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  209.         }
  210.         if (field.getFieldName().equals("id") && field.getClassType().equals(StatistichePdndTracing.class)) {
  211.             return this.toTable(StatistichePdndTracing.model(), returnAlias);
  212.         }

  213.         return super.toTable(field,returnAlias);
  214.        
  215.     }

  216.     @Override
  217.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  218.        
  219.         // In the case of table with alias, using parameter returnAlias​​,
  220.         // it is possible to drive the choice whether to return only the alias or
  221.         // the full definition of the table containing the alias
  222.        
  223.         if(model.equals(StatistichePdndTracing.model())){
  224.             return CostantiDB.STATISTICHE_PDND_TRACING;
  225.         }


  226.         return super.toTable(model,returnAlias);
  227.        
  228.     }

  229. }