Skip to content

Commit

Permalink
feat: remove Raw Junction
Browse files Browse the repository at this point in the history
Closes #48
  • Loading branch information
Idane committed Sep 5, 2022
1 parent 350723d commit 7d39e5e
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@
import javax.validation.Validator;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -161,7 +154,7 @@ public <ID extends Serializable, Entity extends BaseCrudEntity<ID>> void validat
throw new IllegalStateException("A FilterField must have an operation");
}

boolean isJunction = filterField.getOperation() == FilterFieldOperation.And || filterField.getOperation() == FilterFieldOperation.Or || filterField.getOperation() == FilterFieldOperation.Not || filterField.getOperation() == FilterFieldOperation.RawJunction;
boolean isJunction = filterField.getOperation() == FilterFieldOperation.And || filterField.getOperation() == FilterFieldOperation.Or || filterField.getOperation() == FilterFieldOperation.Not;
if (isJunction) {
if (filterField.getChildren() != null && !filterField.getChildren().isEmpty()) {
validateAndFillFilterFieldMetadata(filterField.getChildren(), entityClazz);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,6 @@ public static FilterField containsIn(String fieldName, String... values) {
return null;
}

public static FilterField rawJunction(BaseRawJunction rawJunctionDTO) {
if(rawJunctionDTO == null || rawJunctionDTO.getJunction() == null) {
return null;
}

return createFilterField("", FilterFieldOperation.RawJunction, FilterFieldDataType.None, null, rawJunctionDTO);
}

public static FilterField notContainsIn(String fieldName, String... values) {
if(values != null && values.length > 0) {
return createFilterField(fieldName, FilterFieldOperation.NotContainsIn, FilterFieldDataType.String, null, values);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package studio.crud.crudframework.modelfilter.dsl

import studio.crud.crudframework.model.PersistentEntity
import studio.crud.crudframework.modelfilter.BaseRawJunction
import studio.crud.crudframework.modelfilter.FilterField
import studio.crud.crudframework.modelfilter.dsl.annotation.FilterFieldDsl
import studio.crud.crudframework.modelfilter.enums.FilterFieldDataType
import studio.crud.crudframework.modelfilter.enums.FilterFieldOperation
import java.util.Date
import java.util.*
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty1

Expand Down Expand Up @@ -354,14 +353,6 @@ class FilterFieldsBuilder<RootType : PersistentEntity>(private val filterFields:
filterFields += FilterField(effectiveName, FilterFieldOperation.IsNotNull, FilterFieldDataType.Object, null, null)
}

fun rawJunction(junctionSupplier: () -> BaseRawJunction<*>) {
filterFields += FilterField().apply {
this.operation = FilterFieldOperation.RawJunction
this.dataType = FilterFieldDataType.None
this.values = arrayOf(junctionSupplier())
}
}

infix fun <ChildType : PersistentEntity> KProperty1<RootType, ChildType?>.Sub(setup: FilterFieldsBuilder<ChildType>.() -> Unit) {
val prefix = if (fieldPrefix.isEmpty()) name else "$fieldPrefix/$name"
val filterFieldsBuilder = FilterFieldsBuilder<ChildType>(fieldPrefix = prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum class FilterFieldOperation(val junction: Boolean = false) {
Not(true),
ContainsIn,
NotContainsIn,
RawJunction(true),
StartsWith,
EndsWith,
Noop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ fun FilterField.matches(target: Any): Boolean {
FilterFieldOperation.NotContainsIn -> {
throw UnsupportedOperationException("Cannot use NotContainsIn in FilterField.matches")
}
FilterFieldOperation.RawJunction -> throw UnsupportedOperationException("Cannot use RawJunction in FilterField.matches")
FilterFieldOperation.StartsWith -> {
actualValue as String
val value = this.value1 as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import strikt.assertions.isFalse
import strikt.assertions.isTrue
import studio.crud.crudframework.model.BaseCrudEntity
import studio.crud.crudframework.model.PersistentEntity
import studio.crud.crudframework.modelfilter.BaseRawJunction
import studio.crud.crudframework.modelfilter.dsl.where
import java.util.Date
import java.util.*

private class Customer(
val name: String = "Test",
Expand Down Expand Up @@ -381,20 +380,6 @@ class DynamicModelFilterUtilsTest {
}
}

@Test
fun `test RawJunction operation happy flow`() {
val customer = Customer()
val filter = where<Customer> {
rawJunction {
object : BaseRawJunction<Any>(1) {}
}
}

expectThrows<UnsupportedOperationException> {
filter.matches(customer)
}
}

@Test
fun `test nested field matches`() {
val customer = Customer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Junction;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.*;
import studio.crud.crudframework.jpa.annotation.CrudJoinType;
import studio.crud.crudframework.model.BaseCrudEntity;
import studio.crud.crudframework.model.PersistentEntity;
import studio.crud.crudframework.modelfilter.DynamicModelFilter;
import studio.crud.crudframework.modelfilter.FilterField;
import studio.crud.crudframework.modelfilter.JpaRawJunctionDTO;
import studio.crud.crudframework.modelfilter.OrderDTO;
import studio.crud.crudframework.modelfilter.enums.FilterFieldOperation;

Expand All @@ -25,12 +16,7 @@
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public abstract class AbstractBaseDao implements BaseDao {

Expand Down Expand Up @@ -180,11 +166,6 @@ private void flattenFilterFieldNames(Set<String> flatFilterFieldNames, List<Filt
if(filterField.getFieldName() != null) {
flatFilterFieldNames.add(filterField.getFieldName());
}

if(filterField.getOperation() == FilterFieldOperation.RawJunction && filterField.getValue1() instanceof JpaRawJunctionDTO) {
flatFilterFieldNames.addAll(((JpaRawJunctionDTO) filterField.getValue1()).getRequestedAliases());
}

if(filterField.getChildren() != null && !filterField.getChildren().isEmpty()) {
flattenFilterFieldNames(flatFilterFieldNames, filterField.getChildren());
}
Expand All @@ -195,7 +176,7 @@ private Criterion buildCriterion(FilterField filterField) {

Junction junction = Restrictions.and();

if((filterField.getOperation() == FilterFieldOperation.RawJunction || filterField.getOperation() == FilterFieldOperation.Noop) || filterField.getChildren() != null || isValidSimpleFilterField(filterField)) {
if(filterField.getOperation() == FilterFieldOperation.Noop || filterField.getChildren() != null || isValidSimpleFilterField(filterField)) {

switch(filterField.getOperation()) {
case Equal:
Expand Down Expand Up @@ -297,13 +278,6 @@ private Criterion buildCriterion(FilterField filterField) {
}
junction.add(Restrictions.not(notContainsInJunction));
break;

case RawJunction:
JpaRawJunctionDTO dto = (JpaRawJunctionDTO) filterField.getValue1();
if(dto != null && dto.getJunction() != null) {
junction.add(dto.getJunction());
}
break;
case Noop:
junction.add(Restrictions.sqlRestriction("1=0"));
break;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
import studio.crud.crudframework.modelfilter.FilterField;
import studio.crud.crudframework.modelfilter.OrderDTO;
import studio.crud.crudframework.modelfilter.enums.FilterFieldOperation;
import studio.crud.crudframework.mongo.modelfilter.MongoRawJunctionDTO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.regex.Pattern;

public abstract class AbstractMongoBaseDao {
Expand Down Expand Up @@ -110,7 +105,7 @@ protected Query buildQuery(DynamicModelFilter filter) {


private Criteria buildCriterion(Criteria criteria, FilterField filterField) {
if(filterField.getOperation() == FilterFieldOperation.RawJunction || filterField.getChildren() != null || isValidSimpleFilterField(filterField)) {
if(filterField.getChildren() != null || isValidSimpleFilterField(filterField)) {

switch(filterField.getOperation()) {
case Equal:
Expand Down Expand Up @@ -225,13 +220,6 @@ private Criteria buildCriterion(Criteria criteria, FilterField filterField) {
criteria.not().andOperator(criterias.toArray(new Criteria[]{}));
}
break;

case RawJunction:
MongoRawJunctionDTO dto = (MongoRawJunctionDTO) filterField.getValue1();
if(dto != null && dto.getJunction() != null) {
criteria.andOperator(dto.getJunction());
}
break;
case Noop:
criteria.and("id").in();
}
Expand Down

This file was deleted.

0 comments on commit 7d39e5e

Please sign in to comment.