Java Code Examples for cz.jirutka.rsql.parser.RSQLParser

The following examples show how to use cz.jirutka.rsql.parser.RSQLParser. These examples are extracted from open source projects. 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 Project: gemini   Source File: EntityRefTypeFilterVisitor.java    License: Apache License 2.0 6 votes vote down vote up
private QueryWithParams handleMultipleLogicalKeyEntities(EntityField field, ComparisonNode node, String sqlOperator, FilterVisitorContext filterVisitorContext) {
    List<String> arguments = node.getArguments();
    if (arguments.size() == 1) {
        Entity entityRef = field.getEntityRef();
        String entityName = wrapDoubleQuotes(entityRef.getName().toLowerCase());
        String idName = wrapDoubleQuotes(entityRef.getIdEntityField().getName().toLowerCase());
        String argument = arguments.get(0);

        // we need to parse again the argument if we dont' have a UUID.. since it contains other conditions on keys
        Node rootNode = new RSQLParser().parse(argument);
        QueryWithParams innerQuery = rootNode.accept(this.parentFilterVisitor, FilterVisitorContext.of(entityRef, filterVisitorContext.counterByParameter));
        return new QueryWithParams(String.format("SELECT %1$s.%2$s" +
                "  FROM %1$s WHERE ", entityName, idName)
                + innerQuery.getSql(), innerQuery.getParams());
    }
    throw new GeminiRuntimeException(String.format("EntityRefTypeFilterVisitor unsupported operator %s withRecord for that one argument", node.getOperator().getSymbol()));
}
 
Example 2
@BeforeEach
private void beforeMethod() {
  RSQLParser rsqlParser = new RSQLParser();
  PermissionsController controller =
      new PermissionsController(
          permissionsService, rsqlParser, objectIdentityService, userRoleTools, entityHelper);
  mockMvc =
      MockMvcBuilders.standaloneSetup(controller)
          .setMessageConverters(new FormHttpMessageConverter(), gsonHttpMessageConverter)
          .build();

  user1 = new PrincipalSid("user1");
  user2 = new PrincipalSid("user2");
  role1 = new GrantedAuthoritySid("ROLE_role1");
  role2 = new GrantedAuthoritySid("ROLE_role2");

  objectIdentity = new ObjectIdentityImpl("typeId", "identifier");
}
 
Example 3
@Bean
RestController restController() {
  return new RestController(
      authenticationSettings(),
      dataService(),
      tokenService(),
      authenticationManager(),
      permissionService(),
      userAccountService(),
      new MolgenisRSQL(new RSQLParser()),
      new RestService(
          dataService(),
          idGenerator(),
          fileStore(),
          fileMetaFactory(),
          entityManager(),
          servletUriComponentsBuilderFactory()));
}
 
Example 4
Source Project: gemini   Source File: PersistenceEntityManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void addFilter(QueryWithParams query, FilterContext filterContext, Entity entity) {
    FilterContext.FilterType filterType = filterContext.getFilterType();
    if (filterType == FilterContext.FilterType.GEMINI && !filterContext.getSearchString().isEmpty()) {
        Node rootNode = new RSQLParser(filterVisitor.getOperators()).parse(filterContext.getSearchString());

        QueryWithParams queryWithParams = rootNode.accept(filterVisitor, FilterVisitor.FilterVisitorContext.of(entity));
        query.addToSql(" WHERE " + queryWithParams.getSql());
        query.addParams(queryWithParams.getParams());
    }
    if (filterType == FilterContext.FilterType.PERSISTENCE) {
        query.addToSql(" WHERE " + filterContext.getSearchString());
        query.addParams(filterContext.getParams());
    }
}
 
