Hide getRolloutWithStatusDetails from API (#2442)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-06-10 11:50:45 +03:00
committed by GitHub
parent a7162a1e48
commit 6167dce214
18 changed files with 123 additions and 235 deletions

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.mgmt.rest.resource; package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE;
import static org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -32,7 +34,6 @@ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtDynamicRolloutGroupT
import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup; import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup;
import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody; import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate; import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate;
@@ -95,8 +96,8 @@ final class MgmtRolloutMapper {
if (withDetails) { if (withDetails) {
for (final TotalTargetCountStatus.Status status : TotalTargetCountStatus.Status.values()) { for (final TotalTargetCountStatus.Status status : TotalTargetCountStatus.Status.values()) {
body.addTotalTargetsPerStatus(status.name().toLowerCase(), body.addTotalTargetsPerStatus(
rollout.getTotalTargetCountStatus().getTotalTargetCountByStatus(status)); status.name().toLowerCase(), rollout.getTotalTargetCountStatus().getTotalTargetCountByStatus(status));
} }
body.setTotalGroups(rollout.getRolloutGroupsCreated()); body.setTotalGroups(rollout.getRolloutGroupsCreated());
body.setStartAt(rollout.getStartAt()); body.setStartAt(rollout.getStartAt());
@@ -107,20 +108,17 @@ final class MgmtRolloutMapper {
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).start(rollout.getId())).withRel("start").expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).start(rollout.getId())).withRel("start").expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).pause(rollout.getId())).withRel("pause").expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).pause(rollout.getId())).withRel("pause").expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).resume(rollout.getId())).withRel("resume").expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).resume(rollout.getId())).withRel("resume").expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).triggerNextGroup(rollout.getId())) body.add(linkTo(methodOn(MgmtRolloutRestApi.class).triggerNextGroup(rollout.getId())).withRel("triggerNextGroup").expand());
.withRel("triggerNextGroup").expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).approve(rollout.getId(), null)).withRel("approve").expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).approve(rollout.getId(), null)).withRel("approve")
.expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).deny(rollout.getId(), null)).withRel("deny").expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).deny(rollout.getId(), null)).withRel("deny").expand());
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRolloutGroups(rollout.getId(), body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRolloutGroups(
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, rollout.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null, null)).withRel("groups") REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null, null))
.expand()); .withRel("groups").expand());
final DistributionSet distributionSet = rollout.getDistributionSet(); final DistributionSet distributionSet = rollout.getDistributionSet();
body.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(distributionSet.getId())) body.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(distributionSet.getId()))
.withRel("distributionset").withName(distributionSet.getName() + ":" + distributionSet.getVersion()) .withRel("distributionset").withName(distributionSet.getName() + ":" + distributionSet.getVersion()).expand());
.expand());
} }
body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRollout(rollout.getId())).withSelfRel().expand()); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRollout(rollout.getId())).withSelfRel().expand());

View File

