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