Package org.molgenis.framework.db

Examples of org.molgenis.framework.db.QueryRule


    if (getParent() != null && getParent() instanceof MenuController)
    {
      // set the filter to select the xref-ed entity
      pager.resetFilters();
      getModel().setUserRules(new ArrayList<QueryRule>());
      QueryRule rule = new QueryRule(request.getString("attribute"), QueryRule.Operator.valueOf(request
          .getString("operator")), request.getString("value"));
      pager.addFilter(rule);

      // tell "my" menu to select me
      WritableTuple tuple = new KeyValueTuple();
View Full Code Here


  }

  @Override
  public QueryRule getSortRule()
  {
    final QueryRule sortAsc = getRule(Operator.SORTASC);
    if (sortAsc != null)
    {
      return sortAsc;
    }
    else
View Full Code Here

    }
  }

  private QueryRule getRule(final Operator operator)
  {
    final QueryRule rule = (QueryRule) CollectionUtils.find(filters, new Predicate()
    {

      @Override
      public boolean evaluate(Object arg0)
      {
View Full Code Here

  public static String toRESTstring(List<QueryRule> rules)
  {
    StringBuffer filters = new StringBuffer();

    QueryRule previousRule = null;
    for (QueryRule r : rules)
    {
      if (rules.indexOf(r) > 0)
      {
        if (QueryRule.Operator.OR.equals(previousRule.getOperator()))
        {
          filters.append("\\|");
        }
        else
        {
View Full Code Here

          {
            value = value.substring(1, value.length() - 1);
          }
        }
      }
      if (field == null || field.equals("")) rules.add(new QueryRule(operator, value));
      else
        rules.add(new QueryRule(field, operator, value));
    }

    return rules;
  }
View Full Code Here

          if (StringUtils.isNotEmpty(postData.getSidx()))
          {
            final Operator sortOperator = StringUtils.equals(postData.getSord(), "asc") ? QueryRule.Operator.SORTASC
                : QueryRule.Operator.SORTDESC;
            rules.add(new QueryRule(sortOperator, postData.getSidx()));
          }

          if ((tupleTable instanceof FilterableTupleTable) && !request.isNull("_search")
              && request.getBoolean("_search"))
          {
View Full Code Here

      final String groupOp = filters.getGroupOp();

      int ruleIdx = 0;
      for (final JQGridRule rule : filters.getRules())
      {
        final QueryRule queryRule = convertOperator(rule);
        rules.add(queryRule);

        final boolean notLast = filters.getRules().size() - 1 != ruleIdx++;
        if (groupOp.equals("OR") && notLast)
        {
          rules.add(new QueryRule(QueryRule.Operator.OR));
        }
      }
    }
    return rules;
  }
View Full Code Here

   */

  private static QueryRule convertOperator(JQGridRule jqGridRule)
  {
    // ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
    QueryRule rule = new QueryRule(jqGridRule.getField(), QueryRule.Operator.EQUALS, jqGridRule.getData());
    switch (jqGridRule.getOp())
    {
      case eq:
        rule.setOperator(QueryRule.Operator.EQUALS);
        return rule;
      case ne:
        rule.setOperator(QueryRule.Operator.EQUALS);
        return toNotRule(rule);
      case lt:
        rule.setOperator(QueryRule.Operator.LESS);
        return rule;
      case le:
        rule.setOperator(QueryRule.Operator.LESS_EQUAL);
        return rule;
      case gt:
        rule.setOperator(QueryRule.Operator.GREATER);
        return rule;
      case ge:
        rule.setOperator(QueryRule.Operator.GREATER_EQUAL);
        return rule;
      case bw:
        rule.setValue(jqGridRule.getData() + "%");
        rule.setOperator(QueryRule.Operator.LIKE);
        return rule;
      case bn:
        // NOT
        rule.setValue(jqGridRule.getData() + "%");
        rule.setOperator(QueryRule.Operator.LIKE);
        rule = toNotRule(rule);
        return rule;
      case in:
        rule.setOperator(QueryRule.Operator.IN);
        return rule;
      case ni:
        // NOT
        rule.setOperator(QueryRule.Operator.IN);
        rule = toNotRule(rule);
        return rule;
      case ew:
        rule.setValue("%" + jqGridRule.getData());
        rule.setOperator(QueryRule.Operator.LIKE);
        return rule;
      case en:
        // NOT
        rule.setValue("%" + jqGridRule.getData());
        rule.setOperator(QueryRule.Operator.LIKE);
        return toNotRule(rule);
      case cn:
        rule.setValue("%" + jqGridRule.getData() + "%");
        rule.setOperator(QueryRule.Operator.LIKE);
        return rule;
      case nc:
        // NOT
        rule.setValue("%" + jqGridRule.getData() + "%");
        rule.setOperator(QueryRule.Operator.LIKE);
        return toNotRule(rule);
      default:
        throw new IllegalArgumentException(String.format("Unkown Operator: %s", jqGridRule.getOp()));
    }
  }
View Full Code Here

    // watch out, the "IN" operator expects an Object[]
    CsvWriter csvWriter = new CsvWriter(csvDownload);
    try
    {
      db.find(view.getController().getEntityClass(), csvWriter, fieldsToExport, new QueryRule("id", Operator.IN,
          records));
    }
    finally
    {
      csvWriter.close();
View Full Code Here

    List<QueryRule> rules = new ArrayList<QueryRule>();
    rules.addAll(this.getSystemRules());
    rules.addAll(this.getUserRules());
    if (includingLimitOffset)
    {
      if (this.limit > 0) rules.add(new QueryRule(QueryRule.Operator.LIMIT, this.limit));
      if (this.offset > 0) rules.add(new QueryRule(QueryRule.Operator.OFFSET, this.offset));
    }
    if (!StringUtils.equals(this.sortby, "")) rules.add(new QueryRule(this.sortMode, this.sortby));
    logger.debug("rules.size: " + rules.size() + "=" + this.getSystemRules().size() + "+"
        + this.getUserRules().size());
    return rules.toArray(new QueryRule[rules.size()]);
  }
View Full Code Here

TOP

Related Classes of org.molgenis.framework.db.QueryRule

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.