@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
@@ -48,7 +47,6 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.utils.TenantConfigHelper; import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -85,30 +83,23 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
public ResponseEntity<PagedList<MgmtRolloutResponseBody>> getRollouts( public ResponseEntity<PagedList<MgmtRolloutResponseBody>> getRollouts(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) { final String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeRolloutSortParam(sortParam);
final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL; final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL;
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Rollout> rollouts; final Page<Rollout> rollouts;
if (rsqlParam != null) {
rollouts = rolloutManagement.findByRsql(pageable, rsqlParam, false);
} else {
rollouts = rolloutManagement.findAll(pageable, false);
}
final long totalElements = rollouts.getTotalElements();
final List<MgmtRolloutResponseBody> rest; final List<MgmtRolloutResponseBody> rest;
if (isFullMode) { if (isFullMode) {
rest = MgmtRolloutMapper.toResponseRolloutWithDetails(rolloutManagement.getRolloutWithStatusDetails(rollouts).getContent()); rollouts = rsqlParam == null
? rolloutManagement.findAllWithDetailedStatus(pageable, false)
: rolloutManagement.findByRsqlWithDetailedStatus(pageable, rsqlParam, false);
rest = MgmtRolloutMapper.toResponseRolloutWithDetails(rollouts.getContent());
} else { } else {
rollouts = rsqlParam == null
? rolloutManagement.findAll(pageable, false)
: rolloutManagement.findByRsql(pageable, rsqlParam, false);
rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent()); rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent());
} }
return ResponseEntity.ok(new PagedList<>(rest, rollouts.getTotalElements()));
return ResponseEntity.ok(new PagedList<>(rest, totalElements));
} }
@Override @Override
@@ -214,28 +205,22 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Long rolloutId, final Long rolloutId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) { final String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeRolloutGroupSortParam(sortParam);
final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL; final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL;
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<RolloutGroup> rolloutGroups; final Page<RolloutGroup> rolloutGroups;
if (rsqlParam != null) { if (rsqlParam == null) {
if (isFullMode) {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsqlWithDetailedStatus(rolloutId, rsqlParam, pageable
);
} else {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsql(rolloutId, rsqlParam, pageable);
}
} else {
if (isFullMode) { if (isFullMode) {
rolloutGroups = this.rolloutGroupManagement.findByRolloutWithDetailedStatus(rolloutId, pageable); rolloutGroups = this.rolloutGroupManagement.findByRolloutWithDetailedStatus(rolloutId, pageable);
} else { } else {
rolloutGroups = this.rolloutGroupManagement.findByRollout(rolloutId, pageable); rolloutGroups = this.rolloutGroupManagement.findByRollout(rolloutId, pageable);
} }
} else {
if (isFullMode) {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsqlWithDetailedStatus(rolloutId, rsqlParam, pageable);
} else {
rolloutGroups = this.rolloutGroupManagement.findByRolloutAndRsql(rolloutId, rsqlParam, pageable);
}
} }
final List<MgmtRolloutGroupResponseBody> rest = MgmtRolloutMapper.toResponseRolloutGroup( final List<MgmtRolloutGroupResponseBody> rest = MgmtRolloutMapper.toResponseRolloutGroup(
@@ -249,7 +234,6 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId) final RolloutGroup rolloutGroup = rolloutGroupManagement.getWithDetailedStatus(groupId)
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutId)); .orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutId));
if (!Objects.equals(rolloutId, rolloutGroup.getRollout().getId())) { if (!Objects.equals(rolloutId, rolloutGroup.getRollout().getId())) {
throw new EntityNotFoundException(RolloutGroup.class, groupId); throw new EntityNotFoundException(RolloutGroup.class, groupId);
} }
@@ -263,19 +247,13 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Long rolloutId, final Long groupId, final Long rolloutId, final Long groupId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
findRolloutOrThrowException(rolloutId); findRolloutOrThrowException(rolloutId);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Target> rolloutGroupTargets; final Page<Target> rolloutGroupTargets;
if (rsqlParam != null) { if (rsqlParam == null) {
rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(pageable, groupId, rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(groupId, pageable);
rsqlParam);
} else { } else {
final Page<Target> pageTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(groupId, pageable); rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroupByRsql(pageable, groupId, rsqlParam);
rolloutGroupTargets = pageTargets;
} }
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent(), tenantConfigHelper); final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent(), tenantConfigHelper);
return ResponseEntity.ok(new PagedList<>(rest, rolloutGroupTargets.getTotalElements())); return ResponseEntity.ok(new PagedList<>(rest, rolloutGroupTargets.getTotalElements()));
@@ -284,15 +262,14 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@Override @Override
@AuditLog(entity = "Rollout", type = AuditLog.Type.UPDATE, description = "Trigger Next Rollout Group") @AuditLog(entity = "Rollout", type = AuditLog.Type.UPDATE, description = "Trigger Next Rollout Group")
public ResponseEntity<Void> triggerNextGroup(final Long rolloutId) { public ResponseEntity<Void> triggerNextGroup(final Long rolloutId) {
this.rolloutManagement.triggerNextGroup(rolloutId); rolloutManagement.triggerNextGroup(rolloutId);
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
@Override @Override
public ResponseEntity<MgmtRolloutResponseBody> retryRollout(final Long rolloutId) { public ResponseEntity<MgmtRolloutResponseBody> retryRollout(final Long rolloutId) {
final Rollout rolloutForRetry = this.rolloutManagement.get(rolloutId) final Rollout rolloutForRetry = rolloutManagement.get(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId)); .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
if (rolloutForRetry.isDeleted()) { if (rolloutForRetry.isDeleted()) {
throw new EntityNotFoundException(Rollout.class, rolloutId); throw new EntityNotFoundException(Rollout.class, rolloutId);
} }

View File

@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetFields;
import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.DistributionSetTypeFields;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutFields;
import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.RolloutGroupFields;
import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.SoftwareModuleFields;
@@ -24,6 +25,7 @@ import org.eclipse.hawkbit.repository.TagFields;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetFilterQueryFields; import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
import org.eclipse.hawkbit.repository.TargetTypeFields; import org.eclipse.hawkbit.repository.TargetTypeFields;
import org.springframework.data.domain.Pageable;
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;
@@ -146,4 +148,11 @@ public final class PagingUtility {
} }
return Sort.by(SortUtility.parse(RolloutGroupFields.class, sortParam)); return Sort.by(SortUtility.parse(RolloutGroupFields.class, sortParam));
} }
public static Pageable toPageable(final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final int sanitizedOffsetParam = sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = sanitizeRolloutSortParam(sortParam);
return new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
}
} }

