Refactoring of RepostioryManagement and extending classes (#2174)

* createMetaData renamed to putMetaData
* getXXX methods returing Optional are renamed to findXXX
* unified method order (code cosmetics)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-08 14:03:04 +02:00
committed by GitHub
parent cad18fe04b
commit 6504bc26d9
55 changed files with 942 additions and 986 deletions

View File

@@ -44,7 +44,7 @@ public final class JpaManagementHelper {
}
public static <T, J extends T> Page<T> findAllWithCountBySpec(final JpaSpecificationExecutor<J> repository,
final Pageable pageable, final List<Specification<J>> specList) {
final List<Specification<J>> specList, final Pageable pageable) {
if (CollectionUtils.isEmpty(specList)) {
return convertPage(repository.findAll(Specification.where(null), pageable), pageable);
}

View File

@@ -59,7 +59,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
}
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) {
return distributionSetTypeManagement.getByKey(distributionSetTypekey)
return distributionSetTypeManagement.findByKey(distributionSetTypekey)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey));
}

View File

@@ -51,7 +51,7 @@ public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<
throw new ValidationException("type cannot be null");
}
return softwareModuleTypeManagement.getByKey(type.trim())
return softwareModuleTypeManagement.findByKey(type.trim())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim()));
}
}

View File

