diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index d31aaf1015..c0b05bfb05 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -105,8 +105,7 @@ public ResponseEntity> getRollouts( this.rolloutManagement.setRolloutStatusDetails(rollouts); } - final List rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(), - isFullMode); + final List rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(), isFullMode); return ResponseEntity.ok(new PagedList<>(rest, totalElements)); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index bf7c6b87b2..0c71824b7c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -414,5 +414,4 @@ Slice findByFiltersWithDetailedStatus(@NotNull Pageable pageable, @NotE */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE) void setRolloutStatusDetails(final Slice rollouts); - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java index 89f4829303..6019949520 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java @@ -165,8 +165,7 @@ public void publishRolloutGroupCreatedEventAfterCommit(final RolloutGroup group, @Override public long count() { - return rolloutRepository.count( - RolloutSpecification.isDeletedWithDistributionSet(false, Sort.by(Direction.DESC, JpaRollout_.ID))); + return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, JpaRollout_.ID))); } @Override @@ -225,7 +224,7 @@ public Rollout create(final RolloutCreate rollout, final List validateTargetsInGroups(final L @Override public Page findAll(final Pageable pageable, final boolean deleted) { - return JpaManagementHelper.findAllWithCountBySpec(rolloutRepository, pageable, Collections - .singletonList(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort()))); + return JpaManagementHelper.convertPage( + rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), pageable), pageable); } @Override public Slice findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) { - final Slice rollouts = JpaManagementHelper.findAllWithoutCountBySpec(rolloutRepository, pageable, - Collections - .singletonList(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort()))); + final Slice rollouts = JpaManagementHelper.convertPage( + rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable); setRolloutStatusDetails(rollouts); return rollouts; } @@ -264,11 +262,10 @@ public Slice findAllWithDetailedStatus(final Pageable pageable, final b @Override public Page findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) { final List> specList = new ArrayList<>(2); - specList.add( - RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutFields.class, virtualPropertyReplacer, database)); - specList.add(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort())); - - return JpaManagementHelper.findAllWithCountBySpec(rolloutRepository, pageable, specList); + specList.add(RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutFields.class, virtualPropertyReplacer, database)); + specList.add(RolloutSpecification.isDeleted(deleted, pageable.getSort())); + return JpaManagementHelper.convertPage( + rolloutRepository.findAll(JpaManagementHelper.combineWithAnd(specList), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable); } @Override @@ -732,9 +729,11 @@ private Map> getStatusCountItemForRollo return fromCache; } +// private v isDeletedWithDistributionSet(final Boolean isDeleted, final Sort sort) { + + /** - * Enforces the quota defining the maximum number of {@link Target}s per - * {@link RolloutGroup}. + * Enforces the quota defining the maximum number of {@link Target}s per {@link RolloutGroup}. * * @param requested number of targets to check */ @@ -743,8 +742,8 @@ private void assertTargetsPerRolloutGroupQuota(final long requested) { QuotaHelper.assertAssignmentQuota(requested, quota, Target.class, RolloutGroup.class); } - private RolloutGroupsValidation validateTargetsInGroups(final List groups, final String baseFilter, - final long totalTargets, final Long dsTypeId) { + private RolloutGroupsValidation validateTargetsInGroups( + final List groups, final String baseFilter, final long totalTargets, final Long dsTypeId) { final List groupTargetCounts = new ArrayList<>(groups.size()); Map targetFilterCounts; if (!RolloutHelper.isRolloutRetried(baseFilter)) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index b70a6b8a56..4f61247c77 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -26,6 +26,9 @@ import jakarta.persistence.ForeignKey; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.NamedAttributeNode; +import jakarta.persistence.NamedEntityGraph; +import jakarta.persistence.NamedEntityGraphs; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import jakarta.persistence.Transient; @@ -57,8 +60,8 @@ */ @NoArgsConstructor(access = AccessLevel.PUBLIC) // Default constructor needed for JPA entities. @Entity -@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", - "tenant" }, name = "uk_rollout")) +@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) +@NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) }) // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities @SuppressWarnings("squid:S2160") public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, EventAwareEntity { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/RolloutSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/RolloutSpecification.java index 3f9bd348ca..efd4849365 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/RolloutSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/RolloutSpecification.java @@ -29,23 +29,17 @@ private RolloutSpecification() { } /** - * {@link Specification} for retrieving {@link Rollout}s by its DELETED - * attribute. Includes fetch for stuff that is required for {@link Rollout} - * queries. + * {@link Specification} for retrieving {@link Rollout}s by its deleted attribute. * - * @param isDeleted TRUE/FALSE are compared to the attribute DELETED. If NULL the - * attribute is ignored + * @param isDeleted true/false are compared to the attribute deleted. If NULL the attribute is ignored * @return the {@link Rollout} {@link Specification} */ - public static Specification isDeletedWithDistributionSet(final Boolean isDeleted, final Sort sort) { + public static Specification isDeleted(final Boolean isDeleted, final Sort sort) { return (root, query, cb) -> { - final Predicate predicate = cb.equal(root. get(JpaRollout_.deleted), isDeleted); - root.fetch(JpaRollout_.distributionSet); query.orderBy(QueryUtils.toOrders(sort, root, cb)); return predicate; }; - } /**