Example 5
Source Project: rsql-jpa-specification   Source File: RSQLCommonSupport.java    License: MIT License 5 votes vote down vote up
public static MultiValueMap<String, String> toMultiValueMap(final String rsqlQuery) {
	log.debug("toMultiValueMap(rsqlQuery:{})", rsqlQuery);
	MultiValueMap<String, String> map = CollectionUtils.toMultiValueMap(new HashMap<>());
	if (StringUtils.hasText(rsqlQuery)) {
		new RSQLParser(RSQLOperators.supportedOperators()).parse(rsqlQuery).accept(new RSQLSimpleConverter(), map);
	}
	return map;
}
 
Example 6
Source Project: rsql-jpa-specification   Source File: RSQLCommonSupport.java    License: MIT License 5 votes vote down vote up
public static Map<String, MultiValueMap<String, String>> toComplexMultiValueMap(final String rsqlQuery) {
	log.debug("toComplexMultiValueMap(rsqlQuery:{})", rsqlQuery);
	Map<String, MultiValueMap<String, String>> map = new HashMap<>();
	if (StringUtils.hasText(rsqlQuery)) {
		new RSQLParser(RSQLOperators.supportedOperators()).parse(rsqlQuery).accept(new RSQLComplexConverter(), map);
	}
	return map;
}
 
Example 7
Source Project: rsql-jpa-specification   Source File: RSQLQueryDslSupport.java    License: MIT License 5 votes vote down vote up
public static BooleanExpression toPredicate(final String rsqlQuery, final Path qClazz, final Map<String, String> propertyPathMapper) {
	log.debug("toPredicate({},qClazz:{},propertyPathMapper:{})", rsqlQuery, qClazz);
	if (StringUtils.hasText(rsqlQuery)) {
		return new RSQLParser(RSQLOperators.supportedOperators())
				.parse(rsqlQuery)
				.accept(new RSQLQueryDslPredicateConverter(propertyPathMapper), qClazz);
	} else {
		return null;
	}
}
 
Example 8
Source Project: rsql-jpa-specification   Source File: RSQLJPASupport.java    License: MIT License 5 votes vote down vote up
public static <T> Specification<T> toSpecification(final String rsqlQuery, final boolean distinct, final Map<String, String> propertyPathMapper) {
	log.debug("toSpecification({},distinct:{},propertyPathMapper:{})", rsqlQuery, distinct, propertyPathMapper);
	return new Specification<T>() {
		public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
			query.distinct(distinct);
			if (StringUtils.hasText(rsqlQuery)) {
				Node rsql = new RSQLParser(RSQLOperators.supportedOperators()).parse(rsqlQuery);
				return rsql.accept(new RSQLJPAPredicateConverter(cb, propertyPathMapper), root);
			} else
				return null;
		}
	};
}
 
Example 9
Source Project: dremio-oss   Source File: SearchFilterToQueryConverter.java    License: Apache License 2.0 5 votes vote down vote up
public static SearchQuery toQuery(String filterStr, FilterIndexMapping mapping){

    if(Strings.isNullOrEmpty(filterStr)){
      return SearchQueryUtils.newMatchAllQuery();
    }

    final Node root = new RSQLParser(RSQL_OPERATORS).parse(filterStr);
    return root.accept(new SearchFilterToQueryConverter(mapping).visitor);
  }
 
Example 10
Source Project: pnc   Source File: RSQLProducerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public RSQLProducerImpl() {
    Set<ComparisonOperator> predicateOperators = RSQLOperators.defaultOperators();
    predicateOperators.add(LIKE);
    predicateOperators.add(NOT_LIKE);
    predicateOperators.add(IS_NULL);

    predicateParser = new RSQLParser(predicateOperators);

    Set<ComparisonOperator> sortOperators = new HashSet<>();
    sortOperators.add(ASC);
    sortOperators.add(DESC);

    sortParser = new RSQLParser(sortOperators);
}
 
Example 11
Source Project: molgenis   Source File: ApiConfig.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private RSQLParser rsqlParser() {
  Set<ComparisonOperator> operators = new HashSet<>(RSQLOperators.defaultOperators());
  operators.add(new ComparisonOperator("=q=", false));
  operators.add(new ComparisonOperator("=sq=", false));
  operators.add(new ComparisonOperator("=like=", false));
  operators.add(new ComparisonOperator("=notlike=", false));
  return new RSQLParser(operators);
}
 