@@ -582,7 +582,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
public boolean updateOfflineAssignedVersion(@NotEmpty final String controllerId, final String distributionName, final String version) {
List<DistributionSetAssignmentResult> distributionSetAssignmentResults =
systemSecurityContext.runAsSystem(() ->
distributionSetManagement.getByNameAndVersion(distributionName, version).map(
distributionSetManagement.findByNameAndVersion(distributionName, version).map(
distributionSet -> deploymentManagement.offlineAssignedDistributionSets(
List.of(Map.entry(controllerId, distributionSet.getId())), controllerId))
.orElseThrow(() ->

View File

@@ -316,7 +316,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
RSQLUtility.buildRsqlSpecification(rsqlParam, ActionFields.class, virtualPropertyReplacer, database),
ActionSpecifications.byTargetControllerId(controllerId));
return JpaManagementHelper.findAllWithCountBySpec(actionRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(actionRepository, specList, pageable);
}
@Override

View File

@@ -155,8 +155,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> create(final Collection<DistributionSetCreate> creates) {
final List<JpaDistributionSet> toCreate = creates.stream().map(JpaDistributionSetCreate.class::cast)
.map(this::setDefaultTypeIfMissing).map(JpaDistributionSetCreate::build).toList();
.map(this::setDefaultTypeIfMissing)
.map(JpaDistributionSetCreate::build)
.toList();
return Collections.unmodifiableList(distributionSetRepository.saveAll(AccessController.Operation.CREATE, toCreate));
}
@@ -168,7 +169,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public DistributionSet create(final DistributionSetCreate c) {
final JpaDistributionSetCreate create = (JpaDistributionSetCreate) c;
setDefaultTypeIfMissing(create);
return distributionSetRepository.save(AccessController.Operation.CREATE, create.build());
}
@@ -207,11 +207,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return distributionSetRepository.save(set);
}
@Override
public long count() {
return distributionSetRepository.count(DistributionSetSpecification.isNotDeleted());
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -263,6 +258,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
}
@Override
public Optional<DistributionSet> get(final long id) {
return distributionSetRepository.findById(id).map(DistributionSet.class::cast);
}
@Override
public List<DistributionSet> get(final Collection<Long> ids) {
return Collections.unmodifiableList(getDistributionSets(ids));
@@ -274,8 +274,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSet> get(final long id) {
return distributionSetRepository.findById(id).map(DistributionSet.class::cast);
public long count() {
return distributionSetRepository.count(DistributionSetSpecification.isNotDeleted());
}
@Override
@@ -285,11 +285,30 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSet> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, pageable, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetFields.class, virtualPropertyReplacer,
database),
DistributionSetSpecification.isNotDeleted()));
public Page<DistributionSet> findByRsql(final String rsqlParam, final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetFields.class, virtualPropertyReplacer, database),
DistributionSetSpecification.isNotDeleted()), pageable);
}
@Override
public Optional<DistributionSet> getWithDetails(final long id) {
return distributionSetRepository
.findOne(distributionSetRepository.byIdSpec(id), JpaDistributionSet_.GRAPH_DISTRIBUTION_SET_DETAIL)
.map(DistributionSet.class::cast);
}
@Override
@Transactional
public void invalidate(final DistributionSet distributionSet) {
final JpaDistributionSet jpaSet = (JpaDistributionSet) distributionSet;
jpaSet.invalidate();
distributionSetRepository.save(jpaSet);
}
@Override
public DistributionSet getOrElseThrowException(final long id) {
return getById(id);
}
@Override
@@ -312,6 +331,20 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return distributionSetRepository.save(set);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unassignSoftwareModule(final long id, final long moduleId) {
final JpaDistributionSet set = (JpaDistributionSet) getValid(id);
assertDistributionSetIsNotAssignedToTargets(id);
final JpaSoftwareModule module = findSoftwareModuleAndThrowExceptionIfNotFound(moduleId);
set.removeModule(module);
return distributionSetRepository.save(set);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -327,6 +360,21 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
});
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetMetadata updateMetaData(final long id, final MetaData md) {
// check if exists otherwise throw entity not found exception
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) findMetaDataByDistributionSetId(id, md.getKey())
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, id, md.getKey()));
toUpdate.setValue(md.getValue());
// touch it to update the lock revision because we are modifying the DS indirectly, it will, also check UPDATE access
JpaManagementHelper.touch(entityManager, distributionSetRepository, (JpaDistributionSet) getValid(id));
return distributionSetMetadataRepository.save(toUpdate);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -346,7 +394,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetMetadata> createMetaData(final long id, final Collection<MetaData> md) {
public List<DistributionSetMetadata> putMetaData(final long id, final Collection<MetaData> md) {
final JpaDistributionSet distributionSet = (JpaDistributionSet) getValid(id);
assertMetaDataQuota(id, md.size());
@@ -366,7 +414,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetaData(final long id, final String key) {
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) findMetaDataByDistributionSetId(
id, key)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, id, key));
@@ -403,7 +451,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSet> getByAction(final long actionId) {
public Optional<DistributionSet> findByAction(final long actionId) {
return actionRepository
.findById(actionId)
.map(action -> {
@@ -422,14 +470,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSet> getWithDetails(final long id) {
return distributionSetRepository
.findOne(distributionSetRepository.byIdSpec(id), JpaDistributionSet_.GRAPH_DISTRIBUTION_SET_DETAIL)
.map(DistributionSet.class::cast);
}
@Override
public Optional<DistributionSet> getByNameAndVersion(final String distributionName, final String version) {
public Optional<DistributionSet> findByNameAndVersion(final String distributionName, final String version) {
return distributionSetRepository
.findOne(DistributionSetSpecification.equalsNameAndVersionIgnoreCase(distributionName, version))
.map(DistributionSet.class::cast);
@@ -465,17 +506,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public DistributionSet getOrElseThrowException(final long id) {
return getById(id);
}
@Override
public Page<DistributionSetMetadata> findMetaDataByDistributionSetId(final Pageable pageable,
final long id) {
public Page<DistributionSetMetadata> findMetaDataByDistributionSetId(final long id, final Pageable pageable) {
assertDistributionSetExists(id);
return JpaManagementHelper.findAllWithCountBySpec(distributionSetMetadataRepository, pageable,
Collections.singletonList(byDsIdSpec(id)));
return JpaManagementHelper.findAllWithCountBySpec(distributionSetMetadataRepository, Collections.singletonList(byDsIdSpec(id)), pageable
);
}
@Override
@@ -486,15 +521,15 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSetMetadata> findMetaDataByDistributionSetIdAndRsql(final Pageable pageable,
final long id, final String rsqlParam) {
public Page<DistributionSetMetadata> findMetaDataByDistributionSetIdAndRsql(final long id, final String rsqlParam,
final Pageable pageable) {
assertDistributionSetExists(id);
final List<Specification<JpaDistributionSetMetadata>> specList = Arrays
.asList(RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetMetadataFields.class,
virtualPropertyReplacer, database), byDsIdSpec(id));
return JpaManagementHelper.findAllWithCountBySpec(distributionSetMetadataRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(distributionSetMetadataRepository, specList, pageable);
}
@Override
@@ -512,8 +547,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Slice<DistributionSet> findByDistributionSetFilter(final Pageable pageable,
final DistributionSetFilter distributionSetFilter) {
public Slice<DistributionSet> findByDistributionSetFilter(final DistributionSetFilter distributionSetFilter, final Pageable pageable) {
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
distributionSetFilter);
@@ -527,25 +561,25 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSet> findByTag(final Pageable pageable, final long tagId) {
public Page<DistributionSet> findByTag(final long tagId, final Pageable pageable) {
assertDsTagExists(tagId);
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, pageable, List.of(
DistributionSetSpecification.hasTag(tagId)));
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, List.of(
DistributionSetSpecification.hasTag(tagId)), pageable);
}
@Override
public Page<DistributionSet> findByRsqlAndTag(final Pageable pageable, final String rsqlParam, final long tagId) {
public Page<DistributionSet> findByRsqlAndTag(final String rsqlParam, final long tagId, final Pageable pageable) {
assertDsTagExists(tagId);
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, pageable, List.of(
return JpaManagementHelper.findAllWithCountBySpec(distributionSetRepository, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetFields.class, virtualPropertyReplacer,
database),
DistributionSetSpecification.hasTag(tagId), DistributionSetSpecification.isNotDeleted()));
DistributionSetSpecification.hasTag(tagId), DistributionSetSpecification.isNotDeleted()), pageable);
}
@Override
public Optional<DistributionSetMetadata> getMetaDataByDistributionSetId(final long id, final String key) {
public Optional<DistributionSetMetadata> findMetaDataByDistributionSetId(final long id, final String key) {
assertDistributionSetExists(id);
return distributionSetMetadataRepository
@@ -553,42 +587,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
.map(DistributionSetMetadata.class::cast);
}
@Override
public boolean isInUse(final long id) {
assertDistributionSetExists(id);
return actionRepository.countByDistributionSetId(id) > 0;
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unassignSoftwareModule(final long id, final long moduleId) {
final JpaDistributionSet set = (JpaDistributionSet) getValid(id);
assertDistributionSetIsNotAssignedToTargets(id);
final JpaSoftwareModule module = findSoftwareModuleAndThrowExceptionIfNotFound(moduleId);
set.removeModule(module);
return distributionSetRepository.save(set);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetMetadata updateMetaData(final long id, final MetaData md) {
// check if exists otherwise throw entity not found exception
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(id, md.getKey())
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, id, md.getKey()));
toUpdate.setValue(md.getValue());
// touch it to update the lock revision because we are modifying the DS indirectly, it will, also check UPDATE access
JpaManagementHelper.touch(entityManager, distributionSetRepository, (JpaDistributionSet) getValid(id));
return distributionSetMetadataRepository.save(toUpdate);
}
@Override
public long countByTypeId(final long typeId) {
if (!distributionSetTypeManagement.exists(typeId)) {
@@ -598,9 +596,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return distributionSetRepository.count(DistributionSetSpecification.byType(typeId));
}
@Override
public boolean isInUse(final long id) {
assertDistributionSetExists(id);
return actionRepository.countByDistributionSetId(id) > 0;
}
@Override
public List<Statistic> countRolloutsByStatusForDistributionSet(final Long id) {
assertDistributionSetExists(id);
return distributionSetRepository.countRolloutsByStatusForDistributionSet(id).stream().map(Statistic.class::cast).toList();
}
@@ -619,14 +625,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return distributionSetRepository.countAutoAssignmentsForDistributionSet(id);
}
@Override
@Transactional
public void invalidate(final DistributionSet distributionSet) {
final JpaDistributionSet jpaSet = (JpaDistributionSet) distributionSet;
jpaSet.invalidate();
distributionSetRepository.save(jpaSet);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -635,7 +633,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return updateTag(
ids,
() -> distributionSetTagManagement
.getByName(tagName)
.findByName(tagName)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)),
(allDs, distributionSetTag) -> {
final List<JpaDistributionSet> toBeChangedDSs = allDs.stream().filter(set -> set.addTag(distributionSetTag))

View File

@@ -75,10 +75,11 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetTag> create(final Collection<TagCreate> dst) {
final List<JpaDistributionSetTag> toCreate = dst.stream().map(JpaTagCreate.class::cast)
.map(JpaTagCreate::buildDistributionSetTag).toList();
return Collections
.unmodifiableList(distributionSetTagRepository.saveAll(AccessController.Operation.CREATE, toCreate));
final List<JpaDistributionSetTag> toCreate = dst.stream()
.map(JpaTagCreate.class::cast)
.map(JpaTagCreate::buildDistributionSetTag)
.toList();
return Collections.unmodifiableList(distributionSetTagRepository.saveAll(AccessController.Operation.CREATE, toCreate));
}
@Override
@@ -87,8 +88,7 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
@PreAuthorize(SpPermission.SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
public DistributionSetTag create(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c;
return distributionSetTagRepository.save(AccessController.Operation.CREATE, create.buildDistributionSetTag());
return distributionSetTagRepository.save(AccessController.Operation.CREATE, ((JpaTagCreate) c).buildDistributionSetTag());
}
@Override
@@ -98,7 +98,6 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@PreAuthorize(SpPermission.SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
public DistributionSetTag update(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u;
final JpaDistributionSetTag tag = distributionSetTagRepository.findById(update.getId())
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, update.getId()));
@@ -109,11 +108,6 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
return distributionSetTagRepository.save(tag);
}
@Override
public long count() {
return distributionSetTagRepository.count();
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -137,6 +131,11 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
distributionSetTagRepository.deleteAll(setsFound);
}
@Override
public Optional<DistributionSetTag> get(final long id) {
return distributionSetTagRepository.findById(id).map(DistributionSetTag.class::cast);
}
@Override
public List<DistributionSetTag> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTagRepository.findAllById(ids));
@@ -148,22 +147,37 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
}
@Override
public Optional<DistributionSetTag> get(final long id) {
return distributionSetTagRepository.findById(id).map(DistributionSetTag.class::cast);
public long count() {
return distributionSetTagRepository.count();
}
@Override
public Slice<DistributionSetTag> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetTagRepository, pageable, null);
}
@Override
public Page<DistributionSetTag> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaDistributionSetTag> spec = RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetTagFields.class,
virtualPropertyReplacer, database);
public Page<DistributionSetTag> findByRsql(final String rsqlParam, final Pageable pageable) {
final Specification<JpaDistributionSetTag> spec = RSQLUtility.buildRsqlSpecification(
rsqlParam, DistributionSetTagFields.class, virtualPropertyReplacer, database);
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTagRepository, Collections.singletonList(spec), pageable);
}
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTagRepository, pageable,
Collections.singletonList(spec));
@Override
public Optional<DistributionSetTag> findByName(final String name) {
return distributionSetTagRepository.findByNameEquals(name);
}
@Override
public Page<DistributionSetTag> findByDistributionSet(final Pageable pageable, final long distributionSetId) {
if (!distributionSetRepository.existsById(distributionSetId)) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
}
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTagRepository,
Collections.singletonList(TagSpecification.ofDistributionSet(distributionSetId)), pageable
);
}
@Override
@@ -174,22 +188,6 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
final JpaDistributionSetTag dsTag = distributionSetTagRepository
.findOne(DistributionSetTagSpecifications.byName(tagName))
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
distributionSetTagRepository.delete(dsTag);
}
@Override
public Optional<DistributionSetTag> getByName(final String name) {
return distributionSetTagRepository.findByNameEquals(name);
}
@Override
public Page<DistributionSetTag> findByDistributionSet(final Pageable pageable, final long distributionSetId) {
if (!distributionSetRepository.existsById(distributionSetId)) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
}
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTagRepository, pageable,
Collections.singletonList(TagSpecification.ofDistributionSet(distributionSetId)));
}
}

