AliasTableRicerchePersonalizzate.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.utils;

  21. import org.openspcoop2.core.statistiche.model.StatisticaContenutiModel;
  22. import org.openspcoop2.core.statistiche.model.StatisticaModel;

  23. import java.util.ArrayList;
  24. import java.util.List;

  25. import org.openspcoop2.generic_project.beans.IAliasTableField;
  26. import org.openspcoop2.generic_project.beans.IField;
  27. import org.openspcoop2.generic_project.exception.ExpressionException;
  28. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  29. import org.openspcoop2.generic_project.expression.IExpression;
  30. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  31. import org.openspcoop2.utils.sql.ISQLQueryObject;
  32. import org.openspcoop2.utils.sql.SQLQueryObjectException;

  33. /**    
  34.  * AliasTableRicerchePersonalizzate
  35.  *
  36.  * @author Poli Andrea (poli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class AliasTableRicerchePersonalizzate {

  41.     public static final String ALIAS_PREFIX = "op2S";
  42.    
  43.     private static List<String> addFromTable(IExpression expression, ISQLQueryObject sqlQueryObject,
  44.             ISQLFieldConverter fieldConverter,StatisticaContenutiModel contenutiModel) throws ExpressionNotImplementedException, ExpressionException, SQLQueryObjectException{
  45.         List<IField> iFields = expression.getFields(true);
  46.         List<String> tabelleAggiunteAlias = new ArrayList<>();
  47.         if(iFields!=null && iFields.size()>0){
  48.             for (IField iField : iFields) {
  49.                 if(iField instanceof IAliasTableField){
  50.                     IAliasTableField af = (IAliasTableField) iField;
  51.                     String aliasTabella = null;
  52.                    
  53.                     if(contenutiModel.FILTRO_NOME_1.equals(af.getField()) ||
  54.                             contenutiModel.FILTRO_NOME_2.equals(af.getField()) ||
  55.                             contenutiModel.FILTRO_NOME_3.equals(af.getField()) ||
  56.                             contenutiModel.FILTRO_NOME_4.equals(af.getField()) ||
  57.                             contenutiModel.FILTRO_NOME_5.equals(af.getField()) ||
  58.                             contenutiModel.FILTRO_NOME_6.equals(af.getField()) ||
  59.                             contenutiModel.FILTRO_NOME_7.equals(af.getField()) ||
  60.                             contenutiModel.FILTRO_NOME_8.equals(af.getField()) ||
  61.                             contenutiModel.FILTRO_NOME_9.equals(af.getField()) ||
  62.                             contenutiModel.FILTRO_NOME_10.equals(af.getField()) ){
  63.                         aliasTabella = af.getAliasTable();
  64.                     }
  65.                    
  66.                     if(aliasTabella!=null){
  67.                         if(tabelleAggiunteAlias.contains(aliasTabella)==false){
  68.                             //sqlQueryObject.addFromTable(fieldConverter.toTable(contenutiModel), aliasTabella);
  69.                             //Lo fa gia in automatico la gestione dell'Expression
  70.                             tabelleAggiunteAlias.add(aliasTabella);
  71.                         }
  72.                     }
  73.                    
  74.                 }
  75.             }
  76.         }
  77.         return tabelleAggiunteAlias;
  78.     }
  79.    
  80.    
  81.     public static void join(IExpression expression, ISQLQueryObject sqlQueryObject, StatisticaModel model,StatisticaContenutiModel modelContenuti,
  82.             ISQLFieldConverter sqlFieldConverter) throws ExpressionNotImplementedException, ExpressionException, SQLQueryObjectException{
  83.         List<String> tableWithAlias = AliasTableRicerchePersonalizzate.addFromTable(expression, sqlQueryObject, sqlFieldConverter,modelContenuti);
  84.         if(tableWithAlias!=null && tableWithAlias.size()>0){
  85.             String tableName2 = sqlFieldConverter.toTable(model);
  86.             for (String aliasTable : tableWithAlias) {
  87.                 sqlQueryObject.addWhereCondition(aliasTable+".id_stat="+tableName2+".id");  
  88.             }
  89.         }
  90.         //else{
  91.         if(expression.inUseModel(modelContenuti,false)){
  92.             String tableName1 = sqlFieldConverter.toTable(modelContenuti);
  93.             String tableName2 = sqlFieldConverter.toTable(model);
  94.             sqlQueryObject.addWhereCondition(tableName1+".id_stat="+tableName2+".id");
  95.         }
  96.         //}
  97.        
  98.     }
  99. }