AllarmeNotificaFieldConverter.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.allarmi.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.allarmi.AllarmeNotifica;
  27. import org.openspcoop2.core.constants.CostantiDB;


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

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


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return AllarmeNotifica.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(AllarmeNotifica.model().DATA_NOTIFICA)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".data_notifica";
  64.             }else{
  65.                 return "data_notifica";
  66.             }
  67.         }
  68.         if(field.equals(AllarmeNotifica.model().ID_ALLARME.NOME)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".nome";
  71.             }else{
  72.                 return "nome";
  73.             }
  74.         }
  75.         if(field.equals(AllarmeNotifica.model().OLD_STATO)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".old_stato";
  78.             }else{
  79.                 return "old_stato";
  80.             }
  81.         }
  82.         if(field.equals(AllarmeNotifica.model().OLD_DETTAGLIO_STATO)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".old_stato_dettaglio";
  85.             }else{
  86.                 return "old_stato_dettaglio";
  87.             }
  88.         }
  89.         if(field.equals(AllarmeNotifica.model().NUOVO_STATO)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".nuovo_stato";
  92.             }else{
  93.                 return "nuovo_stato";
  94.             }
  95.         }
  96.         if(field.equals(AllarmeNotifica.model().NUOVO_DETTAGLIO_STATO)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".nuovo_stato_dettaglio";
  99.             }else{
  100.                 return "nuovo_stato_dettaglio";
  101.             }
  102.         }
  103.         if(field.equals(AllarmeNotifica.model().HISTORY_ENTRY)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".history_entry";
  106.             }else{
  107.                 return "history_entry";
  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(AllarmeNotifica.model().DATA_NOTIFICA)){
  122.             return this.toTable(AllarmeNotifica.model(), returnAlias);
  123.         }
  124.         if(field.equals(AllarmeNotifica.model().ID_ALLARME.NOME)){
  125.             return this.toTable(AllarmeNotifica.model().ID_ALLARME, returnAlias);
  126.         }
  127.         if(field.equals(AllarmeNotifica.model().OLD_STATO)){
  128.             return this.toTable(AllarmeNotifica.model(), returnAlias);
  129.         }
  130.         if(field.equals(AllarmeNotifica.model().OLD_DETTAGLIO_STATO)){
  131.             return this.toTable(AllarmeNotifica.model(), returnAlias);
  132.         }
  133.         if(field.equals(AllarmeNotifica.model().NUOVO_STATO)){
  134.             return this.toTable(AllarmeNotifica.model(), returnAlias);
  135.         }
  136.         if(field.equals(AllarmeNotifica.model().NUOVO_DETTAGLIO_STATO)){
  137.             return this.toTable(AllarmeNotifica.model(), returnAlias);
  138.         }
  139.         if(field.equals(AllarmeNotifica.model().HISTORY_ENTRY)){
  140.             return this.toTable(AllarmeNotifica.model(), 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(AllarmeNotifica.model())){
  153.             return CostantiDB.ALLARMI_NOTIFICHE;
  154.         }
  155.         if(model.equals(AllarmeNotifica.model().ID_ALLARME)){
  156.             return CostantiDB.ALLARMI;
  157.         }


  158.         return super.toTable(model,returnAlias);
  159.        
  160.     }

  161. }