cz.jirutka.rsql.parser.RSQLParserException Java Examples

The following examples show how to use cz.jirutka.rsql.parser.RSQLParserException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryConverter.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Query convert(@Nonnull String source) {
  Node node;
  try {
    node = rsqlParser.parse(source);
  } catch (RSQLParserException e) {
    Throwable cause = e.getCause();
    if (cause instanceof UnknownOperatorException) {
      String operator = ((UnknownOperatorException) cause).getOperator();
      throw new UnknownQueryOperatorException(operator);
    } else {
      throw new QueryParseException(e);
    }
  }
  return node.accept(rsqlVisitor);
}
 
Example #2
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testComplexQuery() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q =
      molgenisRSQL.createQuery("((name==piet;age==87),(name==klaas;age>100))", repository);
  assertEquals(
      new QueryImpl<>()
          .nest()
          .nest()
          .eq("name", "piet")
          .and()
          .eq("age", 87)
          .unnest()
          .or()
          .nest()
          .eq("name", "klaas")
          .and()
          .gt("age", 100)
          .unnest()
          .unnest(),
      q);
}
 
Example #3
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
void testEquals() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("name==piet", repository);
  assertEquals(new QueryImpl<>().eq("name", "piet"), q);

  q = molgenisRSQL.createQuery("name=='piet paulusma'", repository);
  assertEquals(new QueryImpl<>().eq("name", "piet paulusma"), q);

  q = molgenisRSQL.createQuery("age==87", repository);
  assertEquals(new QueryImpl<>().eq("age", 87), q);
}
 
Example #4
Source File: QueryParseExceptionTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("languageMessageProvider")
@Override
protected void testGetLocalizedMessage(String lang, String message) {
  RSQLParserException ex = mock(RSQLParserException.class);
  when(ex.getLocalizedMessage()).thenReturn("RSQL MESSAGE");
  Throwable cause = new IllegalAccessException("Query cannot be null");
  when(ex.getCause()).thenReturn(cause);
  assertExceptionMessageEquals(new QueryParseException(ex), lang, message);
}
 
Example #5
Source File: PermissionsController.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Set<Sid> getSidsFromQuery(String queryString) {
  Set<Sid> sids = Collections.emptySet();
  if (!Strings.isNullOrEmpty(queryString)) {
    try {
      Node node = rsqlParser.parse(queryString);
      PermissionsQuery permissionsQuery = node.accept(new PermissionRsqlVisitor());
      sids =
          new LinkedHashSet<>(
              userRoleTools.getSids(permissionsQuery.getUsers(), permissionsQuery.getRoles()));
    } catch (RSQLParserException e) {
      throw new PermissionQueryParseException(e);
    }
  }
  return sids;
}
 
Example #6
Source File: PermissionQueryParseExceptionTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("languageMessageProvider")
@Override
protected void testGetLocalizedMessage(String lang, String message) {
  RSQLParserException cause = mock(RSQLParserException.class);
  when(cause.getLocalizedMessage()).thenReturn("bacause");
  ExceptionMessageTest.assertExceptionMessageEquals(
      new PermissionQueryParseException(cause), lang, message);
}
 
Example #7
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGreaterThanOrEqual() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age>=87", repository);
  assertEquals(new QueryImpl<>().ge("age", 87), q);
}
 
Example #8
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGreaterThan() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age>87", repository);
  assertEquals(new QueryImpl<>().gt("age", 87), q);
}
 
Example #9
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testLessThanOrEqual() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age<=87", repository);
  assertEquals(new QueryImpl<>().le("age", 87), q);
}
 
Example #10
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testLessThan() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  Query<Entity> q = molgenisRSQL.createQuery("age<87", repository);
  assertEquals(new QueryImpl<>().lt("age", 87), q);
}
 
Example #11
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testAnd() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  // ';' and 'and' or synonyms

  Query<Entity> q = molgenisRSQL.createQuery("name==piet and age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").and().eq("age", 87).unnest(), q);

  q = molgenisRSQL.createQuery("name==piet;age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").and().eq("age", 87).unnest(), q);
}
 
Example #12
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testOr() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");
  doReturn(ageAttr).when(entityType).getAttribute("age");

  // ',' and 'or' or synonyms

  Query<Entity> q = molgenisRSQL.createQuery("name==piet or age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").or().eq("age", 87).unnest(), q);

  q = molgenisRSQL.createQuery("name==piet,age==87", repository);
  assertEquals(new QueryImpl<>().nest().eq("name", "piet").or().eq("age", 87).unnest(), q);
}
 
Example #13
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGreaterThanOnNonNumericalAttribute() throws RSQLParserException {
  Attribute nameAttr = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock();
  doReturn(nameAttr).when(entityType).getAttribute("name");

  assertThrows(
      IllegalArgumentException.class, () -> molgenisRSQL.createQuery("name>87", repository));
}
 
Example #14
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGreaterThanWithNonNumericalArg() throws RSQLParserException {
  Attribute ageAttr = when(mock(Attribute.class).getDataType()).thenReturn(INT).getMock();
  doReturn(ageAttr).when(entityType).getAttribute("age");

  assertThrows(
      NumberFormatException.class, () -> molgenisRSQL.createQuery("age>bogus", repository));
}
 
Example #15
Source File: JavaUtilPredicateTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
@Test(expected = RSQLParserException.class)
public void shouldThrowExceptionOnIncorrectSyntax() throws Exception {
    // given
    String rsql = "error";

    // when //then
    new RSQLNodeTravellerPredicate(TestClass.class, rsql);
}
 
Example #16
Source File: PermissionQueryParseException.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PermissionQueryParseException(RSQLParserException cause) {
  super(ERROR_CODE, cause);
  this.cause = requireNonNull(cause);
}
 
Example #17
Source File: QueryParseException.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
public QueryParseException(RSQLParserException parseException) {
  super(ERROR_CODE);
  this.parseException = requireNonNull(parseException);
}
 
Example #18
Source File: MolgenisRSQLTest.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
void testUnknowAttribute() throws RSQLParserException {
  assertThrows(
      UnknownAttributeException.class,
      () -> molgenisRSQL.createQuery("nonexistingattribute==piet", repository));
}