GithubHelp home page GithubHelp logo

vineey / archelix-rsql Goto Github PK

View Code? Open in Web Editor NEW
39.0 11.0 9.0 552 KB

This library brings the convenience of SQL declarative nature to restful APIs in the form of RSQL but without the danger of sql injection by using a typesafe mapping of allowed field paths defined via integration with querydsl library. Like sql, it supports clauses such as select, filter, pagination and sorting that can easily be represented in http request parameters. It primarily supports JPA model and MongoDB query via Querydsl.

License: MIT License

Java 100.00%
rql rsql querydsl spring-data-jpa spring-data spring-data-mongodb rest

archelix-rsql's Issues

Issue with EnumPathConverter

It doesn't convert to enum in case of "in" and "out" queries.

And exception as a result:

Caused by: java.lang.IllegalArgumentException: Parameter value [ACTIVE] did not match expected type [com.***.Status (n/a)]
at org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryImpl.java:874) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.internal.QueryImpl.access$000(QueryImpl.java:80) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.internal.QueryImpl$ParameterRegistrationImpl.bindValue(QueryImpl.java:248) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.internal.QueryImpl$JpaPositionalParameterRegistrationImpl.bindValue(QueryImpl.java:337) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:674) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:198) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:49) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
at com.mysema.query.jpa.impl.JPAUtil.setConstants(JPAUtil.java:55) ~[querydsl-jpa-3.6.5.jar:na]
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:130) ~[querydsl-jpa-3.6.5.jar:na]
at com.mysema.query.jpa.impl.AbstractJPAQuery.count(AbstractJPAQuery.java:81) ~[querydsl-jpa-3.6.5.jar:na]

*Proposed solution: *

public BooleanExpression evaluate(EnumPath path, ComparisonNode comparisonNode) {
        ComparisonOperator comparisonOperator = comparisonNode.getOperator();
        List<String> args = comparisonNode.getArguments();

        Function<String, Enum<?>> toEnumFunction = (String arg) -> {
            Enum enumArg = EnumUtils.getEnum(path.getType(), arg.toUpperCase());
            if (enumArg == null && !NULL.equalsIgnoreCase(arg)) {
                throw new IllegalArgumentException("Nonexistent enum value: " + arg);
            }
            return enumArg;
        };

        List<Enum> enumArgs = args.stream().map(toEnumFunction).collect(Collectors.toList());
        String firstArg = args.get(0);
        Enum firstEnumArg = enumArgs.get(0);

        if (EQUAL.equals(comparisonOperator)) {
            return NULL.equalsIgnoreCase(firstArg) ? path.isNull() : path.eq(firstEnumArg);
        } else if (NOT_EQUAL.equals(comparisonOperator)) {
            return NULL.equalsIgnoreCase(firstArg) ? path.isNotNull() : path.ne(firstEnumArg);
        } else if (IN.equals(comparisonOperator)) {
            return path.in(enumArgs);
        } else if (NOT_IN.equals(comparisonOperator)) {
            return path.notIn(enumArgs);
        }
        throw new UnsupportedRqlOperatorException(comparisonNode, path.getClass());
    }

Converters

Implements converters from rsql-parser to Querydsl sets of Path types such as DatePath, DateTimePath, StringPath, EnumPath, NumberPath, BooleanPath, CollectionPath, TimePath,etc.

RHS path support (Ad Hoc JOIN)?

Hi,

Is it possible to have an expression like employee.company_id == company.id ?

i.e. having a path on both sides of the expression?

Use a generic DSL API

Using a generic DSL API, this shields users from internal implementations and any future refactoring.
Also refactor querydsl modules. split into major modules such as mongodb and jpa implementations.

NPE during simple filter parsing

I haven't dug into the issue, but when parsing a simple filter principal == 035489f4-d602-46c5-b568-39d1f852b565 I get an NPE:

Caused by: java.lang.NullPointerException
	at com.github.vineey.rql.querydsl.filter.QuerydslRsqlVisitor.visit(QuerydslRsqlVisitor.java:80) ~[rsql-querydsl-filter-2.0.0.RELEASE.jar:?]
	at com.github.vineey.rql.querydsl.filter.QuerydslRsqlVisitor.visit(QuerydslRsqlVisitor.java:37) ~[rsql-querydsl-filter-2.0.0.RELEASE.jar:?]
	at cz.jirutka.rsql.parser.ast.ComparisonNode.accept(ComparisonNode.java:70) ~[rsql-parser-2.1.0.jar:2.1.0]
	at com.github.vineey.rql.querydsl.filter.QuerydslFilterBuilder.visit(QuerydslFilterBuilder.java:34) ~[rsql-querydsl-filter-2.0.0.RELEASE.jar:?]
	at com.github.vineey.rql.querydsl.filter.QuerydslFilterBuilder.visit(QuerydslFilterBuilder.java:31) ~[rsql-querydsl-filter-2.0.0.RELEASE.jar:?]
	at com.github.vineey.rql.filter.parser.DefaultFilterParser.parse(DefaultFilterParser.java:42) ~[rsql-api-filter-2.0.0.RELEASE.jar:?]

How to query by relationship?

Is it possible to query by relationship (using spring-data-mongodb)?

I've an Item Model and an Item belongs to a Category. I would like to query the items by category.id=={id}.

I already added these path mappings but the results are always empty.

.put("category", QProduct.item.category)
.put("category.id", QProduct.item.category.id)

QueryDSL SQL 4.1.0

Hello,

You have here a very interesting project that I would like to use. My question is, does it work with last version of QueryDSL SQL 4.1.0?

Thank you.

Is there a way to go without mappings.

I always need to map type -> QEntity.entity.type, type.value -> QEntity.entity.type.value, etc.
Is there a way to not explicitly specify all mappings as I want this to work for all class properties and paths and I have many entities. I can easily create a method that generates from a string a class path through reflection but I'll need the mapping object to be a closure that takes (String path, Class qclass ) and return the Path object instead of a static Map.

Support ISO8660 date formats.

First of all, great job!

The spec in http://doc.apsstandard.org/2.1/spec/rql/ mandate dates to be in ISO UTC format. This also is the date format on the JSON spec and the format returned by JS Date.toJSON. This means the DateUtil class should not fail on strings like 2016-07-17T02:59:59.999Z.

The thing, though is how that it converts to a LocalDateTime. I'm not sure if dropping the time zone info (the Z in the string) is always the correct solution since some masochists developers might use something different than UTC for their timezone.

Custom path converter support

Hello
It seems like the PathConverterContext con't be extened to supprot other path types, like UUID for example. My filter looks like this : uuidField=='CED17E16-78AF-47F6-8ACB-CF5CEEBBF8DB' where uuidField field is defined as private UUID uuidField.
The QuerydslRsqlVisitor::visit method fails with NullPointerException because PathConverterContext.getOperator(path) return null for UUID type.
Is there any workaround to overcome this ?
Thanks

License file is missing

This looks like a nice library. Could you please add a license file or statement indicating what the licensing of this code is. For example, the RSQL project on which this is based is MIT License.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.