View File

@@ -88,43 +88,6 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
this.quotaManagement = quotaManagement;
}
@Override
public Optional<DistributionSetType> getByKey(final String key) {
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)).map(DistributionSetType.class::cast);
}
@Override
public Optional<DistributionSetType> getByName(final String name) {
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)).map(DistributionSetType.class::cast);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignOptionalSoftwareModuleTypes(final long id, final Collection<Long> softwareModulesTypeIds) {
return assignSoftwareModuleTypes(id, softwareModulesTypeIds, false);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final long id, final Collection<Long> softwareModuleTypeIds) {
return assignSoftwareModuleTypes(id, softwareModuleTypeIds, true);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType unassignSoftwareModuleType(final long id, final long softwareModuleTypeId) {
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(id);
checkDistributionSetTypeNotAssigned(id);
type.removeModuleType(softwareModuleTypeId);
return distributionSetTypeRepository.save(type);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -184,11 +147,6 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
return distributionSetTypeRepository.save(type);
}
@Override
public long count() {
return distributionSetTypeRepository.count(DistributionSetTypeSpecification.isNotDeleted());
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -215,6 +173,11 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
distributionSetTypeRepository.deleteAllById(ids);
}
@Override
public Optional<DistributionSetType> get(final long id) {
return distributionSetTypeRepository.findById(id).map(DistributionSetType.class::cast);
}
@Override
public List<DistributionSetType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTypeRepository.findAllById(ids));
@@ -226,8 +189,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
}
@Override
public Optional<DistributionSetType> get(final long id) {
return distributionSetTypeRepository.findById(id).map(DistributionSetType.class::cast);
public long count() {
return distributionSetTypeRepository.count(DistributionSetTypeSpecification.isNotDeleted());
}
@Override
@@ -237,10 +200,47 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
}
@Override
public Page<DistributionSetType> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTypeRepository, pageable, List.of(
public Page<DistributionSetType> findByRsql(final String rsqlParam, final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(distributionSetTypeRepository, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, DistributionSetTypeFields.class, virtualPropertyReplacer, database),
DistributionSetTypeSpecification.isNotDeleted()));
DistributionSetTypeSpecification.isNotDeleted()), pageable);
}
@Override
public Optional<DistributionSetType> findByKey(final String key) {
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)).map(DistributionSetType.class::cast);
}
@Override
public Optional<DistributionSetType> findByName(final String name) {
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)).map(DistributionSetType.class::cast);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignOptionalSoftwareModuleTypes(final long id, final Collection<Long> softwareModulesTypeIds) {
return assignSoftwareModuleTypes(id, softwareModulesTypeIds, false);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final long id, final Collection<Long> softwareModuleTypeIds) {
return assignSoftwareModuleTypes(id, softwareModuleTypeIds, true);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType unassignSoftwareModuleType(final long id, final long softwareModuleTypeId) {
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(id);
checkDistributionSetTypeNotAssigned(id);
type.removeModuleType(softwareModuleTypeId);
return distributionSetTypeRepository.save(type);
}
private static void removeModuleTypes(

View File

@@ -132,7 +132,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
database),
(root, query, cb) -> cb.equal(root.get(JpaRolloutGroup_.rollout).get(JpaRollout_.id), rolloutId));
return JpaManagementHelper.findAllWithCountBySpec(rolloutGroupRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(rolloutGroupRepository, specList, pageable);
}
@Override
@@ -180,11 +180,13 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
// in case of status ready the action has not been created yet and
// the relation information between target and rollout-group is
// stored in the #TargetRolloutGroup.
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, page,
Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository,
Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)), page
);
}
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, page,
Collections.singletonList(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId)));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository,
Collections.singletonList(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId)), page
);
}
@Override
@@ -201,7 +203,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
rolloutGroupId);
});
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
}
@Override

