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:
Dominik Herbst
2016-10-04 11:57:56 +02:00
parent f481e097db
commit 339f45ca6a
9 changed files with 29 additions and 19 deletions

View File

@@ -240,7 +240,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
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 Page<TargetFilterQuery> targetFilterQueries;

View File

@@ -72,7 +72,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
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 Slice<TargetFilterQuery> findTargetFiltersAll;

View File

@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.repository.SoftwareModuleFields;
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
import org.eclipse.hawkbit.rest.util.SortUtility;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
@@ -59,6 +60,14 @@ public final class PagingUtility {
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) {
if (sortParam == null) {
// default

View File

@@ -244,32 +244,34 @@ public interface TargetManagement {
/**
* Finds all targets for all the given parameter {@link TargetFilterQuery}
* and that don't have the specified assigned distribution set.
* and returns not the full target but {@link TargetIdName}.
* and that don't have the specified distribution set in their action
* history.
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
* @param distributionSetId
* id of the {@link DistributionSet}
* @param targetFilterQuery
* {@link TargetFilterQuery}
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findAllTargetIdsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
Long distributionSetId,
@NotNull TargetFilterQuery targetFilterQuery);
Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, Long distributionSetId,
@NotNull TargetFilterQuery targetFilterQuery);
/**
* Counts all targets for all the given parameter {@link TargetFilterQuery}
* and that don't have the specified assigned distribution set. and returns
* not the full target but {@link TargetIdName}.
* and that don't have the specified distribution set in their action
* history.
*
* @param distributionSetId
* id of the {@link DistributionSet}
* @param targetFilterQuery
* {@link TargetFilterQuery}
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countTargetByTargetFilterQueryAndNonDS(Long distributionSetId,
@NotNull TargetFilterQuery targetFilterQuery);
Long countTargetsByTargetFilterQueryAndNonDS(Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery);
/**
* retrieves {@link Target}s by the assigned {@link DistributionSet} without

View File

@@ -563,8 +563,8 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findAllTargetIdsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest,
Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery) {
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class);
@@ -577,7 +577,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@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 List<Specification<JpaTarget>> specList = new ArrayList<>();
specList.add(spec);

View File

@@ -156,7 +156,7 @@ public class AutoAssignChecker {
* @return list of targets with action type
*/
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);
return targets.getContent().stream()

View File

@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.*;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.junit.Test;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import com.google.common.collect.Lists;
@@ -733,7 +732,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
deploymentManagement.assignDistributionSet(assignedSet, assignedTargets);
List<Target> result = targetManagement.findAllTargetIdsByTargetFilterQueryAndNonDS(pageReq,
List<Target> result = targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq,
assignedSet.getId(), tfq).getContent();
assertThat(result)
.as("count of targets").hasSize(unassignedTargets.size())

View File

@@ -73,7 +73,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount);
// 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);
// Run the check

View File

@@ -248,7 +248,7 @@ public class DistributionSetSelectWindow
layout.setMargin(true);
setContent(layout);
Long targetsCount = targetManagement.countTargetByTargetFilterQueryAndNonDS(distributionSetId, targetFilterQuery);
Long targetsCount = targetManagement.countTargetsByTargetFilterQueryAndNonDS(distributionSetId, targetFilterQuery);
Label mainTextLabel;
if(targetsCount == 0) {
mainTextLabel = new Label(i18n.get("message.confirm.assign.consequences.none"));