Added further tests for target searches including the various filter options that we provide

This commit is contained in:
Kai Zimmermann
2016-03-26 16:13:58 +01:00
parent cc8a62d1d4
commit 0cc7284f6f
9 changed files with 747 additions and 183 deletions

View File

@@ -55,7 +55,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
* @return the assignedTargets
*/
public List<Target> getAssignedTargets() {
return targetManagement.findTargetsByControllerID(assignedTargets);
return targetManagement.findTargetByControllerID(assignedTargets);
}
/**

View File

@@ -53,7 +53,6 @@ import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
@@ -155,7 +154,7 @@ public class TargetManagement {
* @return List of found{@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<Target> findTargetsByControllerID(@NotEmpty final Collection<String> controllerIDs) {
public List<Target> findTargetByControllerID(@NotEmpty final Collection<String> controllerIDs) {
return targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs));
}
@@ -331,10 +330,10 @@ public class TargetManagement {
}
/**
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
* Retrieves {@link Target}s by the assigned {@link DistributionSet} without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible including the filtering based
* on the given {@code spec}.
* {@link Target#getActiveActions()} possible including additional filtering
* based on the given {@code spec}.
*
* @param distributionSetID
* the ID of the {@link DistributionSet}
@@ -374,7 +373,8 @@ public class TargetManagement {
/**
* retrieves {@link Target}s by the installed {@link DistributionSet}without
* details, i.e. NO {@link Target#getTags()} and
* {@link Target#getActiveActions()} possible.
* {@link Target#getActiveActions()} possible including additional filtering
* based on the given {@code spec}.
*
* @param distributionSetId
* the ID of the {@link DistributionSet}
@@ -490,7 +490,7 @@ public class TargetManagement {
if (!Strings.isNullOrEmpty(searchText)) {
specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(searchText));
}
if (selectTargetWithNoTag || (tagNames != null && tagNames.length > 0)) {
if (selectTargetWithNoTag != null && (selectTargetWithNoTag || (tagNames != null && tagNames.length > 0))) {
specList.add(TargetSpecifications.hasTags(tagNames, selectTargetWithNoTag));
}
return specList;
@@ -810,14 +810,12 @@ public class TargetManagement {
}
/**
* finds all {@link Target#getControllerId()} for all the given parameters.
* Finds all targets for all the given parameters but returns not the full
* target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
* @param filterByDistributionId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
*
* @param filterByStatus
* find targets having this {@link TargetUpdateStatus}s. Set to
* <code>null</code> in case this is not required.
@@ -825,28 +823,38 @@ public class TargetManagement {
* to find targets having the text anywhere in name or
* description. Set <code>null</code> in case this is not
* required.
* @param installedOrAssignedDistributionSetId
* to find targets having the {@link DistributionSet} as
* installed or assigned. Set to <code>null</code> in case this
* is not required.
* @param filterByTagNames
* to find targets which are having any one in this tag names.
* Set <code>null</code> in case this is not required.
* @param selectTargetWithNoTag
* flag to select targets with no tag assigned
*
* @return the found {@link Target}s
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<TargetIdName> findAllTargetIdsByFilters(final PageRequest pageRequest,
final Long filterByDistributionId, final Collection<TargetUpdateStatus> filterByStatus,
final String filterBySearchText, final Boolean selectTargetWithNoTag, final String... filterByTagNames) {
public List<TargetIdName> findAllTargetIdsByFilters(@NotNull final Pageable pageRequest,
final Collection<TargetUpdateStatus> filterByStatus, final String filterBySearchText,
final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag,
final String... filterByTagNames) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
final Root<Target> targetRoot = query.from(Target.class);
List<Object[]> resultList;
String sortProperty = Target_.id.getName();
if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) {
sortProperty = pageRequest.getSort().iterator().next().getProperty();
}
final CriteriaQuery<Object[]> multiselect = query.multiselect(targetRoot.get(Target_.id),
targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name),
targetRoot.get(pageRequest.getSort().iterator().next().getProperty()));
targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty));
final Predicate[] specificationsForMultiSelect = specificationsToPredicate(
buildSpecificationList(filterByStatus, filterBySearchText, filterByDistributionId,
buildSpecificationList(filterByStatus, filterBySearchText, installedOrAssignedDistributionSetId,
selectTargetWithNoTag, false, filterByTagNames),
targetRoot, multiselect, cb);
@@ -862,24 +870,29 @@ public class TargetManagement {
}
/**
* Finds all {@link Target#getControllerId()} for all the given parameter
* {@link TargetFilterQuery}.
* Finds all targets for all the given parameter {@link TargetFilterQuery}
* and returns not the full target but {@link TargetIdName}.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
* @param targetFilterQuery
* {@link TargetFilterQuery}
* @return the found {@link Target}s
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
public List<TargetIdName> findAllTargetIdsByTargetFilterQuery(final PageRequest pageRequest,
public List<TargetIdName> findAllTargetIdsByTargetFilterQuery(final Pageable pageRequest,
@NotNull final TargetFilterQuery targetFilterQuery) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
final Root<Target> targetRoot = query.from(Target.class);
String sortProperty = Target_.id.getName();
if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) {
sortProperty = pageRequest.getSort().iterator().next().getProperty();
}
final CriteriaQuery<Object[]> multiselect = query.multiselect(targetRoot.get(Target_.id),
targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name),
targetRoot.get(pageRequest.getSort().iterator().next().getProperty()));
targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty));
final Specification<Target> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
final List<Specification<Target>> specList = new ArrayList<>();
@@ -1072,7 +1085,7 @@ public class TargetManagement {
return targetRepository.count(specs);
}
private List<Object[]> getTargetIdNameResultSet(final PageRequest pageRequest, final CriteriaBuilder cb,
private List<Object[]> getTargetIdNameResultSet(final Pageable pageRequest, final CriteriaBuilder cb,
final Root<Target> targetRoot, final CriteriaQuery<Object[]> multiselect) {
List<Object[]> resultList;
if (pageRequest.getSort() != null) {

View File

@@ -15,18 +15,14 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
*
* Stored target filter.
*
*/
@Entity
@Table(name = "sp_target_filter_query", indexes = {
@Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "tenant" }, name = "uk_tenant_custom_filter_name") )
"name", "tenant" }, name = "uk_tenant_custom_filter_name"))
public class TargetFilterQuery extends TenantAwareBaseEntity {
/**
*
*
*/
private static final long serialVersionUID = 7493966984413479089L;
@Column(name = "name", length = 64)
@@ -36,8 +32,7 @@ public class TargetFilterQuery extends TenantAwareBaseEntity {
private String query;
public TargetFilterQuery() {
name = null;
query = null;
// Default constructor for JPA.
}
public TargetFilterQuery(final String name, final String query) {
@@ -45,32 +40,18 @@ public class TargetFilterQuery extends TenantAwareBaseEntity {
this.query = query;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(final String name) {
this.name = name;
}
/**
* @return the query
*/
public String getQuery() {
return query;
}
/**
* @param query
* the query to set
*/
public void setQuery(final String query) {
this.query = query;
}

View File

@@ -13,19 +13,12 @@ import java.io.Serializable;
/**
* ID class of the {@link Target} which contains the
* {@link Target#getControllerId()} and the {@link Target#getName()} in one
* object. Often it's necessary to remeber the IDs of the {@link Target} and the
* resolve for e.g. the UI the name of the target, this is very costly
* object. Often it's necessary to remember the IDs of the {@link Target} and
* the resolve for e.g. the UI the name of the target, this is very costly
* operation, so it's much better if the ID and the name of the {@link Target}
* is already in memory available.
*
*
*
*
*/
public class TargetIdName implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private final long targetId;