View File

@@ -178,11 +178,6 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
return softwareModuleRepository.save(module);
}
@Override
public long count() {
return softwareModuleRepository.count(SoftwareModuleSpecification.isNotDeleted());
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -238,6 +233,11 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
}
@Override
public Optional<SoftwareModule> get(final long id) {
return softwareModuleRepository.findById(id).map(SoftwareModule.class::cast);
}
@Override
public List<SoftwareModule> get(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleRepository.findAllById(ids));
@@ -249,8 +249,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Optional<SoftwareModule> get(final long id) {
return softwareModuleRepository.findById(id).map(SoftwareModule.class::cast);
public long count() {
return softwareModuleRepository.count(SoftwareModuleSpecification.isNotDeleted());
}
@Override
@@ -261,18 +261,18 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Page<SoftwareModule> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleRepository, pageable, List.of(
public Page<SoftwareModule> findByRsql(final String rsqlParam, final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleRepository, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, SoftwareModuleFields.class, virtualPropertyReplacer,
database),
SoftwareModuleSpecification.isNotDeleted()));
SoftwareModuleSpecification.isNotDeleted()), pageable);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleMetadata> createMetaData(final Collection<SoftwareModuleMetadataCreate> create) {
public List<SoftwareModuleMetadata> putMetaData(final Collection<SoftwareModuleMetadataCreate> create) {
if (!create.isEmpty()) {
// check if all metadata entries refer to the same software module
final Long id = ((JpaSoftwareModuleMetadataCreate) create.iterator().next()).getSoftwareModuleId();
@@ -309,7 +309,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata createMetaData(final SoftwareModuleMetadataCreate c) {
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataCreate c) {
final JpaSoftwareModuleMetadataCreate create = (JpaSoftwareModuleMetadataCreate) c;
final Long id = create.getSoftwareModuleId();
@@ -322,12 +322,31 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
return saveMetadata(create);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) {
final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u;
// check if exists otherwise throw entity not found exception
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findMetaDataBySoftwareModuleId(
update.getSoftwareModuleId(), update.getKey())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, update.getSoftwareModuleId(), update.getKey()));
update.getValue().ifPresent(metadata::setValue);
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule());
return softwareModuleMetadataRepository.save(metadata);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetaData(final long id, final String key) {
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(id,
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findMetaDataBySoftwareModuleId(id,
key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, id, key));
JpaManagementHelper.touch(entityManager, softwareModuleRepository,
@@ -335,111 +354,6 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
softwareModuleMetadataRepository.deleteById(metadata.getId());
}
@Override
public Page<SoftwareModule> findByAssignedTo(final Pageable pageable, final long distributionSetId) {
assertDistributionSetExists(distributionSetId);
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleRepository, pageable,
Collections.singletonList(SoftwareModuleSpecification.byAssignedToDs(distributionSetId)));
}
@Override
public long countByAssignedTo(final long distributionSetId) {
assertDistributionSetExists(distributionSetId);
return softwareModuleRepository.count(SoftwareModuleSpecification.byAssignedToDs(distributionSetId));
}
@Override
public Slice<SoftwareModule> findByTextAndType(final Pageable pageable, final String searchText,
final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
specList.add(SoftwareModuleSpecification.isNotDeleted());
if (!ObjectUtils.isEmpty(searchText)) {
specList.add(buildSmSearchQuerySpec(searchText));
}
if (null != typeId) {
assertSoftwareModuleTypeExists(typeId);
specList.add(SoftwareModuleSpecification.equalType(typeId));
}
specList.add(SoftwareModuleSpecification.fetchType());
return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, pageable, specList);
}
@Override
public Optional<SoftwareModule> getByNameAndVersionAndType(final String name, final String version,
final long typeId) {
assertSoftwareModuleTypeExists(typeId);
// TODO AC - Access is restricted. This could have problem with UI when access control is enabled.
// Vaadin UI use this for validation. May need to be called via elevated access
return JpaManagementHelper
.findOneBySpec(softwareModuleRepository, List.of(
SoftwareModuleSpecification.likeNameAndVersion(name, version),
SoftwareModuleSpecification.equalType(typeId),
SoftwareModuleSpecification.fetchType()))
.map(SoftwareModule.class::cast);
}
@Override
public Optional<SoftwareModuleMetadata> getMetaDataBySoftwareModuleId(final long id, final String key) {
assertSoftwareModuleExists(id);
return softwareModuleMetadataRepository.findById(new SwMetadataCompositeKey(id, key))
.map(SoftwareModuleMetadata.class::cast);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(final Pageable pageable, final long id) {
assertSoftwareModuleExists(id);
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleMetadataRepository, pageable,
Collections.singletonList(metadataBySoftwareModuleIdSpec(id)));
}
@Override
public long countMetaDataBySoftwareModuleId(final long id) {
assertSoftwareModuleExists(id);
return softwareModuleMetadataRepository.countBySoftwareModuleId(id);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleIdAndTargetVisible(final Pageable pageable,
final long id) {
assertSoftwareModuleExists(id);
return JpaManagementHelper.convertPage(softwareModuleMetadataRepository.findBySoftwareModuleIdAndTargetVisible(
id, true, PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT)), pageable);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataByRsql(final Pageable pageable, final long id,
final String rsqlParam) {
assertSoftwareModuleExists(id);
final List<Specification<JpaSoftwareModuleMetadata>> specList = Arrays
.asList(RSQLUtility.buildRsqlSpecification(rsqlParam, SoftwareModuleMetadataFields.class,
virtualPropertyReplacer, database), metadataBySoftwareModuleIdSpec(id));
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleMetadataRepository, pageable, specList);
}
@Override
public Slice<SoftwareModule> findByType(final Pageable pageable, final long typeId) {
assertSoftwareModuleTypeExists(typeId);
return JpaManagementHelper.findAllWithoutCountBySpec(
softwareModuleRepository,
pageable,
List.of(
SoftwareModuleSpecification.equalType(typeId),
SoftwareModuleSpecification.isNotDeleted()));
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -469,22 +383,94 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) {
final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u;
public Page<SoftwareModule> findByAssignedTo(final long distributionSetId, final Pageable pageable) {
assertDistributionSetExists(distributionSetId);
// check if exists otherwise throw entity not found exception
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
update.getSoftwareModuleId(), update.getKey())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, update.getSoftwareModuleId(), update.getKey()));
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleRepository,
Collections.singletonList(SoftwareModuleSpecification.byAssignedToDs(distributionSetId)), pageable
);
}
update.getValue().ifPresent(metadata::setValue);
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
@Override
public Slice<SoftwareModule> findByTextAndType(final String searchText, final Long typeId, final Pageable pageable) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
specList.add(SoftwareModuleSpecification.isNotDeleted());
JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule());
return softwareModuleMetadataRepository.save(metadata);
if (!ObjectUtils.isEmpty(searchText)) {
specList.add(buildSmSearchQuerySpec(searchText));
}
if (null != typeId) {
assertSoftwareModuleTypeExists(typeId);
specList.add(SoftwareModuleSpecification.equalType(typeId));
}
specList.add(SoftwareModuleSpecification.fetchType());
return JpaManagementHelper.findAllWithoutCountBySpec(softwareModuleRepository, pageable, specList);
}
@Override
public Optional<SoftwareModule> findByNameAndVersionAndType(final String name, final String version,
final long typeId) {
assertSoftwareModuleTypeExists(typeId);
// TODO AC - Access is restricted. This could have problem with UI when access control is enabled.
// Vaadin UI use this for validation. May need to be called via elevated access
return JpaManagementHelper
.findOneBySpec(softwareModuleRepository, List.of(
SoftwareModuleSpecification.likeNameAndVersion(name, version),
SoftwareModuleSpecification.equalType(typeId),
SoftwareModuleSpecification.fetchType()))
.map(SoftwareModule.class::cast);
}
@Override
public Optional<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(final long id, final String key) {
assertSoftwareModuleExists(id);
return softwareModuleMetadataRepository.findById(new SwMetadataCompositeKey(id, key))
.map(SoftwareModuleMetadata.class::cast);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(final Pageable pageable, final long id) {
assertSoftwareModuleExists(id);
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleMetadataRepository,
Collections.singletonList(metadataBySoftwareModuleIdSpec(id)), pageable
);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleIdAndTargetVisible(final Pageable pageable,
final long id) {
assertSoftwareModuleExists(id);
return JpaManagementHelper.convertPage(softwareModuleMetadataRepository.findBySoftwareModuleIdAndTargetVisible(
id, true, PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT)), pageable);
}
@Override
public Page<SoftwareModuleMetadata> findMetaDataByRsql(final long id, final String rsqlParam, final Pageable pageable) {
assertSoftwareModuleExists(id);
final List<Specification<JpaSoftwareModuleMetadata>> specList = Arrays
.asList(RSQLUtility.buildRsqlSpecification(rsqlParam, SoftwareModuleMetadataFields.class,
virtualPropertyReplacer, database), metadataBySoftwareModuleIdSpec(id));
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleMetadataRepository, specList, pageable);
}
@Override
public Slice<SoftwareModule> findByType(final long typeId, final Pageable pageable) {
assertSoftwareModuleTypeExists(typeId);
return JpaManagementHelper.findAllWithoutCountBySpec(
softwareModuleRepository,
pageable,
List.of(
SoftwareModuleSpecification.equalType(typeId),
SoftwareModuleSpecification.isNotDeleted()));
}
@Override
@@ -495,6 +481,20 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
.collect(Collectors.groupingBy(o -> (Long) o[0], Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList())));
}
@Override
public long countByAssignedTo(final long distributionSetId) {
assertDistributionSetExists(distributionSetId);
return softwareModuleRepository.count(SoftwareModuleSpecification.byAssignedToDs(distributionSetId));
}
@Override
public long countMetaDataBySoftwareModuleId(final long id) {
assertSoftwareModuleExists(id);
return softwareModuleMetadataRepository.countBySoftwareModuleId(id);
}
private static Stream<JpaSoftwareModuleMetadataCreate> createJpaMetadataCreateStream(
final Collection<SoftwareModuleMetadataCreate> create) {
return create.stream().map(JpaSoftwareModuleMetadataCreate.class::cast);

View File

@@ -69,27 +69,6 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
this.database = database;
}
@Override
public Optional<SoftwareModuleType> getByKey(final String key) {
return softwareModuleTypeRepository.findByKey(key);
}
@Override
public Optional<SoftwareModuleType> getByName(final String name) {
return softwareModuleTypeRepository.findByName(name);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleType> create(final Collection<SoftwareModuleTypeCreate> c) {
final List<JpaSoftwareModuleType> creates = c.stream().map(JpaSoftwareModuleTypeCreate.class::cast)
.map(JpaSoftwareModuleTypeCreate::build).toList();
return Collections.unmodifiableList(
softwareModuleTypeRepository.saveAll(AccessController.Operation.CREATE, creates));
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -118,11 +97,6 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
return softwareModuleTypeRepository.save(type);
}
@Override
public long count() {
return softwareModuleTypeRepository.count(SoftwareModuleTypeSpecification.isNotDeleted());
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
@@ -144,6 +118,11 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
.forEach(this::delete);
}
@Override
public Optional<SoftwareModuleType> get(final long id) {
return softwareModuleTypeRepository.findById(id).map(SoftwareModuleType.class::cast);
}
@Override
public List<SoftwareModuleType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleTypeRepository.findAllById(ids));
@@ -155,8 +134,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
}
@Override
public Optional<SoftwareModuleType> get(final long id) {
return softwareModuleTypeRepository.findById(id).map(SoftwareModuleType.class::cast);
public long count() {
return softwareModuleTypeRepository.count(SoftwareModuleTypeSpecification.isNotDeleted());
}
@Override
@@ -166,12 +145,33 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
}
@Override
public Page<SoftwareModuleType> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleTypeRepository, pageable,
List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, SoftwareModuleTypeFields.class,
virtualPropertyReplacer, database),
SoftwareModuleTypeSpecification.isNotDeleted()));
public Page<SoftwareModuleType> findByRsql(final String rsqlParam, final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(softwareModuleTypeRepository, List.of(
RSQLUtility.buildRsqlSpecification(rsqlParam, SoftwareModuleTypeFields.class,
virtualPropertyReplacer, database),
SoftwareModuleTypeSpecification.isNotDeleted()), pageable
);
}
@Override
public Optional<SoftwareModuleType> findByKey(final String key) {
return softwareModuleTypeRepository.findByKey(key);
}
@Override
public Optional<SoftwareModuleType> findByName(final String name) {
return softwareModuleTypeRepository.findByName(name);
}
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleType> create(final Collection<SoftwareModuleTypeCreate> c) {
final List<JpaSoftwareModuleType> creates = c.stream().map(JpaSoftwareModuleTypeCreate.class::cast)
.map(JpaSoftwareModuleTypeCreate::build).toList();
return Collections.unmodifiableList(
softwareModuleTypeRepository.saveAll(AccessController.Operation.CREATE, creates));
}
private void delete(JpaSoftwareModuleType toDelete) {

View File

@@ -192,7 +192,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
TargetFilterQueryFields.class, virtualPropertyReplacer, database))
: Collections.emptyList();
return JpaManagementHelper.findAllWithCountBySpec(targetFilterQueryRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetFilterQueryRepository, specList, pageable);
}
@Override
@@ -225,7 +225,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
virtualPropertyReplacer, database));
}
return JpaManagementHelper.findAllWithCountBySpec(targetFilterQueryRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetFilterQueryRepository, specList, pageable);
}
@Override