View File

@@ -38,7 +38,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
import org.eclipse.hawkbit.repository.model.RolloutGroupsValidation; import org.eclipse.hawkbit.repository.model.RolloutGroupsValidation;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
/** /**
@@ -56,15 +55,6 @@ public interface RolloutManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
long count(); long count();
/**
* Count rollouts by given text in name or description.
*
* @param searchText name or description
* @return total count rollouts for specified filter text.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
long countByFilters(@NotEmpty String searchText);
/** /**
* Counts all {@link Rollout}s for a specific {@link DistributionSet} that * Counts all {@link Rollout}s for a specific {@link DistributionSet} that
* are stoppable * are stoppable
@@ -206,7 +196,7 @@ public interface RolloutManagement {
* statuses * statuses
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> findAllWithDetailedStatus(@NotNull Pageable pageable, boolean deleted); Page<Rollout> findAllWithDetailedStatus(@NotNull Pageable pageable, boolean deleted);
/** /**
* Retrieves all rollouts found by the given specification. * Retrieves all rollouts found by the given specification.
@@ -232,7 +222,7 @@ public interface RolloutManagement {
* not exists * not exists
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> findByFiltersWithDetailedStatus(@NotNull Pageable pageable, @NotEmpty String searchText, Page<Rollout> findByRsqlWithDetailedStatus(@NotNull Pageable pageable, @NotEmpty String searchText,
boolean deleted); boolean deleted);
/** /**
@@ -406,12 +396,4 @@ public interface RolloutManagement {
*/ */
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
void triggerNextGroup(long rolloutId); void triggerNextGroup(long rolloutId);
/**
* Enrich the rollouts Slice with additional details
*
* @param rollouts the rollouts to be enriched.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> getRolloutWithStatusDetails(final Slice<Rollout> rollouts);
} }

View File

@@ -36,14 +36,13 @@ import org.springframework.util.ObjectUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class JpaManagementHelper { public final class JpaManagementHelper {
public static <T, J extends T> Optional<J> findOneBySpec( public static <T, J extends T> Optional<J> findOneBySpec(
final JpaSpecificationExecutor<J> repository, final List<Specification<J>> specList) { final JpaSpecificationExecutor<J> repository, final List<Specification<J>> specList) {
return repository.findOne(combineWithAnd(specList)); return repository.findOne(combineWithAnd(specList));
} }
public static <T, J extends T> Page<T> findAllWithCountBySpec(final JpaSpecificationExecutor<J> repository, public static <T, J extends T> Page<T> findAllWithCountBySpec(
final List<Specification<J>> specList, final Pageable pageable) { final JpaSpecificationExecutor<J> repository, final List<Specification<J>> specList, final Pageable pageable) {
if (CollectionUtils.isEmpty(specList)) { if (CollectionUtils.isEmpty(specList)) {
return convertPage(repository.findAll(Specification.where(null), pageable), pageable); return convertPage(repository.findAll(Specification.where(null), pageable), pageable);
} }
@@ -62,21 +61,20 @@ public final class JpaManagementHelper {
return specList.size() == 1 ? specList.get(0) : SpecificationsBuilder.combineWithAnd(specList); return specList.size() == 1 ? specList.get(0) : SpecificationsBuilder.combineWithAnd(specList);
} }
public static <T, J extends T> Slice<T> findAllWithoutCountBySpec(final NoCountSliceRepository<J> repository, public static <T, J extends T> Slice<T> findAllWithoutCountBySpec(
final Pageable pageable, final List<Specification<J>> specList) { final NoCountSliceRepository<J> repository, final List<Specification<J>> specList, final Pageable pageable) {
if (CollectionUtils.isEmpty(specList)) { if (CollectionUtils.isEmpty(specList)) {
return convertPage(repository.findAllWithoutCount(pageable), pageable); return convertSlice(repository.findAllWithoutCount(pageable), pageable);
} }
return convertPage(repository.findAllWithoutCount(combineWithAnd(specList), pageable), pageable); return convertSlice(repository.findAllWithoutCount(combineWithAnd(specList), pageable), pageable);
} }
public static <T, J extends T> Slice<T> convertPage(final Slice<J> jpaAll, final Pageable pageable) { public static <T, J extends T> Slice<T> convertSlice(final Slice<J> jpaAll, final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(jpaAll.getContent()), pageable, 0); return new PageImpl<>(Collections.unmodifiableList(jpaAll.getContent()), pageable, 0);
} }
public static <J> long countBySpec(final JpaSpecificationExecutor<J> repository, public static <J> long countBySpec(final JpaSpecificationExecutor<J> repository, final List<Specification<J>> specList) {
final List<Specification<J>> specList) {
if (CollectionUtils.isEmpty(specList)) { if (CollectionUtils.isEmpty(specList)) {
return repository.count(Specification.where(null)); return repository.count(Specification.where(null));
} }
@@ -101,11 +99,9 @@ public final class JpaManagementHelper {
public static String[] getFilterNameAndVersionEntries(final String filterString) { public static String[] getFilterNameAndVersionEntries(final String filterString) {
final int semicolonIndex = filterString.indexOf(':'); final int semicolonIndex = filterString.indexOf(':');
final String filterName = semicolonIndex != -1 ? filterString.substring(0, semicolonIndex) final String filterName = semicolonIndex != -1 ? filterString.substring(0, semicolonIndex) : (filterString + "%");
: (filterString + "%");
final String filterVersion = semicolonIndex != -1 ? (filterString.substring(semicolonIndex + 1) + "%") : "%"; final String filterVersion = semicolonIndex != -1 ? (filterString.substring(semicolonIndex + 1) + "%") : "%";
return new String[] { ObjectUtils.isEmpty(filterName) ? "%" : filterName, filterVersion }; return new String[] { ObjectUtils.isEmpty(filterName) ? "%" : filterName, filterVersion };
} }
} }

View File

@@ -308,14 +308,14 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
public Slice<Action> findActionsAll(final Pageable pageable) { public Slice<Action> findActionsAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, pageable, null); return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, null, pageable);
} }
@Override @Override
public Slice<Action> findActions(final String rsqlParam, final Pageable pageable) { public Slice<Action> findActions(final String rsqlParam, final Pageable pageable) {
final List<Specification<JpaAction>> specList = List.of( final List<Specification<JpaAction>> specList = List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, ActionFields.class, virtualPropertyReplacer, database)); RSQLUtility.buildRsqlSpecification(rsqlParam, ActionFields.class, virtualPropertyReplacer, database));
return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, pageable, specList); return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, specList, pageable);
} }
@Override @Override

View File

@@ -275,8 +275,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
public Slice<DistributionSet> findAll(final Pageable pageable) { public Slice<DistributionSet> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, pageable, List.of( return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, List.of(
DistributionSetSpecification.isNotDeleted())); DistributionSetSpecification.isNotDeleted()), pageable);
} }
@Override @Override
@@ -514,7 +514,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public Slice<DistributionSet> findByCompleted(final Pageable pageReq, final Boolean complete) { public Slice<DistributionSet> findByCompleted(final Pageable pageReq, final Boolean complete) {
final List<Specification<JpaDistributionSet>> specifications = buildSpecsByComplete(complete); final List<Specification<JpaDistributionSet>> specifications = buildSpecsByComplete(complete);
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, pageReq, specifications); return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, specifications, pageReq);
} }
@Override @Override
@@ -529,7 +529,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications( final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
distributionSetFilter); distributionSetFilter);
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, pageable, specList); return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, specList, pageable);
} }
@Override @Override

View File

@@ -150,7 +150,7 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
public Slice<DistributionSetTag> findAll(final Pageable pageable) { public Slice<DistributionSetTag> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetTagRepository, pageable, null); return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetTagRepository, null, pageable);
} }
@Override @Override

View File

@@ -191,8 +191,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
public Slice<DistributionSetType> findAll(final Pageable pageable) { public Slice<DistributionSetType> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetTypeRepository, pageable, List.of( return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetTypeRepository, List.of(
DistributionSetTypeSpecification.isNotDeleted())); DistributionSetTypeSpecification.isNotDeleted()), pageable);
} }
@Override @Override

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.jpa.management;
import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions; import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@@ -84,7 +83,6 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
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;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@@ -104,12 +102,12 @@ import org.springframework.validation.annotation.Validated;
@Transactional(readOnly = true) @Transactional(readOnly = true)
public class JpaRolloutManagement implements RolloutManagement { public class JpaRolloutManagement implements RolloutManagement {
private static final List<RolloutStatus> ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING, private static final List<RolloutStatus> ACTIVE_ROLLOUTS = List.of(
RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING, RolloutStatus.CREATING, RolloutStatus.READY, RolloutStatus.STARTING, RolloutStatus.RUNNING,
RolloutStatus.STOPPING); RolloutStatus.STOPPING, RolloutStatus.DELETING);
private static final List<RolloutStatus> ROLLOUT_STATUS_STOPPABLE = Arrays.asList(RolloutStatus.RUNNING, private static final List<RolloutStatus> ROLLOUT_STATUS_STOPPABLE = List.of(
RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING, RolloutStatus.CREATING, RolloutStatus.READY, RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.STARTING, RolloutStatus.RUNNING,
RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED); RolloutStatus.PAUSED, RolloutStatus.APPROVAL_DENIED);
private final RolloutRepository rolloutRepository; private final RolloutRepository rolloutRepository;
private final RolloutGroupRepository rolloutGroupRepository; private final RolloutGroupRepository rolloutGroupRepository;
@@ -178,11 +176,6 @@ public class JpaRolloutManagement implements RolloutManagement {
return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, AbstractJpaBaseEntity_.ID))); return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, AbstractJpaBaseEntity_.ID)));
} }
@Override
public long countByFilters(final String searchText) {
return rolloutRepository.count(RolloutSpecification.likeName(searchText, false));
}
@Override @Override
public long countByDistributionSetIdAndRolloutIsStoppable(final long setId) { public long countByDistributionSetIdAndRolloutIsStoppable(final long setId) {
return rolloutRepository.countByDistributionSetIdAndStatusIn(setId, ROLLOUT_STATUS_STOPPABLE); return rolloutRepository.countByDistributionSetIdAndStatusIn(setId, ROLLOUT_STATUS_STOPPABLE);
@@ -273,28 +266,27 @@ public class JpaRolloutManagement implements RolloutManagement {
} }
@Override @Override
public Slice<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) { public Page<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) {
final Slice<Rollout> rollouts = JpaManagementHelper.convertPage( return appendStatusDetails(JpaManagementHelper.convertPage(
rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable),
pageable); pageable));
return getRolloutWithStatusDetails(rollouts);
} }
@Override @Override
public Page<Rollout> findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) { public Page<Rollout> findByRsql(final Pageable pageable, final String rsql, final boolean deleted) {
final List<Specification<JpaRollout>> specList = new ArrayList<>(2); final List<Specification<JpaRollout>> specList = List.of(
specList.add(RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutFields.class, virtualPropertyReplacer, database)); RSQLUtility.buildRsqlSpecification(rsql, RolloutFields.class, virtualPropertyReplacer, database),
specList.add(RolloutSpecification.isDeleted(deleted, pageable.getSort())); RolloutSpecification.isDeleted(deleted, pageable.getSort()));
return JpaManagementHelper.convertPage( return JpaManagementHelper.convertPage(rolloutRepository.findAll(JpaManagementHelper.combineWithAnd(specList), pageable), pageable);
rolloutRepository.findAll(JpaManagementHelper.combineWithAnd(specList), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable);
} }
@Override @Override
public Slice<Rollout> findByFiltersWithDetailedStatus(final Pageable pageable, final String searchText, public Page<Rollout> findByRsqlWithDetailedStatus(final Pageable pageable, final String rsql, final boolean deleted) {
final boolean deleted) { final List<Specification<JpaRollout>> specList = List.of(
final Slice<Rollout> findAll = JpaManagementHelper.findAllWithoutCountBySpec(rolloutRepository, pageable, RSQLUtility.buildRsqlSpecification(rsql, RolloutFields.class, virtualPropertyReplacer, database),
Collections.singletonList(RolloutSpecification.likeName(searchText, deleted))); RolloutSpecification.isDeleted(deleted, pageable.getSort()));
return getRolloutWithStatusDetails(findAll); return appendStatusDetails(JpaManagementHelper.convertPage(
rolloutRepository.findAll(JpaManagementHelper.combineWithAnd(specList), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable));
} }
@Override @Override
@@ -326,8 +318,8 @@ public class JpaRolloutManagement implements RolloutManagement {
rolloutStatusCache.putRolloutStatus(rolloutId, rolloutStatusCountItems); rolloutStatusCache.putRolloutStatus(rolloutId, rolloutStatusCountItems);
} }
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
rollout.get().getTotalTargets(), rollout.get().getActionType()); rolloutStatusCountItems, rollout.get().getTotalTargets(), rollout.get().getActionType());
((JpaRollout) rollout.get()).setTotalTargetCountStatus(totalTargetCountStatus); ((JpaRollout) rollout.get()).setTotalTargetCountStatus(totalTargetCountStatus);
return rollout; return rollout;
} }
@@ -445,14 +437,9 @@ public class JpaRolloutManagement implements RolloutManagement {
final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId) final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId)); .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
if (jpaRollout == null) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}
if (RolloutStatus.DELETING == jpaRollout.getStatus()) { if (RolloutStatus.DELETING == jpaRollout.getStatus()) {
return; return;
} }
jpaRollout.setStatus(RolloutStatus.DELETING); jpaRollout.setStatus(RolloutStatus.DELETING);
rolloutRepository.save(jpaRollout); rolloutRepository.save(jpaRollout);
} }
@@ -496,8 +483,7 @@ public class JpaRolloutManagement implements RolloutManagement {
startNextRolloutGroupAction.exec(rollout, latestRunning); startNextRolloutGroupAction.exec(rollout, latestRunning);
} }
@Override private Page<Rollout> appendStatusDetails(final Page<Rollout> rollouts) {
public Slice<Rollout> getRolloutWithStatusDetails(final Slice<Rollout> rollouts) {
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).toList(); final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).toList();
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds); final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds);

View File

@@ -253,9 +253,9 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
public Slice<SoftwareModule> findAll(final Pageable pageable) { public Slice<SoftwareModule> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, pageable, List.of( return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, List.of(
SoftwareModuleSpecification.isNotDeleted(), SoftwareModuleSpecification.isNotDeleted(),
SoftwareModuleSpecification.fetchType())); SoftwareModuleSpecification.fetchType()), pageable);
} }
@Override @Override
@@ -412,7 +412,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
specList.add(SoftwareModuleSpecification.fetchType()); specList.add(SoftwareModuleSpecification.fetchType());
return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, pageable, specList); return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, specList, pageable);
} }
@Override @Override
@@ -436,10 +436,10 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
return JpaManagementHelper.findAllWithoutCountBySpec( return JpaManagementHelper.findAllWithoutCountBySpec(
softwareModuleRepository, softwareModuleRepository,
pageable,
List.of( List.of(
SoftwareModuleSpecification.equalType(typeId), SoftwareModuleSpecification.equalType(typeId),
SoftwareModuleSpecification.isNotDeleted())); SoftwareModuleSpecification.isNotDeleted()), pageable
);
} }
@Override @Override

View File

@@ -136,8 +136,9 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
public Slice<SoftwareModuleType> findAll(final Pageable pageable) { public Slice<SoftwareModuleType> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleTypeRepository, pageable, return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleTypeRepository,
List.of(SoftwareModuleTypeSpecification.isNotDeleted())); List.of(SoftwareModuleTypeSpecification.isNotDeleted()), pageable
);
} }
@Override @Override

View File

@@ -158,7 +158,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override @Override
public Slice<TargetFilterQuery> findAll(final Pageable pageable) { public Slice<TargetFilterQuery> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, pageable, null); return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, null, pageable);
} }
@Override @Override
@@ -177,8 +177,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
return findAll(pageable); return findAll(pageable);
} }
return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, pageable, return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository,
Collections.singletonList(TargetFilterQuerySpecification.likeName(name))); Collections.singletonList(TargetFilterQuerySpecification.likeName(name)), pageable
);
} }
@Override @Override
@@ -207,7 +208,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
? Collections.singletonList(TargetFilterQuerySpecification.equalsQuery(query)) ? Collections.singletonList(TargetFilterQuerySpecification.equalsQuery(query))
: Collections.emptyList(); : Collections.emptyList();
return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, pageable, specList); return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, specList, pageable);
} }
@Override @Override
@@ -215,8 +216,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
final long setId) { final long setId) {
final DistributionSet distributionSet = distributionSetManagement.getOrElseThrowException(setId); final DistributionSet distributionSet = distributionSetManagement.getOrElseThrowException(setId);
return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, pageable, return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository,
Collections.singletonList(TargetFilterQuerySpecification.byAutoAssignDS(distributionSet))); Collections.singletonList(TargetFilterQuerySpecification.byAutoAssignDS(distributionSet)), pageable
);
} }
@Override @Override
@@ -236,8 +238,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override @Override
public Slice<TargetFilterQuery> findWithAutoAssignDS(final Pageable pageable) { public Slice<TargetFilterQuery> findWithAutoAssignDS(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository, pageable, return JpaManagementHelper.findAllWithoutCountBySpec(targetFilterQueryRepository,
Collections.singletonList(TargetFilterQuerySpecification.withAutoAssignDS())); Collections.singletonList(TargetFilterQuerySpecification.withAutoAssignDS()), pageable
);
} }
@Override @Override

View File

@@ -343,7 +343,7 @@ public class JpaTargetManagement implements TargetManagement {
} }
return JpaManagementHelper.findAllWithoutCountBySpec( return JpaManagementHelper.findAllWithoutCountBySpec(
targetRepository, pageRequest, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group))); targetRepository, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group)), pageRequest);
} }
@Override @Override
@@ -384,7 +384,7 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
public Slice<Target> findByFilters(final Pageable pageable, final FilterParams filterParams) { public Slice<Target> findByFilters(final Pageable pageable, final FilterParams filterParams) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams); final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
return JpaManagementHelper.findAllWithoutCountBySpec(targetRepository, pageable, specList); return JpaManagementHelper.findAllWithoutCountBySpec(targetRepository, specList, pageable);
} }
@Override @Override
@@ -420,8 +420,9 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
public Slice<Target> findByRsql(final Pageable pageable, final String targetFilterQuery) { public Slice<Target> findByRsql(final Pageable pageable, final String targetFilterQuery) {
return JpaManagementHelper.findAllWithoutCountBySpec( return JpaManagementHelper.findAllWithoutCountBySpec(
targetRepository, pageable, targetRepository,
List.of(RSQLUtility.buildRsqlSpecification(targetFilterQuery, TargetFields.class, virtualPropertyReplacer, database))); List.of(RSQLUtility.buildRsqlSpecification(targetFilterQuery, TargetFields.class, virtualPropertyReplacer, database)), pageable
);
} }
@Override @Override
@@ -430,9 +431,9 @@ public class JpaTargetManagement implements TargetManagement {
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId)); .orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
return JpaManagementHelper.findAllWithoutCountBySpec( return JpaManagementHelper.findAllWithoutCountBySpec(
targetRepository, pageable, targetRepository, List.of(RSQLUtility.buildRsqlSpecification(
List.of(RSQLUtility.buildRsqlSpecification( targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer, database)), pageable
targetFilterQuery.getQuery(), TargetFields.class, virtualPropertyReplacer, database))); );
} }
@Override @Override

View File

@@ -153,8 +153,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
public Slice<TargetType> findByName(final Pageable pageable, final String name) { public Slice<TargetType> findByName(final Pageable pageable, final String name) {
return JpaManagementHelper.findAllWithoutCountBySpec(targetTypeRepository, pageable, return JpaManagementHelper.findAllWithoutCountBySpec(targetTypeRepository, List.of(TargetTypeSpecification.likeName(name)), pageable
List.of(TargetTypeSpecification.likeName(name))); );
} }
@Override @Override

View File

@@ -40,22 +40,4 @@ public final class RolloutSpecification {
return predicate; return predicate;
}; };
} }
/**
* Builds a {@link Specification} to search a rollout by name.
*
* @param searchText search string
* @param isDeleted <code>true</code> if deleted rollouts should be included in
* the search. Otherwise <code>false</code>
* @return criteria specification with a query for name of a rollout
*/
public static Specification<JpaRollout> likeName(final String searchText, final boolean isDeleted) {
return (rolloutRoot, query, criteriaBuilder) -> {
final String searchTextToLower = searchText.toLowerCase();
return criteriaBuilder.and(
criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(AbstractJpaNamedEntity_.name)), searchTextToLower),
criteriaBuilder.equal(rolloutRoot.get(JpaRollout_.deleted), isDeleted));
};
}
} }