Example 12
public PermissionsController(
    PermissionService permissionService,
    RSQLParser rsqlParser,
    ObjectIdentityService objectIdentityService,
    UserRoleTools userRoleTools,
    EntityHelper entityHelper) {
  super(PERMISSION_API_IDENTIFIER, 1);
  this.permissionService = requireNonNull(permissionService);
  this.rsqlParser = requireNonNull(rsqlParser);
  this.objectIdentityService = requireNonNull(objectIdentityService);
  this.userRoleTools = requireNonNull(userRoleTools);
  this.entityHelper = requireNonNull(entityHelper);
}
 
Example 13
Source Project: molgenis   Source File: RsqlConfig.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public RSQLParser rsqlParser() {
  Set<ComparisonOperator> operators = RSQLOperators.defaultOperators();
  operators.add(new ComparisonOperator("=q=", false));
  operators.add(new ComparisonOperator("=sq=", false));
  operators.add(new ComparisonOperator("=notlike=", false));
  operators.add(new ComparisonOperator("=rng=", true));
  operators.add(new ComparisonOperator("=like=", false));
  return new RSQLParser(operators);
}
 
Example 14
Source Project: tutorials   Source File: UserController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/users/rsql")
@ResponseBody
public List<User> findAllByRsql(@RequestParam(value = "search") String search) {
    Node rootNode = new RSQLParser().parse(search);
    Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    return dao.findAll(spec);
}
 
Example 15
Source Project: tutorials   Source File: RsqlIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName==john;lastName==doe");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);

    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
 
Example 16
Source Project: tutorials   Source File: RsqlIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName!=john");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);

    assertThat(userTom, isIn(results));
    assertThat(userJohn, not(isIn(results)));
}
 
Example 17
Source Project: tutorials   Source File: RsqlIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenMinAge_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("age>25");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);

    assertThat(userTom, isIn(results));
    assertThat(userJohn, not(isIn(results)));
}
 
Example 18
Source Project: tutorials   Source File: RsqlIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName==jo*");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);

    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
 
Example 19
Source Project: tutorials   Source File: RsqlIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
public void givenListOfFirstName_whenGettingListOfUsers_thenCorrect() {
    final Node rootNode = new RSQLParser().parse("firstName=in=(john,jack)");
    final Specification<User> spec = rootNode.accept(new CustomRsqlVisitor<User>());
    final List<User> results = repository.findAll(spec);

    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
 
Example 20
public QueryConverter(RSQLParser rsqlParser, QueryRsqlVisitor rsqlVisitor) {
  this.rsqlParser = requireNonNull(rsqlParser);
  this.rsqlVisitor = requireNonNull(rsqlVisitor);
}
 
Example 21
@BeforeEach
void setUpBeforeMethod() {
  // RSQLParser is final, can't be mocked
  queryConverter = new QueryConverter(new RSQLParser(), rsqlVisitor);
}
 
Example 22
Source Project: molgenis   Source File: RestConfig.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
RestConfig(RSQLParser rsqlParser) {
  this.rsqlParser = requireNonNull(rsqlParser);
}
 
Example 23
Source Project: molgenis   Source File: MolgenisRSQL.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public MolgenisRSQL(RSQLParser rsqlParser) {
  this.rsqlParser = requireNonNull(rsqlParser);
}
 
Example 24
public AggregateQueryRsqlConverter(RSQLParser rsqlParser) {
  this.rsqlParser = checkNotNull(rsqlParser);
}
 
Example 25
public QueryRsqlConverter(RSQLParser rsqlParser) {
  this.rsqlParser = rsqlParser;
}
 
Example 26
@BeforeEach
void beforeMethod() {
  molgenisRSQL = new MolgenisRSQL(new RSQLParser());
  when(repository.getEntityType()).thenReturn(entityType);
}