Add Rollout.ds entity graph (#2127)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -105,8 +105,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -414,5 +414,4 @@ public interface RolloutManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
|
||||
void setRolloutStatusDetails(final Slice<Rollout> rollouts);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -165,8 +165,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
|
||||
@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 class JpaRolloutManagement implements RolloutManagement {
|
||||
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
|
||||
@@ -248,15 +247,14 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -264,11 +262,10 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
@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
|
||||
@@ -732,9 +729,11 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
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 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
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)) {
|
||||
|
||||
@@ -26,6 +26,9 @@ import jakarta.persistence.FetchType;
|
||||
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 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
*/
|
||||
@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 {
|
||||
|
||||
@@ -29,23 +29,17 @@ public final class 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user