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

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.plugins.model.PluginModel;
  24. import org.openspcoop2.core.plugins.model.PluginProprietaCompatibilitaModel;
  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,PluginProprietaCompatibilitaModel proprietaModel) 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(proprietaModel.NOME.equals(af.getField()) ){
  54.                         aliasTabella = af.getAliasTable();
  55.                     }
  56.                    
  57.                     if(aliasTabella!=null){
  58.                         if(tabelleAggiunteAlias.contains(aliasTabella)==false){
  59.                             //sqlQueryObject.addFromTable(fieldConverter.toTable(contenutiModel), aliasTabella);
  60.                             //Lo fa gia in automatico la gestione dell'Expression
  61.                             tabelleAggiunteAlias.add(aliasTabella);
  62.                         }
  63.                     }
  64.                    
  65.                 }
  66.             }
  67.         }
  68.         return tabelleAggiunteAlias;
  69.     }
  70.    
  71.    
  72.     public static void join(IExpression expression, ISQLQueryObject sqlQueryObject, PluginModel model,PluginProprietaCompatibilitaModel modelProprieta,
  73.             ISQLFieldConverter sqlFieldConverter) throws ExpressionNotImplementedException, ExpressionException, SQLQueryObjectException{
  74.         List<String> tableWithAlias = AliasTableRicerchePersonalizzate.addFromTable(expression, sqlQueryObject, sqlFieldConverter,modelProprieta);
  75.         if(tableWithAlias!=null && tableWithAlias.size()>0){
  76.             String tableName2 = sqlFieldConverter.toTable(model);
  77.             for (String aliasTable : tableWithAlias) {
  78.                 sqlQueryObject.addWhereCondition(aliasTable+".id_plugin="+tableName2+".id");    
  79.             }
  80.         }
  81.         else{
  82.             if(expression.inUseModel(modelProprieta,false)){
  83.                 String tableName1 = sqlFieldConverter.toTable(modelProprieta);
  84.                 String tableName2 = sqlFieldConverter.toTable(model);
  85.                 sqlQueryObject.addWhereCondition(tableName1+".id_plugin="+tableName2+".id");
  86.             }
  87.         }
  88.        
  89.     }
  90. }