View File

@@ -345,7 +345,7 @@ public class JpaTargetManagement implements TargetManagement {
TargetSpecifications.failedActionsForRollout(rolloutId),
TargetSpecifications.isNotInRolloutGroups(groups));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageRequest, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageRequest);
}
@Override
@@ -382,8 +382,9 @@ public class JpaTargetManagement implements TargetManagement {
public Page<Target> findByAssignedDistributionSet(final Pageable pageReq, final long distributionSetId) {
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageReq,
List.of(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId())));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository,
List.of(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId())), pageReq
);
}
@Override
@@ -395,7 +396,7 @@ public class JpaTargetManagement implements TargetManagement {
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database),
TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageReq, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageReq);
}
@Override
@@ -419,8 +420,9 @@ public class JpaTargetManagement implements TargetManagement {
public Page<Target> findByInstalledDistributionSet(final Pageable pageReq, final long distributionSetId) {
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageReq,
List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository,
List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq
);
}
@Override
@@ -432,13 +434,14 @@ public class JpaTargetManagement implements TargetManagement {
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database),
TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
}
@Override
public Page<Target> findByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) {
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageable,
List.of(TargetSpecifications.hasTargetUpdateStatus(status)));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.hasTargetUpdateStatus(status)),
pageable
);
}
@Override
@@ -466,8 +469,8 @@ public class JpaTargetManagement implements TargetManagement {
public Page<Target> findByTag(final Pageable pageable, final long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageable,
List.of(TargetSpecifications.hasTag(tagId)));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.hasTag(tagId)), pageable
);
}
@Override
@@ -478,7 +481,7 @@ public class JpaTargetManagement implements TargetManagement {
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database),
TargetSpecifications.hasTag(tagId));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
}
@Override
@@ -685,8 +688,9 @@ public class JpaTargetManagement implements TargetManagement {
@Override
public Page<Target> findByControllerAttributesRequested(final Pageable pageReq) {
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, pageReq,
List.of(TargetSpecifications.hasRequestControllerAttributesTrue()));
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.hasRequestControllerAttributesTrue()),
pageReq
);
}
@Override
@@ -770,8 +774,9 @@ public class JpaTargetManagement implements TargetManagement {
public Page<TargetMetadata> findMetaDataByControllerId(final Pageable pageable, final String controllerId) {
final Long id = getByControllerIdAndThrowIfNotFound(controllerId).getId();
return JpaManagementHelper.findAllWithCountBySpec(targetMetadataRepository, pageable,
Collections.singletonList(metadataByTargetIdSpec(id)));
return JpaManagementHelper.findAllWithCountBySpec(targetMetadataRepository, Collections.singletonList(metadataByTargetIdSpec(id)),
pageable
);
}
@Override
@@ -791,7 +796,7 @@ public class JpaTargetManagement implements TargetManagement {
.buildRsqlSpecification(rsqlParam, TargetMetadataFields.class, virtualPropertyReplacer, database),
metadataByTargetIdSpec(targetId));
return JpaManagementHelper.findAllWithCountBySpec(targetMetadataRepository, pageable, specList);
return JpaManagementHelper.findAllWithCountBySpec(targetMetadataRepository, specList, pageable);
}
@Override

View File

@@ -99,13 +99,13 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override
public Page<TargetTag> findAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, pageable, null);
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, null, pageable);
}
@Override
public Page<TargetTag> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, pageable, Collections.singletonList(
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetTagFields.class, virtualPropertyReplacer, database)));
return JpaManagementHelper.findAllWithCountBySpec(targetTagRepository, Collections.singletonList(
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetTagFields.class, virtualPropertyReplacer, database)), pageable);
}
@Override

View File

@@ -144,10 +144,10 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override
public Page<TargetType> findByRsql(final Pageable pageable, final String rsqlParam) {
return JpaManagementHelper.findAllWithCountBySpec(targetTypeRepository, pageable,
List.of(
RSQLUtility.buildRsqlSpecification(
rsqlParam, TargetTypeFields.class, virtualPropertyReplacer, database)));
return JpaManagementHelper.findAllWithCountBySpec(targetTypeRepository, List.of(
RSQLUtility.buildRsqlSpecification(
rsqlParam, TargetTypeFields.class, virtualPropertyReplacer, database)), pageable
);
}
@Override