Skip to content

Commit

Permalink
Remove unused TargetManagement#findByFilterOrderByLinkedDistributionS…
Browse files Browse the repository at this point in the history
…et (#2138)

Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Dec 11, 2024
1 parent ede05fe commit 68c0b61
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,30 +453,6 @@ Page<Target> findByInstalledDistributionSetAndRsql(@NotNull Pageable pageReq, lo
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findByTargetFilterQuery(@NotNull Pageable pageable, long targetFilterQueryId);

/**
* method retrieves all {@link Target}s from the repo in the following order:
* <p>
* <ol>
* <li>{@link Target}s which have the given {@link DistributionSet} as installed
* distribution set</li>
* <li>{@link Target}s which have the given {@link DistributionSet} as assigned
* distribution set</li>
* <li>{@link Target}s which have no connection to the given
* {@link DistributionSet}</li>
* </ol>
*
* @param pageable the page request to page the result set
* @param orderByDistributionSetId {@link DistributionSet#getId()} to be ordered by
* @param filterParams the filters to apply; only filters are enabled that have non-null
* value; filters are AND-gated
* @return a paged result {@link Page} of the {@link Target}s in a defined
* order.
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Target> findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageable, long orderByDistributionSetId,
@NotNull FilterParams filterParams);

/**
* Find targets by tag name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,6 @@ public Slice<Target> findByTargetFilterQuery(final Pageable pageable, final long
virtualPropertyReplacer, database)));
}

@Override
public Slice<Target> findByFilterOrderByLinkedDistributionSet(final Pageable pageable,
final long orderByDistributionSetId, final FilterParams filterParams) {
// remove default sort from pageable to not overwrite sorted spec
final OffsetBasedPageRequest unsortedPage = new OffsetBasedPageRequest(pageable.getOffset(),
pageable.getPageSize(), Sort.unsorted());

final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
specList.add(TargetSpecifications.orderedByLinkedDistributionSet(orderByDistributionSetId, pageable.getSort()));

return JpaManagementHelper.findAllWithoutCountBySpec(targetRepository, unsortedPage, specList);
}

@Override
public Page<Target> findByTag(final Pageable pageable, final long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
import java.util.List;

import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
Expand All @@ -31,7 +29,6 @@
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
Expand All @@ -52,9 +49,7 @@
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.query.QueryUtils;

/**
* Specifications class for {@link Target}s. The class provides Spring Data JPQL Specifications.
Expand Down Expand Up @@ -222,8 +217,7 @@ public static Specification<JpaTarget> hasInstalledOrAssignedDistributionSet(@No
}

/**
* Finds all targets by given {@link Target#getControllerId()}s and which
* are not yet assigned to given {@link DistributionSet}.
* Finds all targets by given {@link Target#getControllerId()}s and which are not yet assigned to given {@link DistributionSet}.
*
* @param tIDs to search for.
* @param distributionId set that is not yet assigned
Expand All @@ -232,8 +226,8 @@ public static Specification<JpaTarget> hasInstalledOrAssignedDistributionSet(@No
public static Specification<JpaTarget> hasControllerIdAndAssignedDistributionSetIdNot(final List<String> tIDs,
@NotNull final Long distributionId) {
return (targetRoot, query, cb) -> cb.and(targetRoot.get(JpaTarget_.controllerId).in(tIDs),
cb.or(cb.notEqual(targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet)
.get(JpaDistributionSet_.id), distributionId),
cb.or(
cb.notEqual(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), distributionId),
cb.isNull(targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet))));
}

Expand Down Expand Up @@ -276,8 +270,7 @@ public static Specification<JpaTarget> hasTags(final String[] tagNames, final Bo
*/
public static Specification<JpaTarget> hasAssignedDistributionSet(final Long distributionSetId) {
return (targetRoot, query, cb) -> cb.equal(
targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id),
distributionSetId);
targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), distributionSetId);
}

/**
Expand Down Expand Up @@ -481,45 +474,6 @@ public static Specification<JpaTarget> hasTargetTypeNot(final Long typeId) {
cb.notEqual(targetRoot.get(JpaTarget_.targetType).get(JpaTargetType_.id), typeId));
}

/**
* Can be added to specification chain to order result by provided
* distribution set
*
* Order: 1. Targets with DS installed, 2. Targets with DS assigned, 3.
* Based on requested sorting or id if <code>null</code>.
*
* NOTE: Other specs, pagables and sort objects may alter the queries
* orderBy entry too, possibly invalidating the applied order, keep in mind
* when using this
*
* @param distributionSetIdForOrder distribution set to consider
* @param sort the sorting requested
* @return specification that applies order by ds, may be overwritten
*/
public static Specification<JpaTarget> orderedByLinkedDistributionSet(final long distributionSetIdForOrder,
final Sort sort) {
return (targetRoot, query, cb) -> {
// Enhance query with custom select based sort
final Expression<Object> selectCase = cb.selectCase()
.when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id),
distributionSetIdForOrder), 1)
.when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id),
distributionSetIdForOrder), 2)
.otherwise(100);
final List<Order> orders = new ArrayList<>();
orders.add(cb.asc(selectCase));
if (sort == null || sort.isEmpty()) {
orders.add(cb.desc(targetRoot.get(JpaTarget_.id)));
} else {
orders.addAll(QueryUtils.toOrders(sort, targetRoot, cb));
}
query.orderBy(orders);

// Spec only provides order, so no further filtering
return query.getRestriction();
};
}

public static Specification<JpaTarget> failedActionsForRollout(final String rolloutId) {
return (targetRoot, query, cb) -> {
Join<JpaTarget, Action> targetActions =
Expand Down
Loading

0 comments on commit 68c0b61

Please sign in to comment.