View File

@@ -109,12 +109,6 @@ class RolloutManagementSecurityTest extends AbstractJpaIntegrationTest {
assertPermissions(() -> rolloutManagement.countByDistributionSetIdAndRolloutIsStoppable(1L), List.of(SpPermission.READ_ROLLOUT)); assertPermissions(() -> rolloutManagement.countByDistributionSetIdAndRolloutIsStoppable(1L), List.of(SpPermission.READ_ROLLOUT));
} }
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void countByFiltersPermissionsCheck() {
assertPermissions(() -> rolloutManagement.countByFilters("searchFilter"), List.of(SpPermission.READ_ROLLOUT));
}
@Test @Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.") @Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void createPermissionsCheck() { void createPermissionsCheck() {
@@ -150,26 +144,9 @@ class RolloutManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.") @Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void findByFiltersWithDetailedStatusPermissionsCheck() { void findByRsqlWithDetailedStatusPermissionsCheck() {
assertPermissions(() -> rolloutManagement.findByFiltersWithDetailedStatus(PAGE, "searchFilter", false), assertPermissions(() ->
List.of(SpPermission.READ_ROLLOUT)); rolloutManagement.findByRsqlWithDetailedStatus(PAGE, "name==*", false), List.of(SpPermission.READ_ROLLOUT));
}
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void getRolloutWithStatusDetailsPermissionsCheck() {
final String rolloutName = "rollout-std";
final int amountGroups = 5; // static only
final String targetPrefix = "controller-rollout-std-";
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(targetPrefix, 0, amountGroups * 3);
final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups,
"controllerid==" + targetPrefix + "*", distributionSet, "60", "30", false, false);
assertPermissions(() -> {
rolloutManagement.getRolloutWithStatusDetails(new PageImpl<>(List.of(rollout)));
return null;
}, List.of(SpPermission.READ_ROLLOUT, SpPermission.READ_REPOSITORY));
} }
@Test @Test

