Skip to content

Commit

Permalink
Mod. to extractAttribute method
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnul97 authored and Coduz committed Dec 13, 2022
1 parent ea84920 commit 0d478c0
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -828,21 +828,26 @@ private static <E> Predicate handleAttributePredicate(@NonNull AttributePredicat
}

/**
* Utility method that selects the correct {@link Root} attribute.<br>
* This method handles {@link Embedded} attributes and nested {@link KapuaEntity}es up to one level of nesting<br>
* Utility method that selects the correct {@link Root} attribute.
* <p>
* This method handles {@link Embedded} attributes and nested {@link KapuaEntity}es.
* <p>
* Filter predicates takes advantage of the dot notation to access {@link Embedded} attributes and nested {@link KapuaEntity}es.
*
* @param entityRoot The {@link Root} entity from which extract the attribute.
* @param attributeName The full attribute name. It can contain at maximum one '.' separator.
* @param attributeName The full attribute name.
* @return The {@link Path} expression that matches the given {@code attributeName} parameter.
* @since 1.0.0
*/
private static <E, P> Path<P> extractAttribute(@NonNull Root<E> entityRoot, @NonNull String attributeName) {

Path<P> expressionPath;
Path<P> expressionPath = null;
if (attributeName.contains(ATTRIBUTE_SEPARATOR)) {
expressionPath = entityRoot.get(attributeName.split(ATTRIBUTE_SEPARATOR_ESCAPED)[0]).get(attributeName.split(ATTRIBUTE_SEPARATOR_ESCAPED)[1]);
String[] pathComponents = attributeName.split(ATTRIBUTE_SEPARATOR_ESCAPED);
Path<P> rootPath = entityRoot.get(pathComponents[0]);
for (int i = 1; i < pathComponents.length; i++) {
expressionPath = rootPath.get(pathComponents[i]);
rootPath = expressionPath;
}
} else {
expressionPath = entityRoot.get(attributeName);
}
Expand Down

0 comments on commit 0d478c0

Please sign in to comment.