Skip to content

Commit

Permalink
Case insensitive filtering and restrict the limit violation enum valu…
Browse files Browse the repository at this point in the history
…es. (#51)

Signed-off-by: Florent MILLOT <millotflo@gmail.com>
  • Loading branch information
flomillot authored Nov 3, 2023
1 parent a25c0f1 commit 9325a15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public ResponseEntity<FaultType[]> getFaultTypes() {
@GetMapping(value = "/limit-violation-types", produces = APPLICATION_JSON_VALUE)
@Operation(summary = "Get list of limit violation types")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of limit violation types")})
public ResponseEntity<LimitViolationType[]> getLimitTypes() {
return ResponseEntity.ok().body(LimitViolationType.values());
public ResponseEntity<List<LimitViolationType>> getLimitTypes() {
return ResponseEntity.ok().body(List.of(LimitViolationType.LOW_SHORT_CIRCUIT_CURRENT, LimitViolationType.HIGH_SHORT_CIRCUIT_CURRENT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ private SpecificationUtils() {

// we use .as(String.class) to be able to works on enum fields
public static <X> Specification<X> equals(String field, String value) {
return (root, cq, cb) -> cb.equal(getColumnPath(root, field).as(String.class), value);
return (root, cq, cb) -> cb.equal(cb.upper(getColumnPath(root, field)).as(String.class), value.toUpperCase());
}

public static <X> Specification<X> contains(String field, String value) {
return (root, cq, cb) -> cb.like(getColumnPath(root, field), "%" + EscapeCharacter.DEFAULT.escape(value) + "%", EscapeCharacter.DEFAULT.getEscapeCharacter());
return (root, cq, cb) -> cb.like(cb.upper(getColumnPath(root, field)), "%" + EscapeCharacter.DEFAULT.escape(value).toUpperCase() + "%", EscapeCharacter.DEFAULT.getEscapeCharacter());
}

public static <X> Specification<X> startsWith(String field, String value) {
return (root, cq, cb) -> cb.like(getColumnPath(root, field), EscapeCharacter.DEFAULT.escape(value) + "%", EscapeCharacter.DEFAULT.getEscapeCharacter());
return (root, cq, cb) -> cb.like(cb.upper(getColumnPath(root, field)), EscapeCharacter.DEFAULT.escape(value).toUpperCase() + "%", EscapeCharacter.DEFAULT.getEscapeCharacter());
}

public static <X> Specification<X> notEqual(String field, Double value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ private Stream<Arguments> provideContainsFilters() {
resultMagnitudeEntity,
List.of(
new ResourceFilter(ResourceFilter.DataType.TEXT, ResourceFilter.Type.CONTAINS, "_D_1", "connectableId")),
List.of())
List.of()),
// case insensitive
Arguments.of(
resultMagnitudeEntity,
List.of(
new ResourceFilter(ResourceFilter.DataType.TEXT, ResourceFilter.Type.CONTAINS, "id_2", "connectableId")),
List.of(feederResultEntity2))
);
}

Expand All @@ -195,7 +201,13 @@ private Stream<Arguments> provideStartsWithFilters() {
List.of(
new ResourceFilter(ResourceFilter.DataType.TEXT, ResourceFilter.Type.STARTS_WITH, "A_CONN", "connectableId"),
new ResourceFilter(ResourceFilter.DataType.TEXT, ResourceFilter.Type.STARTS_WITH, "B_CONN", "connectableId")),
List.of())
List.of()),
// case insensitive
Arguments.of(
resultMagnitudeEntity,
List.of(
new ResourceFilter(ResourceFilter.DataType.TEXT, ResourceFilter.Type.STARTS_WITH, "a_conn", "connectableId")),
List.of(feederResultEntity1, feederResultEntity2))
);
}

Expand Down

0 comments on commit 9325a15

Please sign in to comment.