Fix retrieve Rollout with details (#2435)

* Fix retrieve Rollout with details

* Rename RolloutManagement method for retrieve Rollout slice with details. Slight refactoring in MgmtRolloutMapper

---------

Co-authored-by: vasilchev <vasil.ilchev@bosch.com>
This commit is contained in:
Vasil Ilchev
2025-06-09 15:38:20 +03:00
committed by GitHub
parent 5a304af165
commit 09a3d3e0c6
5 changed files with 20 additions and 18 deletions

View File

@@ -62,7 +62,11 @@ final class MgmtRolloutMapper {
return toResponseRollout(rollouts, false);
}
static List<MgmtRolloutResponseBody> toResponseRollout(final List<Rollout> rollouts, final boolean withDetails) {
static List<MgmtRolloutResponseBody> toResponseRolloutWithDetails(final List<Rollout> rollouts) {
return toResponseRollout(rollouts, true);
}
private static List<MgmtRolloutResponseBody> toResponseRollout(final List<Rollout> rollouts, final boolean withDetails) {
if (rollouts == null) {
return Collections.emptyList();
}

View File

@@ -94,19 +94,20 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Rollout> rollouts;
if (rsqlParam != null) {
rollouts = this.rolloutManagement.findByRsql(pageable, rsqlParam, false);
rollouts = rolloutManagement.findByRsql(pageable, rsqlParam, false);
} else {
rollouts = this.rolloutManagement.findAll(pageable, false);
rollouts = rolloutManagement.findAll(pageable, false);
}
final long totalElements = rollouts.getTotalElements();
final List<MgmtRolloutResponseBody> rest;
if (isFullMode) {
this.rolloutManagement.setRolloutStatusDetails(rollouts);
rest = MgmtRolloutMapper.toResponseRolloutWithDetails(rolloutManagement.getRolloutWithStatusDetails(rollouts).getContent());
} else {
rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent());
}
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(), isFullMode);
return ResponseEntity.ok(new PagedList<>(rest, totalElements));
}

View File

@@ -412,6 +412,6 @@ public interface RolloutManagement {
*
* @param rollouts the rollouts to be enriched.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
void setRolloutStatusDetails(final Slice<Rollout> rollouts);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
Slice<Rollout> getRolloutWithStatusDetails(final Slice<Rollout> rollouts);
}

View File

@@ -277,8 +277,7 @@ public class JpaRolloutManagement implements RolloutManagement {
final Slice<Rollout> rollouts = JpaManagementHelper.convertPage(
rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable),
pageable);
setRolloutStatusDetails(rollouts);
return rollouts;
return getRolloutWithStatusDetails(rollouts);
}
@Override
@@ -295,8 +294,7 @@ public class JpaRolloutManagement implements RolloutManagement {
final boolean deleted) {
final Slice<Rollout> findAll = JpaManagementHelper.findAllWithoutCountBySpec(rolloutRepository, pageable,
Collections.singletonList(RolloutSpecification.likeName(searchText, deleted)));
setRolloutStatusDetails(findAll);
return findAll;
return getRolloutWithStatusDetails(findAll);
}
@Override
@@ -499,7 +497,7 @@ public class JpaRolloutManagement implements RolloutManagement {
}
@Override
public void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
public Slice<Rollout> getRolloutWithStatusDetails(final Slice<Rollout> rollouts) {
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).toList();
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds);
@@ -510,6 +508,7 @@ public class JpaRolloutManagement implements RolloutManagement {
((JpaRollout) rollout).setTotalTargetCountStatus(totalTargetCountStatus);
});
}
return rollouts;
}
/**

View File

@@ -22,11 +22,9 @@ import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate;
import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageImpl;
@@ -159,7 +157,7 @@ class RolloutManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void setRolloutStatusDetailsPermissionsCheck() {
void getRolloutWithStatusDetailsPermissionsCheck() {
final String rolloutName = "rollout-std";
final int amountGroups = 5; // static only
final String targetPrefix = "controller-rollout-std-";
@@ -169,9 +167,9 @@ class RolloutManagementSecurityTest extends AbstractJpaIntegrationTest {
final Rollout rollout = testdataFactory.createRolloutByVariables(rolloutName, rolloutName, amountGroups,
"controllerid==" + targetPrefix + "*", distributionSet, "60", "30", false, false);
assertPermissions(() -> {
rolloutManagement.setRolloutStatusDetails(new PageImpl<>(List.of(rollout)));
rolloutManagement.getRolloutWithStatusDetails(new PageImpl<>(List.of(rollout)));
return null;
}, List.of(SpPermission.UPDATE_ROLLOUT, SpPermission.READ_REPOSITORY));
}, List.of(SpPermission.READ_ROLLOUT, SpPermission.READ_REPOSITORY));
}
@Test