View File

@@ -1096,32 +1096,9 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(count).isEqualTo(10L); assertThat(count).isEqualTo(10L);
} }
@Test
@Description("Verify the count of filtered existing rollouts.")
void countRolloutsAllByFilters() {
final int amountTargetsForRollout = 6;
final int amountGroups = 2;
final String successCondition = "50";
final String errorCondition = "80";
for (int i = 1; i <= 5; i++) {
createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition,
errorCondition, "Rollout" + i, "Rollout" + i);
}
for (int i = 1; i <= 5; i++) {
createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition,
errorCondition, "SomethingElse" + i, "SomethingElse" + i);
}
final Long count = rolloutManagement.countByFilters("Rollout%");
assertThat(count).isEqualTo(5L);
}
@Test @Test
@Description("Verify that the filtering and sorting ascending for rollout is working correctly.") @Description("Verify that the filtering and sorting ascending for rollout is working correctly.")
void findRolloutByFilters() { void findRolloutByFilters() {
final int amountTargetsForRollout = 6; final int amountTargetsForRollout = 6;
final int amountGroups = 2; final int amountGroups = 2;
final String successCondition = "50"; final String successCondition = "50";
@@ -1135,8 +1112,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
errorCondition, "SomethingElse" + i, "SomethingElse" + i); errorCondition, "SomethingElse" + i, "SomethingElse" + i);
} }
final Slice<Rollout> rollout = rolloutManagement.findByFiltersWithDetailedStatus( final Slice<Rollout> rollout = rolloutManagement.findByRsqlWithDetailedStatus(
new OffsetBasedPageRequest(0, 100, Sort.by(Direction.ASC, "name")), "Rollout%", false); new OffsetBasedPageRequest(0, 100, Sort.by(Direction.ASC, "name")), "name==Rollout*", false);
final List<Rollout> rolloutList = rollout.getContent(); final List<Rollout> rolloutList = rollout.getContent();
assertThat(rolloutList).hasSize(5); assertThat(rolloutList).hasSize(5);
int i = 1; int i = 1;
@@ -1905,8 +1882,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(rolloutManagement.findByRsql(PAGE, "name==*", true).getContent()).hasSize(1); assertThat(rolloutManagement.findByRsql(PAGE, "name==*", true).getContent()).hasSize(1);
assertThat(rolloutManagement.findByRsql(PAGE, "name==*", false).getContent()).isEmpty(); assertThat(rolloutManagement.findByRsql(PAGE, "name==*", false).getContent()).isEmpty();
assertThat(rolloutManagement.count()).isZero(); assertThat(rolloutManagement.count()).isZero();
assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(createdRollout.getId(), PAGE).getContent()) assertThat(rolloutGroupManagement.findByRolloutWithDetailedStatus(createdRollout.getId(), PAGE).getContent()).hasSize(amountGroups);
.hasSize(amountGroups);
// verify that all scheduled actions are deleted // verify that all scheduled actions are deleted
assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.SCHEDULED) assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.SCHEDULED)