UnionExpression.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.generic_project.beans;

  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.generic_project.exception.ExpressionException;
  26. import org.openspcoop2.generic_project.expression.IExpression;
  27. import org.openspcoop2.generic_project.expression.IPaginatedExpression;

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

  36.     private IExpression expression;
  37.     private Map<String,Object> returnFieldMap = new HashMap<>();
  38.     private List<String> keys = new ArrayList<>(); // contiene le keys della mappa per preservare l'ordine di inserimento.
  39.    
  40.     public UnionExpression(IExpression expression){
  41.         this.expression = expression;
  42.     }
  43.     public UnionExpression(IPaginatedExpression paginatedExpression){
  44.         this.expression = paginatedExpression;
  45.     }

  46.     public void addSelectField(IField field,String alias) throws ExpressionException{
  47.         if(this.returnFieldMap.containsKey(alias)){
  48.             throw new ExpressionException("Alias ["+alias+"] already used");
  49.         }
  50.         this.returnFieldMap.put(alias, field);
  51.         this.keys.add(alias);
  52.     }
  53.    
  54.     public void addSelectFunctionField(FunctionField functionField) throws ExpressionException{
  55.         String alias = functionField.getAlias();
  56.         if(this.returnFieldMap.containsKey(alias)){
  57.             throw new ExpressionException("Alias ["+alias+"] already used");
  58.         }
  59.         this.returnFieldMap.put(alias, functionField);
  60.         this.keys.add(alias);
  61.     }
  62.    
  63.     public IExpression getExpression() {
  64.         return this.expression;
  65.     }
  66.     public List<String> getReturnFieldAliases(){
  67.         return this.keys;
  68.     }
  69.     public Object getReturnField(String alias){
  70.         return this.returnFieldMap.get(alias);
  71.     }
  72.    
  73. }