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);
|
this.rolloutManagement.setRolloutStatusDetails(rollouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(),
|
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent(), isFullMode);
|
||||||
isFullMode);
|
|
||||||
|
|
||||||
return ResponseEntity.ok(new PagedList<>(rest, totalElements));
|
return ResponseEntity.ok(new PagedList<>(rest, totalElements));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,5 +414,4 @@ public interface RolloutManagement {
|
|||||||
*/
|
*/
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_UPDATE)
|
||||||
void setRolloutStatusDetails(final Slice<Rollout> rollouts);
|
void setRolloutStatusDetails(final Slice<Rollout> rollouts);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -165,8 +165,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long count() {
|
public long count() {
|
||||||
return rolloutRepository.count(
|
return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, JpaRollout_.ID)));
|
||||||
RolloutSpecification.isDeletedWithDistributionSet(false, Sort.by(Direction.DESC, JpaRollout_.ID)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -225,7 +224,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
throw new ValidationException("The amount of groups cannot be 0");
|
throw new ValidationException("The amount of groups cannot be 0");
|
||||||
}
|
}
|
||||||
RolloutHelper.verifyRolloutGroupAmount(groups.size(), quotaManagement);
|
RolloutHelper.verifyRolloutGroupAmount(groups.size(), quotaManagement);
|
||||||
return createRolloutGroups(groups, conditions, createRollout((JpaRollout)rollout.build(), false));
|
return createRolloutGroups(groups, conditions, createRollout((JpaRollout) rollout.build(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -248,15 +247,14 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<Rollout> findAll(final Pageable pageable, final boolean deleted) {
|
public Page<Rollout> findAll(final Pageable pageable, final boolean deleted) {
|
||||||
return JpaManagementHelper.findAllWithCountBySpec(rolloutRepository, pageable, Collections
|
return JpaManagementHelper.convertPage(
|
||||||
.singletonList(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort())));
|
rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), pageable), pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Slice<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) {
|
public Slice<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) {
|
||||||
final Slice<Rollout> rollouts = JpaManagementHelper.findAllWithoutCountBySpec(rolloutRepository, pageable,
|
final Slice<Rollout> rollouts = JpaManagementHelper.convertPage(
|
||||||
Collections
|
rolloutRepository.findAll(RolloutSpecification.isDeleted(deleted, pageable.getSort()), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable);
|
||||||
.singletonList(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort())));
|
|
||||||
setRolloutStatusDetails(rollouts);
|
setRolloutStatusDetails(rollouts);
|
||||||
return rollouts;
|
return rollouts;
|
||||||
}
|
}
|
||||||
@@ -264,11 +262,10 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
@Override
|
@Override
|
||||||
public Page<Rollout> findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) {
|
public Page<Rollout> findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) {
|
||||||
final List<Specification<JpaRollout>> specList = new ArrayList<>(2);
|
final List<Specification<JpaRollout>> specList = new ArrayList<>(2);
|
||||||
specList.add(
|
specList.add(RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutFields.class, virtualPropertyReplacer, database));
|
||||||
RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutFields.class, virtualPropertyReplacer, database));
|
specList.add(RolloutSpecification.isDeleted(deleted, pageable.getSort()));
|
||||||
specList.add(RolloutSpecification.isDeletedWithDistributionSet(deleted, pageable.getSort()));
|
return JpaManagementHelper.convertPage(
|
||||||
|
rolloutRepository.findAll(JpaManagementHelper.combineWithAnd(specList), JpaRollout_.GRAPH_ROLLOUT_DS, pageable), pageable);
|
||||||
return JpaManagementHelper.findAllWithCountBySpec(rolloutRepository, pageable, specList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -732,9 +729,11 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
return fromCache;
|
return fromCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private v isDeletedWithDistributionSet(final Boolean isDeleted, final Sort sort) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforces the quota defining the maximum number of {@link Target}s per
|
* Enforces the quota defining the maximum number of {@link Target}s per {@link RolloutGroup}.
|
||||||
* {@link RolloutGroup}.
|
|
||||||
*
|
*
|
||||||
* @param requested number of targets to check
|
* @param requested number of targets to check
|
||||||
*/
|
*/
|
||||||
@@ -743,8 +742,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
QuotaHelper.assertAssignmentQuota(requested, quota, Target.class, RolloutGroup.class);
|
QuotaHelper.assertAssignmentQuota(requested, quota, Target.class, RolloutGroup.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RolloutGroupsValidation validateTargetsInGroups(final List<RolloutGroup> groups, final String baseFilter,
|
private RolloutGroupsValidation validateTargetsInGroups(
|
||||||
final long totalTargets, final Long dsTypeId) {
|
final List<RolloutGroup> groups, final String baseFilter, final long totalTargets, final Long dsTypeId) {
|
||||||
final List<Long> groupTargetCounts = new ArrayList<>(groups.size());
|
final List<Long> groupTargetCounts = new ArrayList<>(groups.size());
|
||||||
Map<String, Long> targetFilterCounts;
|
Map<String, Long> targetFilterCounts;
|
||||||
if (!RolloutHelper.isRolloutRetried(baseFilter)) {
|
if (!RolloutHelper.isRolloutRetried(baseFilter)) {
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import jakarta.persistence.FetchType;
|
|||||||
import jakarta.persistence.ForeignKey;
|
import jakarta.persistence.ForeignKey;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.NamedAttributeNode;
|
||||||
|
import jakarta.persistence.NamedEntityGraph;
|
||||||
|
import jakarta.persistence.NamedEntityGraphs;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.persistence.Transient;
|
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.
|
@NoArgsConstructor(access = AccessLevel.PUBLIC) // Default constructor needed for JPA entities.
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name",
|
@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout"))
|
||||||
"tenant" }, name = "uk_rollout"))
|
@NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) })
|
||||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
|
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
|
||||||
@SuppressWarnings("squid:S2160")
|
@SuppressWarnings("squid:S2160")
|
||||||
public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, EventAwareEntity {
|
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
|
* {@link Specification} for retrieving {@link Rollout}s by its <code>deleted</code> attribute.
|
||||||
* attribute. Includes fetch for stuff that is required for {@link Rollout}
|
|
||||||
* queries.
|
|
||||||
*
|
*
|
||||||
* @param isDeleted TRUE/FALSE are compared to the attribute DELETED. If NULL the
|
* @param isDeleted true/false are compared to the attribute <code>deleted</code>. If NULL the attribute is ignored
|
||||||
* attribute is ignored
|
|
||||||
* @return the {@link Rollout} {@link Specification}
|
* @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) -> {
|
return (root, query, cb) -> {
|
||||||
|
|
||||||
final Predicate predicate = cb.equal(root.<Boolean> get(JpaRollout_.deleted), isDeleted);
|
final Predicate predicate = cb.equal(root.<Boolean> get(JpaRollout_.deleted), isDeleted);
|
||||||
root.fetch(JpaRollout_.distributionSet);
|
|
||||||
query.orderBy(QueryUtils.toOrders(sort, root, cb));
|
query.orderBy(QueryUtils.toOrders(sort, root, cb));
|
||||||
return predicate;
|
return predicate;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user