Remove unused DistributionSetManagement#findByDistributionSetFilterOrderByLinkedTarget (#2141)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -32,7 +32,6 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
@@ -83,7 +82,6 @@ import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
@@ -409,7 +407,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
throw new InsufficientPermissionException("Target not accessible (or not found)!");
|
||||
}
|
||||
return distributionSetRepository
|
||||
.findOne(DistributionSetSpecification.byId(action.getDistributionSet().getId()))
|
||||
.findOne(DistributionSetSpecification.byIdFetch(action.getDistributionSet().getId()))
|
||||
.orElseThrow(() ->
|
||||
new InsufficientPermissionException("DistributionSet not accessible (or not found)!"));
|
||||
})
|
||||
@@ -518,25 +516,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, pageable, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<DistributionSet> findByDistributionSetFilterOrderByLinkedTarget(final Pageable pageable,
|
||||
final DistributionSetFilter distributionSetFilter, final String assignedOrInstalled) {
|
||||
// remove default sort from pageable to not overwrite sorted spec
|
||||
final OffsetBasedPageRequest unsortedPage = new OffsetBasedPageRequest(pageable.getOffset(),
|
||||
pageable.getPageSize(), Sort.unsorted());
|
||||
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
|
||||
distributionSetFilter);
|
||||
specList.add(DistributionSetSpecification.orderedByLinkedTarget(assignedOrInstalled, pageable.getSort()));
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, unsortedPage, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByDistributionSetFilter(@NotNull final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
|
||||
distributionSetFilter);
|
||||
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
|
||||
return JpaManagementHelper.countBySpec(distributionSetRepository, specList);
|
||||
}
|
||||
|
||||
@@ -791,7 +773,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
distributionSetRepository.findById(dsIds.iterator().next())
|
||||
.map(List::of)
|
||||
.orElseGet(Collections::emptyList) :
|
||||
distributionSetRepository.findAll(DistributionSetSpecification.byIds(dsIds));
|
||||
distributionSetRepository.findAll(DistributionSetSpecification.byIdsFetch(dsIds));
|
||||
if (allDs.size() < dsIds.size()) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, notFound(dsIds, allDs));
|
||||
}
|
||||
@@ -898,7 +880,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final BiFunction<List<JpaDistributionSet>, DistributionSetTag, T> updater) {
|
||||
final List<JpaDistributionSet> allDs = dsIds.size() == 1 ?
|
||||
distributionSetRepository.findById(dsIds.iterator().next()).map(List::of).orElseGet(Collections::emptyList) :
|
||||
distributionSetRepository.findAll(DistributionSetSpecification.byIds(dsIds));
|
||||
distributionSetRepository.findAll(DistributionSetSpecification.byIdsFetch(dsIds));
|
||||
if (allDs.size() < dsIds.size()) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsIds, allDs.stream().map(DistributionSet::getId).toList());
|
||||
}
|
||||
|
||||
@@ -66,8 +66,7 @@ public interface DistributionSetRepository extends BaseEntityRepository<JpaDistr
|
||||
Long countAutoAssignmentsForDistributionSet(@Param("dsId") Long dsId);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s where given {@link SoftwareModule} is
|
||||
* assigned.
|
||||
* Finds {@link DistributionSet}s where given {@link SoftwareModule} is assigned.
|
||||
* <p/>
|
||||
* No access control applied.
|
||||
*
|
||||
@@ -77,8 +76,7 @@ public interface DistributionSetRepository extends BaseEntityRepository<JpaDistr
|
||||
Long countByModulesId(Long moduleId);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to
|
||||
* an {@link Action}, i.e. in use.
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to an {@link Action}, i.e. in use.
|
||||
* <p/>
|
||||
* No access control applied.
|
||||
*
|
||||
@@ -89,8 +87,7 @@ public interface DistributionSetRepository extends BaseEntityRepository<JpaDistr
|
||||
List<Long> findAssignedToTargetDistributionSetsById(@Param("ids") Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to
|
||||
* an {@link Rollout}, i.e. in use.
|
||||
* Finds {@link DistributionSet}s based on given ID that are assigned yet to an {@link Rollout}, i.e. in use.
|
||||
* <p/>
|
||||
* No access control applied.
|
||||
*
|
||||
@@ -111,10 +108,8 @@ public interface DistributionSetRepository extends BaseEntityRepository<JpaDistr
|
||||
long countByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
* reasons (this is a "delete everything" query after all) we add the tenant
|
||||
* manually to query even if this will by done by {@link EntityManager}
|
||||
* anyhow. The DB should take care of optimizing this away.
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety reasons (this is a "delete everything" query after all) we add
|
||||
* the tenant manually to query even if this will by done by {@link EntityManager} anyhow. The DB should take care of optimizing this away.
|
||||
*
|
||||
* @param tenant to delete data from
|
||||
*/
|
||||
|
||||
@@ -14,9 +14,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Expression;
|
||||
import jakarta.persistence.criteria.JoinType;
|
||||
import jakarta.persistence.criteria.Order;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
@@ -29,24 +27,18 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.query.QueryUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Specifications class for {@link DistributionSet}s. The class provides Spring
|
||||
* Data JPQL Specifications.
|
||||
* Specifications class for {@link DistributionSet}s. The class provides Spring Data JPQL Specifications.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class DistributionSetSpecification {
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s with
|
||||
* DELETED attribute <code>false</code> - i.e. is not deleted.
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s with DELETED attribute <code>false</code> - i.e. is not deleted.
|
||||
*
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
@@ -55,51 +47,44 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its
|
||||
* DELETED attribute.
|
||||
* {@link Specification} for retrieving {@link DistributionSet}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 DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> isDeleted(final Boolean isDeleted) {
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.<Boolean> get(JpaDistributionSet_.deleted), isDeleted);
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.deleted), isDeleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its
|
||||
* COMPLETED attribute.
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its COMPLETED attribute.
|
||||
*
|
||||
* @param isCompleted TRUE/FALSE are compared to the attribute COMPLETED. If NULL the
|
||||
* attribute is ignored
|
||||
* @param isCompleted TRUE/FALSE are compared to the attribute COMPLETED. If NULL the attribute is ignored
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> isCompleted(final Boolean isCompleted) {
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.<Boolean> get(JpaDistributionSet_.complete), isCompleted);
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.complete), isCompleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its VALID
|
||||
* attribute.
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by its VALID attribute.
|
||||
*
|
||||
* @param isValid TRUE/FALSE are compared to the attribute VALID. If NULL the
|
||||
* attribute is ignored
|
||||
* @param isValid TRUE/FALSE are compared to the attribute VALID. If NULL the attribute is ignored
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> isValid(final Boolean isValid) {
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.<Boolean> get(JpaDistributionSet_.valid), isValid);
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.valid), isValid);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given
|
||||
* {@link DistributionSet#getId()}.
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given {@link DistributionSet#getId()}.
|
||||
*
|
||||
* @param distid to search
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> byId(final Long distid) {
|
||||
public static Specification<JpaDistributionSet> byIdFetch(final Long distid) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Predicate predicate = cb.equal(dsRoot.<Long> get(JpaDistributionSet_.id), distid);
|
||||
final Predicate predicate = cb.equal(dsRoot.get(JpaDistributionSet_.id), distid);
|
||||
dsRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
|
||||
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
|
||||
query.distinct(true);
|
||||
@@ -109,15 +94,14 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given
|
||||
* {@link DistributionSet#getId()}s.
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given {@link DistributionSet#getId()}s.
|
||||
*
|
||||
* @param distids to search
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> byIds(final Collection<Long> distids) {
|
||||
public static Specification<JpaDistributionSet> byIdsFetch(final Collection<Long> distids) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Predicate predicate = dsRoot.<Long> get(JpaDistributionSet_.id).in(distids);
|
||||
final Predicate predicate = dsRoot.get(JpaDistributionSet_.id).in(distids);
|
||||
dsRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
|
||||
dsRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
|
||||
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
|
||||
@@ -127,8 +111,7 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "like name
|
||||
* and like version".
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "like name and like version".
|
||||
*
|
||||
* @param name to be filtered on
|
||||
* @param version to be filtered on
|
||||
@@ -136,20 +119,18 @@ public final class DistributionSetSpecification {
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> likeNameAndVersion(final String name, final String version) {
|
||||
return (dsRoot, query, cb) -> cb.and(
|
||||
cb.like(cb.lower(dsRoot.<String> get(JpaDistributionSet_.name)), name.toLowerCase()),
|
||||
cb.like(cb.lower(dsRoot.<String> get(JpaDistributionSet_.version)), version.toLowerCase()));
|
||||
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
|
||||
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "has at
|
||||
* least one of the given tag names".
|
||||
* {@link Specification} for retrieving {@link DistributionSet}s by "has at least one of the given tag names".
|
||||
*
|
||||
* @param tagNames to be filtered on
|
||||
* @param selectDSWithNoTag flag to select distribution sets with no tag
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> hasTags(final Collection<String> tagNames,
|
||||
final Boolean selectDSWithNoTag) {
|
||||
public static Specification<JpaDistributionSet> hasTags(final Collection<String> tagNames, final Boolean selectDSWithNoTag) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Predicate predicate = getHasTagsPredicate(dsRoot, cb, selectDSWithNoTag, tagNames);
|
||||
query.distinct(true);
|
||||
@@ -158,36 +139,30 @@ public final class DistributionSetSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns query criteria {@link Specification} comparing case insensitive "NAME
|
||||
* == AND VERSION ==".
|
||||
* returns query criteria {@link Specification} comparing case insensitive "NAME == AND VERSION ==".
|
||||
*
|
||||
* @param name to be filtered on
|
||||
* @param version to be filtered on
|
||||
* @return the {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> equalsNameAndVersionIgnoreCase(final String name,
|
||||
final String version) {
|
||||
public static Specification<JpaDistributionSet> equalsNameAndVersionIgnoreCase(final String name, final String version) {
|
||||
return (dsRoot, query, cb) -> cb.and(
|
||||
cb.equal(cb.lower(dsRoot.<String> get(JpaDistributionSet_.name)), name.toLowerCase()),
|
||||
cb.equal(cb.lower(dsRoot.<String> get(JpaDistributionSet_.version)), version.toLowerCase()));
|
||||
|
||||
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
|
||||
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given
|
||||
* {@link DistributionSet#getType()}.
|
||||
* {@link Specification} for retrieving {@link DistributionSet} with given {@link DistributionSet#getType()}.
|
||||
*
|
||||
* @param typeId id of distribution set type to search
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> byType(final Long typeId) {
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.type).get(JpaDistributionSetType_.id),
|
||||
typeId);
|
||||
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.type).get(JpaDistributionSetType_.id), typeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Specification} for retrieving {@link DistributionSet} for given id
|
||||
* collection of {@link DistributionSet#getType()}.
|
||||
* {@link Specification} for retrieving {@link DistributionSet} for given id collection of {@link DistributionSet#getType()}.
|
||||
*
|
||||
* @param typeIds id collection of distribution set type to search
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
@@ -203,54 +178,16 @@ public final class DistributionSetSpecification {
|
||||
* @return the {@link DistributionSet} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> hasTag(final Long tagId) {
|
||||
|
||||
return (dsRoot, query, cb) -> {
|
||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags,
|
||||
JoinType.LEFT);
|
||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
|
||||
return cb.equal(tags.get(JpaDistributionSetTag_.id), tagId);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be added to specification chain to order result by provided target
|
||||
*
|
||||
* Order: 1. Distribution set installed on target, 2. Distribution set(s)
|
||||
* assigned to target, 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 linkedControllerId controller id to get installed/assigned DS for
|
||||
* @param sort
|
||||
* @return specification that applies order by target, may be overwritten
|
||||
*/
|
||||
public static Specification<JpaDistributionSet> orderedByLinkedTarget(final String linkedControllerId,
|
||||
final Sort sort) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Root<JpaTarget> targetRoot = query.from(JpaTarget.class);
|
||||
|
||||
final Expression<Object> assignedInstalledCase = cb.selectCase()
|
||||
.when(cb.equal(targetRoot.get(JpaTarget_.installedDistributionSet), dsRoot), 1)
|
||||
.when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet), dsRoot), 2).otherwise(3);
|
||||
|
||||
final List<Order> orders = new ArrayList<>();
|
||||
orders.add(cb.asc(assignedInstalledCase));
|
||||
if (sort == null || sort.isEmpty()) {
|
||||
orders.add(cb.asc(dsRoot.get(JpaDistributionSet_.id)));
|
||||
} else {
|
||||
orders.addAll(QueryUtils.toOrders(sort, dsRoot, cb));
|
||||
}
|
||||
query.orderBy(orders);
|
||||
|
||||
return cb.equal(targetRoot.get(JpaTarget_.controllerId), linkedControllerId);
|
||||
};
|
||||
}
|
||||
|
||||
private static Predicate getHasTagsPredicate(final Root<JpaDistributionSet> dsRoot, final CriteriaBuilder cb,
|
||||
private static Predicate getHasTagsPredicate(
|
||||
final Root<JpaDistributionSet> dsRoot, final CriteriaBuilder cb,
|
||||
final Boolean selectDSWithNoTag, final Collection<String> tagNames) {
|
||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags,
|
||||
JoinType.LEFT);
|
||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
|
||||
final Path<String> exp = tags.get(JpaDistributionSetTag_.name);
|
||||
|
||||
final List<Predicate> hasTagsPredicates = new ArrayList<>();
|
||||
@@ -261,8 +198,8 @@ public final class DistributionSetSpecification {
|
||||
hasTagsPredicates.add(exp.in(tagNames));
|
||||
}
|
||||
|
||||
return hasTagsPredicates.stream().reduce(cb::or).orElseThrow(
|
||||
() -> new RuntimeException("Neither NO_TAG, nor TAG distribution set tag filter was provided!"));
|
||||
return hasTagsPredicates.stream().reduce(cb::or)
|
||||
.orElseThrow(() -> new RuntimeException("Neither NO_TAG, nor TAG distribution set tag filter was provided!"));
|
||||
}
|
||||
|
||||
private static boolean isNoTagActive(final Boolean selectDSWithNoTag) {
|
||||
|
||||
Reference in New Issue
Block a user