Add existsByInstalledOrAssignedDistributionSet (#1064)

Signed-off-by: Florian Ruschbaschan <Florian.Ruschbaschan@bosch.io>
This commit is contained in:
Florian Ruschbaschan
2021-01-12 11:29:48 +01:00
committed by GitHub
parent 2191db40d7
commit 8816396d18
5 changed files with 44 additions and 3 deletions

View File

@@ -646,6 +646,13 @@ public class JpaTargetManagement implements TargetManagement {
return targetRepository.countByInstalledDistributionSetId(distId);
}
@Override
public boolean existsByInstalledOrAssignedDistributionSet(final long distId) {
throwEntityNotFoundIfDsDoesNotExist(distId);
return targetRepository.existsByInstalledOrAssignedDistributionSet(distId);
}
@Override
public Page<Target> findByTargetFilterQueryAndNonDS(final Pageable pageRequest, final long distributionSetId,
final String targetFilterQuery) {

View File

@@ -208,6 +208,16 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
*/
Long countByInstalledDistributionSetId(Long distId);
/**
* Checks if there is already a {@link Target} that has the given distribution set Id assigned or installed.
*
* @param distId
* to check
* @return <code>true</code> if a {@link Target} exists.
*/
@Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaTarget t WHERE t.installedDistributionSet.id=:distId OR t.assignedDistributionSet.id=:distId")
boolean existsByInstalledOrAssignedDistributionSet(@Param("distId") Long distId);
/**
* Finds all {@link Target}s in the repository.
*