Commit 87e12c2d authored by Matija Obreza's avatar Matija Obreza

Renamed filter#buildQuery to #buildPredicate

- Copy filter to target class
parent 14e8e60b
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.model.filters;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Set;
......@@ -60,11 +61,11 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
public Set<String> NOTNULL;
/**
* Builds the DSL query.
* Builds the DSL predicate.
*
* @return the predicate
*/
public abstract Predicate buildQuery();
public abstract Predicate buildPredicate();
/**
* Builds the query.
......@@ -73,7 +74,7 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
* @param basicModel the basic model
* @param builder the builder
*/
protected void buildQuery(final EntityPathBase<R> instance, final QBasicModel basicModel, final BooleanBuilder builder) {
protected void buildPredicate(final EntityPathBase<R> instance, final QBasicModel basicModel, final BooleanBuilder builder) {
if (CollectionUtils.isNotEmpty(id)) {
builder.and(basicModel.id.in(id));
}
......@@ -86,7 +87,7 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
NOTNULL.forEach(notNullProp -> builder.and(getProperty(instance, clazz, notNullProp).isNotNull()));
}
if (NOT != null) {
builder.and(NOT.buildQuery().not());
builder.and(NOT.buildPredicate().not());
}
}
......@@ -126,6 +127,19 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
throw new RuntimeException("Error accessing field " + nullProp + " for isNull() in " + instance.getClass());
}
}
/**
* Copy by serializing to JSON and de-serializing to specified type.
*
* @param <X> the generic type
* @param targetType the target type
* @return the x
* @throws IOException Signals that an I/O exception has occurred.
*/
public <X> X copy(Class<X> targetType) throws IOException {
return jsonizer.readValue(jsonizer.writeValueAsString(this), targetType);
}
@Override
public String toString() {
......
......@@ -49,6 +49,14 @@ public class NumberFilter<T extends Number & Comparable<?>> {
*/
public T[] between;
public NumberFilter() {
}
public NumberFilter(T ge, T le) {
this.ge = ge;
this.le = le;
}
/**
* Builds the query.
*
......
......@@ -46,7 +46,7 @@ public abstract class VersionedModelFilter<T extends VersionedModelFilter<T, R>,
* @param builder the builder
*/
protected void buildQuery(final EntityPathBase<R> instance, final QVersionedModel versionedModel, final BooleanBuilder builder) {
super.buildQuery(instance, versionedModel._super, builder);
super.buildPredicate(instance, versionedModel._super, builder);
if (CollectionUtils.isNotEmpty(version)) {
builder.and(versionedModel.version.in(version));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment