Package it.eng.qbe.query

Examples of it.eng.qbe.query.ExpressionNode


   * @param optionalUserFilters
   * @throws JSONException
   */
  public static void applyOptionalFilters(Query query, JSONObject optionalUserFilters) throws JSONException{
    String[] fields = JSONObject.getNames(optionalUserFilters);
    ExpressionNode leftExpression = query.getWhereClauseStructure();
    for(int i=0; i<fields.length; i++){
      String fieldName = fields[i];
      JSONArray valuesArray = optionalUserFilters.getJSONArray(fieldName);

      //if the filter has some value
      if(valuesArray.length()>0){

        String[] values = new String[1];
        values[0] =fieldName;

        Operand leftOperand = new Operand(values,fieldName, AbstractStatement.OPERAND_TYPE_FIELD, values,values);

        values = new String[valuesArray.length()];
        for(int j=0; j<valuesArray.length(); j++){
          values[j] = valuesArray.getString(j);
        }

        Operand rightOperand = new Operand(values,fieldName, AbstractStatement.OPERAND_TYPE_STATIC, values, values);

        String operator = "NOT EQUALS TO";
        if(valuesArray.length()>0){
          operator="IN";
        }

        query.addWhereField("OptionalFilter"+i, "OptionalFilter"+i, false, leftOperand, operator, rightOperand, "AND");



        ExpressionNode filterNode = new ExpressionNode("NO_NODE_OP","$F{OptionalFilter"+i+"}");

        //build the where clause tree
        if(leftExpression==null){
          leftExpression = filterNode;
        }else{
          ExpressionNode operationNode = new ExpressionNode("NODE_OP", "AND");
          operationNode.addChild(leftExpression);
          operationNode.addChild(filterNode);
          leftExpression = operationNode;
        }
      }
    }
    query.setWhereClauseStructure(leftExpression);
View Full Code Here


                option = temp;
                break;
              }
            }
            if (option != null) {
              ExpressionNode node = applyStaticClosedFilterToWhereClause(query, option);
              updateWhereClauseStructure(query, node, "AND");
            }
          }
        } else {
          JSONArray options = aStaticClosedFilter.getJSONArray(QbeJSONTemplateParser.OPTIONS);
          List<ExpressionNode> nodes = new ArrayList<ExpressionNode>();
          for (int j = 0; j < options.length(); j++) {
            JSONObject option = options.getJSONObject(j);
            boolean isActive = formViewerState.isOnOffFilterActive(filterGroupId, option.getString(QbeJSONTemplateParser.ID));
            if (isActive) {
              ExpressionNode node = applyStaticClosedFilterToWhereClause(query, option);
              nodes.add(node);
            }
          }
          if (!nodes.isEmpty()) {
            String booleanConnector = aStaticClosedFilter.getString("booleanConnector");
View Full Code Here

      }
      query.addWhereField(filter.getString("id"), null, false, leftOperand, filter.getString("operator"), rightOperand, filter.getString("booleanConnector"));
    }
    // updating where clause structure: the new condition must be added with AND boolean connector
    JSONObject expression = option.getJSONObject("expression");
    ExpressionNode node = QueryJSONDeserializer.getFilterExpTree(expression);
    return node;
  }
View Full Code Here

    return node;
  }
 
  private void updateWhereClauseStructure(Query query, String filterId,
      String booleanConnector) {
    ExpressionNode node = query.getWhereClauseStructure();
    ExpressionNode newFilterNode = new ExpressionNode("NODE_CONST", "$F{" + filterId + "}");
    if (node == null) {
      node = newFilterNode;
      query.setWhereClauseStructure(node);
    } else {
      if (node.getType() == "NODE_OP" && node.getValue().equals(booleanConnector)) {
        node.addChild(newFilterNode);
      } else {
        ExpressionNode newNode = new ExpressionNode("NODE_OP", booleanConnector);
        newNode.addChild(node);
        newNode.addChild(newFilterNode);
        query.setWhereClauseStructure(newNode);
      }
    }
  }
