Design internal filter API #31

Open
ctron opened this Issue Feb 5, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@ctron
Contributor

ctron commented Feb 5, 2016

Package Drone needs an internal filter API. Internal at least for now. The core use cases for this filter API is to filter for artifacts based on a single channel or a set of artifacts.

There are many use cases. First of old the long standing request for filling features based on a sub-set of the channel (see ctron/package-drone#66), a global search function (see ctron/package-drone#114) could also benefit from such an API and the cleanup aspect could also benefit from having a filter.

Now the requirements to such a filter API are:

  • Provide a type safe model of the filter
  • Have the possibility to serialized and deserialize the filter to a string (query string)
  • Be easy to write in Java source as well as query string

So I would like to see something in the source code that looks like this:

MetaKey MY_KEY = new MetaKey ( "ns", "key" );
ArtifactLocator al = …;

al.search ( Filters.equals ( MY_KEY, "foo-bar" ) );
al.search ( Filters.or ( Filters.equals ( MY_KEY, "foo-bar" ), Filters.equals ( MY_KEY, "bar-foo") );

// using import static

al.search ( equals ( MY_KEY, "foo-bar" ) );
al.search ( or ( equals ( MY_KEY, "foo-bar" ), equals ( MY_KEY, "bar-foo") );

// with a query string

al.search ( Filters.parse ( "foo:bar = foo-bar or foo:bar = bar-foo" ) );
al.search ( Filters.parse ( "foo:bar = 'foo-bar' or foo:bar = 'bar-foo'" ) );

With a search method like:

List<ArtifactInformation> result = al.search ( predicate);
List<ArtifactInformation> result = al.search ( predicate, options );

Of course it would be possible to use Java 8 stream on the interface, and I guess it might be a good idea to use them for implementing the ArtifactLocator for some channel types. But considering the possibility that there might be a database or some sort of index being involved some time in the future, I would like to use a filter model which is a real model which can then be transformed in e.g. a stream setup, but also to some sort of JPA query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment