Commit 3aadc3dd authored by Matija Obreza's avatar Matija Obreza

Added accessors to object filters

parent 35d46216
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,15 +15,16 @@
*/
package org.genesys.blocks.model.filters;
import java.util.HashSet;
import java.util.Set;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.EntityPathBase;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.QAuditedVersionedModel;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.EntityPathBase;
/**
* {@link AuditedVersionedModel} match by sample filters.
*
......@@ -67,4 +68,52 @@ public abstract class AuditedVersionedModelFilter<T extends AuditedVersionedMode
builder.and(lastModifiedDate.buildQuery(auditedVersionedModel.lastModifiedDate));
}
}
/**
* Created by.
*
* @return the sets the
*/
public synchronized Set<Long> createdBy() {
if (createdBy == null) {
createdBy = new HashSet<>();
}
return createdBy;
}
/**
* Last modified by.
*
* @return the sets the
*/
public synchronized Set<Long> lastModifiedBy() {
if (lastModifiedBy == null) {
lastModifiedBy = new HashSet<>();
}
return lastModifiedBy;
}
/**
* Created date.
*
* @return the date filter
*/
public synchronized DateFilter createdDate() {
if (createdDate == null) {
createdDate = new DateFilter();
}
return createdDate;
}
/**
* Last modified date.
*
* @return the date filter
*/
public synchronized DateFilter lastModifiedDate() {
if (lastModifiedDate == null) {
lastModifiedDate = new DateFilter();
}
return lastModifiedDate;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@ package org.genesys.blocks.model.filters;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
......@@ -79,11 +80,11 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
builder.and(basicModel.id.in(id));
}
if (NULL != null && !NULL.isEmpty()) {
Class<?> clazz = instance.getClass();
final Class<?> clazz = instance.getClass();
NULL.forEach(nullProp -> builder.and(getProperty(instance, clazz, nullProp).isNull()));
}
if (NOTNULL != null && !NOTNULL.isEmpty()) {
Class<?> clazz = instance.getClass();
final Class<?> clazz = instance.getClass();
NOTNULL.forEach(notNullProp -> builder.and(getProperty(instance, clazz, notNullProp).isNotNull()));
}
if (NOT != null) {
......@@ -117,7 +118,7 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
private SimpleExpression<?> getProperty(final EntityPathBase<R> instance, final Class<?> clazz, final String nullProp) {
try {
Field prop = clazz.getField(nullProp);
final Field prop = clazz.getField(nullProp);
if (SimpleExpression.class.isAssignableFrom(prop.getType())) {
return (SimpleExpression<?>) prop.get(instance);
} else {
......@@ -127,8 +128,7 @@ 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.
*
......@@ -137,7 +137,7 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
* @return the x
* @throws IOException Signals that an I/O exception has occurred.
*/
public <X> X copy(Class<X> targetType) throws IOException {
public <X> X copy(final Class<X> targetType) throws IOException {
return jsonizer.readValue(jsonizer.writeValueAsString(this), targetType);
}
......@@ -145,8 +145,44 @@ public abstract class BasicModelFilter<T extends BasicModelFilter<T, R>, R exten
public String toString() {
try {
return jsonizer.writeValueAsString(this);
} catch (JsonProcessingException e) {
} catch (final JsonProcessingException e) {
throw new RuntimeException("Could not serialize to JSON: " + e.getMessage(), e);
}
}
/**
* Id.
*
* @return the sets the
*/
public synchronized Set<Long> id() {
if (id == null) {
id = new HashSet<>();
}
return id;
}
/**
* Checks if is null.
*
* @return the sets the
*/
public synchronized Set<String> isNull() {
if (NULL == null) {
NULL = new HashSet<>();
}
return NULL;
}
/**
* Not null.
*
* @return the sets the
*/
public synchronized Set<String> notNull() {
if (NOTNULL == null) {
NOTNULL = new HashSet<>();
}
return NOTNULL;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -47,6 +47,7 @@ public class DateFilter {
*
* @deprecated Use {@link #ge} and {@link #le}
*/
@Deprecated
public Date[] between;
/**
......@@ -69,7 +70,7 @@ public class DateFilter {
if (lt != null) {
and.and(date.lt(lt));
}
if ((between != null) && (between.length == 2)) {
if (between != null && between.length == 2) {
and.and(date.between(between[0], between[1]));
}
return and;
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.model.filters;
import java.util.HashSet;
import java.util.Set;
import com.querydsl.core.BooleanBuilder;
......@@ -47,16 +48,26 @@ public class NumberFilter<T extends Number & Comparable<?>> {
*
* @deprecated Use {@link #ge} and {@link #le}
*/
@Deprecated
public T[] between;
/**
* Instantiates a new number filter.
*/
public NumberFilter() {
}
public NumberFilter(T ge, T le) {
/**
* Instantiates a new number filter.
*
* @param ge the ge
* @param le the le
*/
public NumberFilter(final T ge, final T le) {
this.ge = ge;
this.le = le;
}
}
/**
* Builds the query.
*
......@@ -80,9 +91,21 @@ public class NumberFilter<T extends Number & Comparable<?>> {
if (le != null) {
and.and(val.loe(le));
}
if ((between != null) && (between.length == 2)) {
if (between != null && between.length == 2) {
and.and(val.between(between[0], between[1]));
}
return and;
}
/**
* Eq.
*
* @return the sets the
*/
public synchronized Set<T> eq() {
if (eq == null) {
eq = new HashSet<>();
}
return eq;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.model.filters;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
......@@ -51,4 +52,16 @@ public abstract class UuidModelFilter<T extends UuidModelFilter<T, R>, R extends
builder.and(uuidModel.uuid.in(uuid));
}
}
/**
* Uuid.
*
* @return the sets the
*/
public synchronized Set<UUID> uuid() {
if (uuid == null) {
uuid = new HashSet<>();
}
return uuid;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,15 +15,16 @@
*/
package org.genesys.blocks.model.filters;
import java.util.HashSet;
import java.util.Set;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.EntityPathBase;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.QVersionedModel;
import org.genesys.blocks.model.VersionedModel;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.EntityPathBase;
/**
* {@link VersionedModel} match by sample filters.
*
......@@ -54,4 +55,16 @@ public abstract class VersionedModelFilter<T extends VersionedModelFilter<T, R>,
builder.and(versionedModel.active.eq(active));
}
}
/**
* Version.
*
* @return the sets the
*/
public synchronized Set<Integer> version() {
if (version == null) {
version = new HashSet<>();
}
return 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