Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and adjusted jacoco-exclusion- #445

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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