Coder Social home page Coder Social logo

runway's Issues

Runway local filter does not work when Condition/Criteria contains Links

 /**
     * Perform local {@code criteria} resolution and return all the records in
     * {@code clazz} that match.
     * 
     * @param <T>
     * @param clazz
     * @param criteria
     * @param order
     * @param page
     * @param realms
     * @return the matching records in {@code clazz}
     */
    private <T extends Record> Set<T> filter(Class<T> clazz, Criteria criteria,
            @Nullable Order order, @Nullable Page page,
            @Nonnull Realms realms) {
        ConcourseCompiler compiler = ConcourseCompiler.get();
        ConditionTree ast = (ConditionTree) compiler
                .parse($Criteria.amongRealms(realms, criteria));
        String[] keys = compiler.analyze(ast).keys()
                .toArray(Array.containing());
        Predicate<T> filter = record -> compiler.evaluate(ast,
                record.mmap(keys));
        if(page != null) {
            return Pagination.applyFilterAndPage(
                    $page -> order == null ? load(clazz, $page)
                            : load(clazz, order, $page),
                    filter, page);
        }
        else {
            Set<T> records = order == null ? load(clazz) : load(clazz, order);
            return records.stream().filter(filter)
                    .collect(Collectors.toCollection(LinkedHashSet::new));
        }
    }

    /**
     * Perform local {@code criteria} resolution and return all the records in
     * the hierarchy of {@code clazz} that match.
     * 
     * @param <T>
     * @param clazz
     * @param criteria
     * @param order
     * @param page
     * @param realms
     * @return the matching records in the {@code clazz} hierarchy
     */
    private <T extends Record> Set<T> filterAny(Class<T> clazz,
            Criteria criteria, @Nullable Order order, @Nullable Page page,
            @Nonnull Realms realms) {
        ConcourseCompiler compiler = ConcourseCompiler.get();
        ConditionTree ast = (ConditionTree) compiler
                .parse($Criteria.amongRealms(realms, criteria));
        String[] keys = compiler.analyze(ast).keys()
                .toArray(Array.containing());
        Predicate<T> filter = record -> compiler.evaluate(ast,
                record.mmap(keys));
        if(page != null) {
            return Pagination
                    .applyFilterAndPage(
                            $page -> order == null ? loadAny(clazz, $page)
                                    : loadAny(clazz, order, $page),
                            filter, page);
        }
        else {
            Set<T> records = order == null ? loadAny(clazz)
                    : loadAny(clazz, order);
            return records.stream().filter(filter)
                    .collect(Collectors.toCollection(LinkedHashSet::new));
        }
    }

The code above needs to be modified to modify the output of record.mmap to change any Record values to Link.to values. this is because the Criteria that is passed in will feature Links as values (e.g., Operator.LINKS_TO) and that compiler will fail to match that against the actual Record objects

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.