Skip to content

Commit

Permalink
Merge pull request #2 from Ouest-France/1-improve-querydsl-to-allow-l…
Browse files Browse the repository at this point in the history
…ogical-operand

feat(logical-operators): add logical operators on single and multiple…
  • Loading branch information
arnaud-thorel-of authored Dec 3, 2023
2 parents 58d939a + cc2c545 commit 53b6c48
Show file tree
Hide file tree
Showing 22 changed files with 445 additions and 181 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check Feature

on:
push:
branches-ignore: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build
run: mvn -ntp -B package --file pom.xml
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ To achieve the transformations between annotation based and concrete source, you
```java
package postgrest.mappers;

import fr.ouestfrance.querydsl.model.FilterFieldInfoModel;
import fr.ouestfrance.querydsl.service.ext.Mapper;
import fr.ouestfrance.querydsl.FilterOperation;

Expand All @@ -103,7 +102,9 @@ public class EqualsMapper implements Mapper<String> {
// Will transform model to queryString "$key=eq.value" => example : service=eq.CIA
}

public FilterOperation getOperation(){ return FilterOperation.EQ; }
public FilterOperation getOperation() {
return FilterOperation.EQ;
}
}
```

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/FilterField.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@
* @return <code>true</code> is should handle null, otherwise <code>false</code>
*/
boolean orNull() default false;
/**
* Group the filter in "or group" every filter with "orGroup" will be joined together
* @return group name
*/
String groupName() default "";
}
10 changes: 9 additions & 1 deletion src/main/java/fr/ouestfrance/querydsl/FilterFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@

/**
* List of filterField, using value allow to avoid attribute name
* @return list of filterField
*
* @return filter fields
*/
FilterField[] value() default {};

/**
* Group the filter in "or group" every filter with "orGroup" will be joined together
*
* @return group name
*/
String groupName() default "";
}
15 changes: 15 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/model/FieldMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fr.ouestfrance.querydsl.model;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

/**
* FieldInformation class represent metadata on declared field in a class
*
* @param name Name of the field
* @param type Return declared type of the field
* @param getter Getter method to access data
*/
public record FieldMetadata(String name, Type type, Method getter) {

}
8 changes: 8 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/model/Filter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fr.ouestfrance.querydsl.model;

/**
* Filter interface
* The filter can be SimpleFilter or GroupFilter
*/
public interface Filter {
}

This file was deleted.

35 changes: 0 additions & 35 deletions src/main/java/fr/ouestfrance/querydsl/model/FilterFieldModel.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/model/GroupFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.ouestfrance.querydsl.model;

import java.util.List;

/**
* Group filter allow to create a filter with logical operand and sub filters
* @param name of the group
* @param filters list of filters in the group
* @param operand logical operator to apply
*/
public record GroupFilter(String name, List<Filter> filters, Operand operand) implements Filter {

/**
* Operand types
*/
public enum Operand {
/**
* OR Operand
*/
OR,
/**
* AND Operand
*/
AND
}
}
14 changes: 14 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/model/SimpleFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.ouestfrance.querydsl.model;

import fr.ouestfrance.querydsl.FilterOperation;

/**
* FilterFieldInfoModel allow to store object representation of FilterField Annotation
* @param key key of the criteria
* @param operation operator to apply
* @param orNull allow the field to be null
* @param metadata metadata of the field representing type, method accessor and field name
*/
public record SimpleFilter(String key, FilterOperation operation, boolean orNull,
FieldMetadata metadata) implements Filter {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.ouestfrance.querydsl.service;

import fr.ouestfrance.querydsl.model.FilterFieldModel;
import fr.ouestfrance.querydsl.model.Filter;
import fr.ouestfrance.querydsl.service.scanner.FilterFieldAnnotationScanner;

import java.util.List;
Expand All @@ -16,7 +16,7 @@ public class FilterFieldAnnotationProcessorService {
/**
* Cache of models
*/
private static final Map<Class<?>, List<FilterFieldModel>> CACHE = new ConcurrentHashMap<>();
private static final Map<Class<?>, List<Filter>> CACHE = new ConcurrentHashMap<>();
/**
* Annotation scanner
*/
Expand All @@ -28,7 +28,7 @@ public class FilterFieldAnnotationProcessorService {
* @param clazz clazz to handle
* @return List of filterFieldModel
*/
public List<FilterFieldModel> process(Class<?> clazz) {
public List<Filter> process(Class<?> clazz) {
return CACHE.computeIfAbsent(clazz, x -> scanner.scan(clazz));
}
}
4 changes: 2 additions & 2 deletions src/main/java/fr/ouestfrance/querydsl/service/ext/Mapper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.ouestfrance.querydsl.service.ext;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.model.FilterFieldInfoModel;
import fr.ouestfrance.querydsl.model.SimpleFilter;

/**
* Interface that allow to transform operation to concrete filter objet depending on the connector source
Expand Down Expand Up @@ -33,7 +33,7 @@ public interface Mapper<T> {
* @param data value data to apply to filter
* @return criteria representation
*/
T map(FilterFieldInfoModel filterField, Object data);
T map(SimpleFilter filterField, Object data);

/**
* type of the operation handled by the mapper
Expand Down
Loading

0 comments on commit 53b6c48

Please sign in to comment.