Skip to content

Commit

Permalink
Add Rollout.ds entity graph (#2127)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Dec 6, 2024
1 parent 9de1bd2 commit b9c10ac
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public ResponseEntity<PagedList<MgmtRolloutResponseBody>> getRollouts(
this.rolloutManagement.setRolloutStatusDetails(rollouts);
}

final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(),
isFullMode);
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(), isFullMode);

return ResponseEntity.ok(new PagedList<>(rest, totalElements));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,4 @@ Slice<Rollout> findByFiltersWithDetailedStatus(@NotNull Pageable pageable, @NotE
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
void setRolloutStatusDetails(final Slice<Rollout> rollouts);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,7 +224,7 @@ public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate
throw new ValidationException("The amount of groups cannot be 0");
}
RolloutHelper.verifyRolloutGroupAmount(groups.size(), quotaManagement);
return createRolloutGroups(groups, conditions, createRollout((JpaRollout)rollout.build(), false));
return createRolloutGroups(groups, conditions, createRollout((JpaRollout) rollout.build(), false));
}

@Override
Expand All @@ -248,27 +247,25 @@ public ListenableFuture<RolloutGroupsValidation> validateTargetsInGroups(final L

@Override
public Page<Rollout> 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<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) {
final Slice<Rollout> rollouts = JpaManagementHelper.findAllWithoutCountBySpec(rolloutRepository, pageable,
Collections
.singletonList(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort())));
final Slice<Rollout> rollouts = JpaManagementHelper.convertPage(
rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable);
setRolloutStatusDetails(rollouts);
return rollouts;
}

@Override
public Page<Rollout> findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) {
final List<Specification<JpaRollout>> 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
Expand Down Expand Up @@ -732,9 +729,11 @@ private Map<Long, List<TotalTargetCountActionStatus>> 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
*/
Expand All @@ -743,8 +742,8 @@ private void assertTargetsPerRolloutGroupQuota(final long requested) {
QuotaHelper.assertAssignmentQuota(requested, quota, Target.class, RolloutGroup.class);
}

private RolloutGroupsValidation validateTargetsInGroups(final List<RolloutGroup> groups, final String baseFilter,
final long totalTargets, final Long dsTypeId) {
private RolloutGroupsValidation validateTargetsInGroups(
final List<RolloutGroup> groups, final String baseFilter, final long totalTargets, final Long dsTypeId) {
final List<Long> groupTargetCounts = new ArrayList<>(groups.size());
Map<String, Long> targetFilterCounts;
if (!RolloutHelper.isRolloutRetried(baseFilter)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>deleted</code> 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 <code>deleted</code>. If NULL the attribute is ignored
* @return the {@link Rollout} {@link Specification}
*/
public static Specification<JpaRollout> isDeletedWithDistributionSet(final Boolean isDeleted, final Sort sort) {
public static Specification<JpaRollout> isDeleted(final Boolean isDeleted, final Sort sort) {
return (root, query, cb) -> {

final Predicate predicate = cb.equal(root.<Boolean> get(JpaRollout_.deleted), isDeleted);
root.fetch(JpaRollout_.distributionSet);
query.orderBy(QueryUtils.toOrders(sort, root, cb));
return predicate;
};

}

/**
Expand Down

0 comments on commit b9c10ac

Please sign in to comment.