Skip to content

Commit

Permalink
Cleanup and adjusted jacoco-exclusion- (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfloe authored Sep 2, 2024
1 parent 874385a commit a885ece
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 67 deletions.
2 changes: 2 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
<exclude>de/uftos/repositories/ucdl/parser/javacc/*</exclude>
<exclude>de/uftos/entities/*</exclude>
<exclude>de/uftos/controller/*</exclude>
<exclude>de/uftos/config/*</exclude>
<exclude>de/uftos/*</exclude>
</excludes>
</configuration>
<executions>
Expand Down
71 changes: 4 additions & 67 deletions server/src/main/java/de/uftos/utils/SpecificationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Specification<T> build() {
*
* @param text The text to search for
* @return The current instance of {@code SpecificationBuilder} with the
* search filter added if the parameter is present.
* search filter added if the parameter is present.
*/
public SpecificationBuilder<T> search(Optional<String> text) {
if (text.isEmpty()) {
Expand All @@ -63,7 +63,7 @@ public SpecificationBuilder<T> search(Optional<String> text) {
* @param param The optional parameter value to filter by.
* @param paramName The name of the parameter to filter on.
* @return The current instance of {@code SpecificationBuilder} with the
* OR filter added if the parameter is present.
* OR filter added if the parameter is present.
*/
public SpecificationBuilder<T> optionalOrLike(Optional<String> param, String paramName) {
if (param.isEmpty()) {
Expand All @@ -76,23 +76,6 @@ public SpecificationBuilder<T> optionalOrLike(Optional<String> param, String par
return this;
}

/**
* Adds an AND filter to the specification that checks whether the parameter
* is present in the array.
*
* @param param The parameter value to filter by.
* @param paramName The name of the parameter to filter on.
* @return The current instance of {@code SpecificationBuilder} with the
* AND filter added if the parameter is present.
*/
public SpecificationBuilder<T> andIn(String[] param, String paramName) {
specification =
specification.and(
(root, query, cb) -> root.get(paramName).in(Arrays.stream(param).toList())
);
return this;
}

/**
* Adds a filter to the specification by joining with another relation if the
* provided attribute value array is present.
Expand All @@ -101,7 +84,7 @@ public SpecificationBuilder<T> andIn(String[] param, String paramName) {
* @param relationName The name of the relation to join.
* @param attributeName The name of the attribute in the joined relation to filter on.
* @return The current instance of {@code SpecificationBuilder} with the join filter
* added if the attribute value array is present.
* added if the attribute value array is present.
*/
public SpecificationBuilder<T> optionalAndJoinIn(Optional<String[]> attributeValue,
String relationName, String attributeName) {
Expand All @@ -125,7 +108,7 @@ public SpecificationBuilder<T> optionalAndJoinIn(Optional<String[]> attributeVal
* @param secondRelationName The name of the second relation to join.
* @param attributeName The name of the attribute in the joined relation to filter on.
* @return The current instance of {@code SpecificationBuilder} with the join filter
* added if the attribute value array is present.
* added if the attribute value array is present.
*/
public SpecificationBuilder<T> andDoubleJoinIn(String[] attributeValue, String firstRelationName,
String secondRelationName, String attributeName) {
Expand All @@ -139,52 +122,6 @@ public SpecificationBuilder<T> andDoubleJoinIn(String[] attributeValue, String f
return this;
}

/**
* Adds a filter to the specification by joining with another relation if the
* provided attribute value array is present and checking whether the given attribute
* has a similar value to the wanted one.
*
* @param attributeValue The optional attribute value to filter by.
* @param relationName The name of the relation to join.
* @param attributeName The name of the attribute in the joined relation to filter on.
* @return The current instance of {@code SpecificationBuilder} with the join filter
* added if the attribute value is present.
*/
public SpecificationBuilder<T> optionalAndJoinLikeIgnoreCase(Optional<String> attributeValue,
String relationName,
String attributeName) {
if (attributeValue.isEmpty()) {
return this;
}
specification = specification.and(
(root, query, cb) -> likeIgnoreCase(cb, root.join(relationName).get(attributeName),
attributeValue.get())
);
return this;
}

/**
* Adds a filter to the specification by joining with another relation if the
* provided attribute value array is present and checking whether the given attribute
* has the exact same value as the wanted one.
*
* @param attributeValue The optional attribute value to filter by.
* @param relationName The name of the relation to join.
* @param attributeName The name of the attribute in the joined relation to filter on.
* @return The current instance of {@code SpecificationBuilder} with the join filter
* added if the attribute value is present.
*/
public SpecificationBuilder<T> andJoinEquals(String attributeValue,
String relationName, String attributeName) {
if (attributeValue.isEmpty()) {
return this;
}
specification = specification.and(
(root, query, cb) -> cb.equal(root.join(relationName).get(attributeName), attributeValue)
);
return this;
}

private Predicate likeIgnoreCase(CriteriaBuilder cb, Expression<String> value, String pattern) {
return cb.like(cb.lower(value), "%" + pattern.toLowerCase() + "%");
}
Expand Down

0 comments on commit a885ece

Please sign in to comment.