View Full Code Here

    }
  }

  private void updateWhereClauseStructure(Query query, ExpressionNode nodeToInsert,
      String booleanConnector) {
    ExpressionNode node = query.getWhereClauseStructure();
    if (node == null) {
      node = nodeToInsert;
      query.setWhereClauseStructure(node);
    } else {
      ExpressionNode newNode = new ExpressionNode("NODE_OP", booleanConnector);
      newNode.addChild(node);
      newNode.addChild(nodeToInsert);
      query.setWhereClauseStructure(newNode);
    }
  }
View Full Code Here

    }
  }
 
  private void updateWhereClauseStructure(Query query, List<ExpressionNode> list,
      String booleanConnectorBetweenNodes, String booleanConnector) {
    ExpressionNode node = query.getWhereClauseStructure();
    ExpressionNode nodeToInsert = new ExpressionNode("NODE_OP", booleanConnectorBetweenNodes);
    Iterator<ExpressionNode> it = list.iterator();
    while (it.hasNext()) {
      nodeToInsert.addChild(it.next());
    }
    if (node == null) {
      node = nodeToInsert;
      query.setWhereClauseStructure(node);
    } else {
      ExpressionNode newNode = new ExpressionNode("NODE_OP", booleanConnector);
      newNode.addChild(node);
      newNode.addChild(nodeToInsert);
      query.setWhereClauseStructure(newNode);
    }
  }
View Full Code Here

    Query query = new Query();
    query.addSelectFiled(fieldUniqueName, "NONE", "Valori", true, true, false, "asc", null);
    query.setDistinctClauseEnabled(true);
    if (filtersJSON != null) {
     
      ExpressionNode whereClauseStructure = new ExpressionNode("NODE_CONST", "$F{Filter1}");
      query.setWhereClauseStructure(whereClauseStructure);
      String valuefilter = (String) filtersJSON.get(SpagoBIConstants.VALUE_FILTER);
      String typeFilter = (String) filtersJSON.get(SpagoBIConstants.TYPE_FILTER);
      String typeValueFilter = (String) filtersJSON.get(SpagoBIConstants.TYPE_VALUE_FILTER);
      WhereField.Operand leftOperand = new WhereField.Operand(new String[] {fieldUniqueName}, "", AbstractStatement.OPERAND_TYPE_FIELD, null, null);
View Full Code Here

    try {
      exp.put(QuerySerializationConstants.EXPRESSION_TYPE, filterExp.getType()) ;
      exp.put(QuerySerializationConstants.EXPRESSION_VALUE, filterExp.getValue());
     
      for(int i = 0; i < filterExp.getChildNodes().size(); i++) {
        ExpressionNode child = (ExpressionNode)filterExp.getChildNodes().get(i);
        JSONObject childJSON = encodeFilterExp(child);
        childsJSON.put(childJSON);
      }   
     
      exp.put(QuerySerializationConstants.EXPRESSION_CHILDREN, childsJSON);
View Full Code Here

  */
 
 
 
  private void deserializeExpression(JSONObject expressionJOSN, IDataSource dataSource, Query query) throws SerializationException {
    ExpressionNode filterExp;
   
    // start recursion
    filterExp = getFilterExpTree( expressionJOSN );
   
    query.setWhereClauseStructure( filterExp );
View Full Code Here

    }
    */
  }
 
  public static ExpressionNode getFilterExpTree(JSONObject nodeJSON) throws SerializationException {
    ExpressionNode node = null;
    String nodeType;
    String nodeValue;
    JSONArray childNodesJSON;
   
    if(nodeJSON.has("type") && nodeJSON.has("value")) {   
      try {
      nodeType = nodeJSON.getString("type");
      nodeValue = nodeJSON.getString("value");     
      node = new ExpressionNode(nodeType, nodeValue);
     
      childNodesJSON = nodeJSON.getJSONArray("childNodes");
      for(int i = 0; i < childNodesJSON.length(); i++) {
        JSONObject childNodeJSON = childNodesJSON.getJSONObject(i);
        node.addChild( getFilterExpTree(childNodeJSON) );
      }
      } catch(JSONException e) {
        throw new SerializationException("An error occurred while deserializing where clause structure: " + nodeJSON.toString(), e);
      }
    }
View Full Code Here

TOP

Related Classes of it.eng.qbe.query.ExpressionNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.