Include attribute values in target search text filter (#736)

* Add specification for like attribute value

v2: ensure returned targets are unique
v3: remove redundant or

Signed-off-by: Stefan Schake <stefan.schake@devolo.de>

* Use like attribute value specification with target search text

Target attributes are the primary way to relay back metadata,
particularly in a plug&play application. They should therefore be
included in the target search. Attribute keys are excluded since they
are expected to be consistent between targets.

v3: remove whitespace changes

Signed-off-by: Stefan Schake <stefan.schake@devolo.de>

* Add test for target search includes attribute values

v2: test targets returned are unique

Signed-off-by: Stefan Schake <stefan.schake@devolo.de>
This commit is contained in:
Stefan Schake
2018-11-29 10:18:51 +01:00
committed by Stefan Behl
parent b2dfd4a99e
commit e9ddcefd4a
3 changed files with 59 additions and 1 deletions

View File

@@ -465,7 +465,7 @@ public class JpaTargetManagement implements TargetManagement {
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
}
if (!StringUtils.isEmpty(filterParams.getFilterBySearchText())) {
specList.add(TargetSpecifications.likeIdOrNameOrDescription(filterParams.getFilterBySearchText()));
specList.add(TargetSpecifications.likeIdOrNameOrDescriptionOrAttributeValue(filterParams.getFilterBySearchText()));
}
if (isHasTagsFilterActive(filterParams)) {
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),

View File

@@ -18,6 +18,7 @@ import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.SetJoin;
import javax.persistence.criteria.MapJoin;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
@@ -37,6 +38,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
/**
* Specifications class for {@link Target}s. The class provides Spring Data JPQL
@@ -148,6 +150,36 @@ public final class TargetSpecifications {
};
}
/**
* {@link Specification} for retrieving {@link Target}s by "like attribute
* value".
*
* @param searchText
* to be filtered on
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> likeAttributeValue(final String searchText) {
return (targetRoot, query, cb) -> {
final String searchTextToLower = searchText.toLowerCase();
final MapJoin<JpaTarget, String, String> attributeMap = targetRoot.join(JpaTarget_.controllerAttributes,
JoinType.LEFT);
query.distinct(true);
return cb.like(cb.lower(attributeMap.value()), searchTextToLower);
};
}
/**
* {@link Specification} for retrieving {@link Target}s by "like
* controllerId or like name or like description or like attribute value".
*
* @param searchText
* to be filtered on
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> likeIdOrNameOrDescriptionOrAttributeValue(final String searchText) {
return Specifications.where(likeIdOrNameOrDescription(searchText)).or(likeAttributeValue(searchText));
}
/**
* {@link Specification} for retrieving {@link Target}s by "like
* controllerId".