Fixed sanitizing of filter query sort parameters. Corrected name of TargetManagement method
Signed-off-by: Dominik Herbst <dominik.herbst@bosch-si.com>
This commit is contained in:
@@ -240,7 +240,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
|||||||
|
|
||||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||||
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
|
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
|
||||||
|
|
||||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||||
final Page<TargetFilterQuery> targetFilterQueries;
|
final Page<TargetFilterQuery> targetFilterQueries;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
|||||||
|
|
||||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||||
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
|
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
|
||||||
|
|
||||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||||
final Slice<TargetFilterQuery> findTargetFiltersAll;
|
final Slice<TargetFilterQuery> findTargetFiltersAll;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
|||||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||||
import org.eclipse.hawkbit.repository.TargetFields;
|
import org.eclipse.hawkbit.repository.TargetFields;
|
||||||
|
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
|
||||||
import org.eclipse.hawkbit.rest.util.SortUtility;
|
import org.eclipse.hawkbit.rest.util.SortUtility;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.domain.Sort.Direction;
|
import org.springframework.data.domain.Sort.Direction;
|
||||||
@@ -59,6 +60,14 @@ public final class PagingUtility {
|
|||||||
return new Sort(SortUtility.parse(TargetFields.class, sortParam));
|
return new Sort(SortUtility.parse(TargetFields.class, sortParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Sort sanitizeTargetFilterQuerySortParam(final String sortParam) {
|
||||||
|
if (sortParam == null) {
|
||||||
|
// default
|
||||||
|
return new Sort(Direction.ASC, TargetFilterQueryFields.NAME.getFieldName());
|
||||||
|
}
|
||||||
|
return new Sort(SortUtility.parse(TargetFilterQueryFields.class, sortParam));
|
||||||
|
}
|
||||||
|
|
||||||
static Sort sanitizeSoftwareModuleSortParam(final String sortParam) {
|
static Sort sanitizeSoftwareModuleSortParam(final String sortParam) {
|
||||||
if (sortParam == null) {
|
if (sortParam == null) {
|
||||||
// default
|
// default
|
||||||
|
|||||||
@@ -244,32 +244,34 @@ public interface TargetManagement {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all targets for all the given parameter {@link TargetFilterQuery}
|
* Finds all targets for all the given parameter {@link TargetFilterQuery}
|
||||||
* and that don't have the specified assigned distribution set.
|
* and that don't have the specified distribution set in their action
|
||||||
* and returns not the full target but {@link TargetIdName}.
|
* history.
|
||||||
*
|
*
|
||||||
* @param pageRequest
|
* @param pageRequest
|
||||||
* the pageRequest to enhance the query for paging and sorting
|
* the pageRequest to enhance the query for paging and sorting
|
||||||
|
* @param distributionSetId
|
||||||
|
* id of the {@link DistributionSet}
|
||||||
* @param targetFilterQuery
|
* @param targetFilterQuery
|
||||||
* {@link TargetFilterQuery}
|
* {@link TargetFilterQuery}
|
||||||
* @return the found {@link TargetIdName}s
|
* @return the found {@link TargetIdName}s
|
||||||
*/
|
*/
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||||
Page<Target> findAllTargetIdsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
|
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, Long distributionSetId,
|
||||||
Long distributionSetId,
|
@NotNull TargetFilterQuery targetFilterQuery);
|
||||||
@NotNull TargetFilterQuery targetFilterQuery);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts all targets for all the given parameter {@link TargetFilterQuery}
|
* Counts all targets for all the given parameter {@link TargetFilterQuery}
|
||||||
* and that don't have the specified assigned distribution set. and returns
|
* and that don't have the specified distribution set in their action
|
||||||
* not the full target but {@link TargetIdName}.
|
* history.
|
||||||
*
|
*
|
||||||
|
* @param distributionSetId
|
||||||
|
* id of the {@link DistributionSet}
|
||||||
* @param targetFilterQuery
|
* @param targetFilterQuery
|
||||||
* {@link TargetFilterQuery}
|
* {@link TargetFilterQuery}
|
||||||
* @return the found {@link TargetIdName}s
|
* @return the found {@link TargetIdName}s
|
||||||
*/
|
*/
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||||
Long countTargetByTargetFilterQueryAndNonDS(Long distributionSetId,
|
Long countTargetsByTargetFilterQueryAndNonDS(Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery);
|
||||||
@NotNull TargetFilterQuery targetFilterQuery);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
|
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
|
||||||
|
|||||||
@@ -563,8 +563,8 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<Target> findAllTargetIdsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
|
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
|
||||||
Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
|
Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
|
||||||
|
|
||||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
|
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
|
||||||
|
|
||||||
@@ -577,7 +577,7 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long countTargetByTargetFilterQueryAndNonDS(Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
|
public Long countTargetsByTargetFilterQueryAndNonDS(Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
|
||||||
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
|
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
|
||||||
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
||||||
specList.add(spec);
|
specList.add(spec);
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class AutoAssignChecker {
|
|||||||
* @return list of targets with action type
|
* @return list of targets with action type
|
||||||
*/
|
*/
|
||||||
private List<TargetWithActionType> getTargetsWithActionType(TargetFilterQuery targetFilterQuery, Long dsId, int count) {
|
private List<TargetWithActionType> getTargetsWithActionType(TargetFilterQuery targetFilterQuery, Long dsId, int count) {
|
||||||
Page<Target> targets = targetManagement.findAllTargetIdsByTargetFilterQueryAndNonDS(new PageRequest(0, count),
|
Page<Target> targets = targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(new PageRequest(0, count),
|
||||||
dsId, targetFilterQuery);
|
dsId, targetFilterQuery);
|
||||||
|
|
||||||
return targets.getContent().stream()
|
return targets.getContent().stream()
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
|||||||
import org.eclipse.hawkbit.repository.model.*;
|
import org.eclipse.hawkbit.repository.model.*;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Slice;
|
import org.springframework.data.domain.Slice;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -733,7 +732,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
deploymentManagement.assignDistributionSet(assignedSet, assignedTargets);
|
deploymentManagement.assignDistributionSet(assignedSet, assignedTargets);
|
||||||
|
|
||||||
List<Target> result = targetManagement.findAllTargetIdsByTargetFilterQueryAndNonDS(pageReq,
|
List<Target> result = targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq,
|
||||||
assignedSet.getId(), tfq).getContent();
|
assignedSet.getId(), tfq).getContent();
|
||||||
assertThat(result)
|
assertThat(result)
|
||||||
.as("count of targets").hasSize(unassignedTargets.size())
|
.as("count of targets").hasSize(unassignedTargets.size())
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
|||||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount);
|
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount);
|
||||||
|
|
||||||
// Count the number of targets that will be assigned with setA
|
// Count the number of targets that will be assigned with setA
|
||||||
assertThat(targetManagement.countTargetByTargetFilterQueryAndNonDS(setA.getId(), targetFilterQuery))
|
assertThat(targetManagement.countTargetsByTargetFilterQueryAndNonDS(setA.getId(), targetFilterQuery))
|
||||||
.isEqualTo(90);
|
.isEqualTo(90);
|
||||||
|
|
||||||
// Run the check
|
// Run the check
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ public class DistributionSetSelectWindow
|
|||||||
layout.setMargin(true);
|
layout.setMargin(true);
|
||||||
setContent(layout);
|
setContent(layout);
|
||||||
|
|
||||||
Long targetsCount = targetManagement.countTargetByTargetFilterQueryAndNonDS(distributionSetId, targetFilterQuery);
|
Long targetsCount = targetManagement.countTargetsByTargetFilterQueryAndNonDS(distributionSetId, targetFilterQuery);
|
||||||
Label mainTextLabel;
|
Label mainTextLabel;
|
||||||
if(targetsCount == 0) {
|
if(targetsCount == 0) {
|
||||||
mainTextLabel = new Label(i18n.get("message.confirm.assign.consequences.none"));
|
mainTextLabel = new Label(i18n.get("message.confirm.assign.consequences.none"));
|
||||||
|
|||||||
Reference in New Issue
Block a user