Complete repository refactoring - method renaming (#575)

* Split Tag management

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Repo method naming schame applied.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* findAll returns slice instead of page.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Complete javadoc.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Allow null values again.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Readability improvements.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Forgot a method.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fixed broken completed filter.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-09-22 08:22:41 +02:00
committed by GitHub
parent 68523cd8de
commit edae83a1b5
211 changed files with 3796 additions and 4160 deletions

View File

@@ -47,22 +47,9 @@ public interface DistributionSetRepository
* to be found
* @return list of found {@link DistributionSet}s
*/
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag")
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag and ds.deleted = 0")
Page<JpaDistributionSet> findByTag(Pageable pageable, @Param("tag") final Long tagId);
/**
* Finds {@link DistributionSet}s by assigned {@link Tag}.
*
* @param pageable
* paging and sorting information
*
* @param tagId
* to be found
* @return page of found {@link DistributionSet}s
*/
@Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tagId")
Page<JpaDistributionSet> findByTagId(Pageable pageable, @Param("tagId") final Long tagId);
/**
* deletes the {@link DistributionSet}s with the given IDs.
*
@@ -175,4 +162,5 @@ public interface DistributionSetRepository
@Transactional
@Query("DELETE FROM JpaDistributionSet t WHERE t.tenant = :tenant")
void deleteByTenant(@Param("tenant") String tenant);
}

View File

@@ -82,4 +82,9 @@ public interface DistributionSetTagRepository
@Transactional
@Query("DELETE FROM JpaDistributionSetTag t WHERE t.tenant = :tenant")
void deleteByTenant(@Param("tenant") String tenant);
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaDistributionSetTag d WHERE d.id IN ?1")
List<JpaDistributionSetTag> findAll(Iterable<Long> ids);
}

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import java.util.List;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
@@ -48,7 +50,7 @@ public interface DistributionSetTypeRepository
* count or all undeleted.
* @return number of {@link DistributionSetType}s in the repository.
*/
Long countByDeleted(boolean isDeleted);
long countByDeleted(boolean isDeleted);
/**
* Counts all distribution set type where a specific software module type is
@@ -60,7 +62,7 @@ public interface DistributionSetTypeRepository
* @return the number of {@link DistributionSetType}s in the repository
* assigned to the given software module type
*/
Long countByElementsSmType(JpaSoftwareModuleType softwareModuleType);
long countByElementsSmType(JpaSoftwareModuleType softwareModuleType);
/**
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
@@ -75,4 +77,9 @@ public interface DistributionSetTypeRepository
@Transactional
@Query("DELETE FROM JpaDistributionSetType t WHERE t.tenant = :tenant")
void deleteByTenant(@Param("tenant") String tenant);
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaDistributionSetType d WHERE d.id IN ?1")
List<JpaDistributionSetType> findAll(Iterable<Long> ids);
}

View File

@@ -85,7 +85,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename,
public Artifact create(final InputStream stream, final Long moduleId, final String filename,
final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting,
final String contentType) {
AbstractDbArtifact result = null;
@@ -137,8 +137,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteArtifact(final Long id) {
final JpaArtifact existing = (JpaArtifact) findArtifact(id)
public void delete(final Long id) {
final JpaArtifact existing = (JpaArtifact) get(id)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, id));
clearArtifactBinary(existing.getSha1Hash(), existing.getSoftwareModule().getId());
@@ -149,29 +149,29 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
@Override
public Optional<Artifact> findArtifact(final Long id) {
public Optional<Artifact> get(final Long id) {
return Optional.ofNullable(localArtifactRepository.findOne(id));
}
@Override
public Optional<Artifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
public Optional<Artifact> getByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId);
return localArtifactRepository.findFirstByFilenameAndSoftwareModuleId(filename, softwareModuleId);
}
@Override
public Optional<Artifact> findFirstArtifactBySHA1(final String sha1Hash) {
public Optional<Artifact> findFirstBySHA1(final String sha1Hash) {
return localArtifactRepository.findFirstBySha1Hash(sha1Hash);
}
@Override
public Optional<Artifact> findArtifactByFilename(final String filename) {
public Optional<Artifact> getByFilename(final String filename) {
return localArtifactRepository.findFirstByFilename(filename);
}
@Override
public Page<Artifact> findArtifactBySoftwareModule(final Pageable pageReq, final Long swId) {
public Page<Artifact> findBySoftwareModule(final Pageable pageReq, final Long swId) {
throwExceptionIfSoftwareModuleDoesNotExist(swId);
return localArtifactRepository.findBySoftwareModuleId(pageReq, swId);
@@ -206,13 +206,13 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename,
public Artifact create(final InputStream inputStream, final Long moduleId, final String filename,
final boolean overrideExisting) {
return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null);
return create(inputStream, moduleId, filename, null, null, overrideExisting, null);
}
@Override
public Long countArtifactsAll() {
public long count() {
return localArtifactRepository.count();
}

View File

@@ -483,12 +483,12 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
public Optional<Target> findByControllerId(final String controllerId) {
public Optional<Target> getByControllerId(final String controllerId) {
return targetRepository.findByControllerId(controllerId);
}
@Override
public Optional<Target> findByTargetId(final Long targetId) {
public Optional<Target> get(final Long targetId) {
return Optional.ofNullable(targetRepository.findOne(targetId));
}
@@ -522,4 +522,9 @@ public class JpaControllerManagement implements ControllerManagement {
return messages.getContent();
}
@Override
public Optional<SoftwareModule> getSoftwareModule(final Long id) {
return Optional.ofNullable(softwareModuleRepository.findOne(id));
}
}

View File

@@ -496,14 +496,14 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
@Override
public Long countActionsByTarget(final String controllerId) {
public long countActionsByTarget(final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return actionRepository.countByTargetControllerId(controllerId);
}
@Override
public Long countActionsByTarget(final String rsqlParam, final String controllerId) {
public long countActionsByTarget(final String rsqlParam, final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return actionRepository.count(createSpecificationFor(controllerId, rsqlParam));
@@ -578,12 +578,12 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
@Override
public Long countActionStatusAll() {
public long countActionStatusAll() {
return actionStatusRepository.count();
}
@Override
public Long countActionsAll() {
public long countActionsAll() {
return actionRepository.count();
}

View File

@@ -21,9 +21,9 @@ import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.DistributionSetFields;
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.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
import org.eclipse.hawkbit.repository.builder.DistributionSetUpdate;
import org.eclipse.hawkbit.repository.builder.GenericDistributionSetUpdate;
@@ -63,6 +63,7 @@ import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -88,7 +89,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private DistributionSetRepository distributionSetRepository;
@Autowired
private TagManagement tagManagement;
private DistributionSetTagManagement distributionSetTagManagement;
@Autowired
private SystemManagement systemManagement;
@@ -105,6 +106,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Autowired
private ActionRepository actionRepository;
@Autowired
private NoCountPagingRepository criteriaNoCountDao;
@Autowired
private ApplicationEventPublisher eventPublisher;
@@ -127,13 +131,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
private AfterTransactionCommitExecutor afterCommit;
@Override
public Optional<DistributionSet> findDistributionSetByIdWithDetails(final Long distid) {
public Optional<DistributionSet> getWithDetails(final Long distid) {
return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)));
}
@Override
public Optional<DistributionSet> findDistributionSetById(final Long distid) {
return Optional.ofNullable(distributionSetRepository.findOne(distid));
public long countByTypeId(final Long typeId) {
if (!distributionSetTypeManagement.exists(typeId)) {
throw new EntityNotFoundException(DistributionSetType.class, typeId);
}
return distributionSetRepository.countByTypeId(typeId);
}
@Override
@@ -148,7 +156,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));
}
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName)
final DistributionSetTag myTag = distributionSetTagManagement.getByName(tagName)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
DistributionSetTagAssignmentResult result;
@@ -189,7 +197,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet updateDistributionSet(final DistributionSetUpdate u) {
public DistributionSet update(final DistributionSetUpdate u) {
final GenericDistributionSetUpdate update = (GenericDistributionSetUpdate) u;
final JpaDistributionSet set = findDistributionSetAndThrowExceptionIfNotFound(update.getId());
@@ -217,13 +225,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final String key) {
return (JpaDistributionSetType) distributionSetTypeManagement.findDistributionSetTypeByKey(key)
return (JpaDistributionSetType) distributionSetTypeManagement.getByKey(key)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, key));
}
private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
return (JpaDistributionSet) findDistributionSetById(setId)
return (JpaDistributionSet) get(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
}
@@ -236,8 +244,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteDistributionSet(final Collection<Long> distributionSetIDs) {
final List<DistributionSet> setsFound = findDistributionSetsById(distributionSetIDs);
public void delete(final Collection<Long> distributionSetIDs) {
final List<DistributionSet> setsFound = get(distributionSetIDs);
if (setsFound.size() < distributionSetIDs.size()) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs,
@@ -275,7 +283,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet createDistributionSet(final DistributionSetCreate c) {
public DistributionSet create(final DistributionSetCreate c) {
final JpaDistributionSetCreate create = (JpaDistributionSetCreate) c;
if (create.getType() == null) {
create.type(systemManagement.getTenantMetadata().getDefaultDsType().getKey());
@@ -288,8 +296,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> createDistributionSets(final Collection<DistributionSetCreate> creates) {
return creates.stream().map(this::createDistributionSet).collect(Collectors.toList());
public List<DistributionSet> create(final Collection<DistributionSetCreate> creates) {
return creates.stream().map(this::create).collect(Collectors.toList());
}
@Override
@@ -329,7 +337,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSet> findDistributionSetsByFilters(final Pageable pageable,
public Page<DistributionSet> findByDistributionSetFilter(final Pageable pageable,
final DistributionSetFilter distributionSetFilter) {
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
distributionSetFilter);
@@ -341,6 +349,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Slice<DistributionSet> convertDsPage(final Slice<JpaDistributionSet> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
/**
*
* @param distributionSetFilter
@@ -359,52 +372,21 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSet> findDistributionSetsByDeletedAndOrCompleted(final Pageable pageReq,
final Boolean deleted, final Boolean complete) {
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(2);
if (deleted != null) {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification.isDeleted(deleted);
specList.add(spec);
}
public Page<DistributionSet> findByCompleted(final Pageable pageReq, final Boolean complete) {
List<Specification<JpaDistributionSet>> specList;
if (complete != null) {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification.isCompleted(complete);
specList.add(spec);
specList = Arrays.asList(DistributionSetSpecification.isDeleted(false),
DistributionSetSpecification.isCompleted(complete));
} else {
specList = Arrays.asList(DistributionSetSpecification.isDeleted(false));
}
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@Override
public Page<DistributionSet> findDistributionSetsAll(final String rsqlParam, final Pageable pageReq,
final Boolean deleted) {
final Specification<JpaDistributionSet> spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyReplacer);
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(2);
if (deleted != null) {
specList.add(DistributionSetSpecification.isDeleted(deleted));
}
specList.add(spec);
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@Override
public Page<DistributionSet> findDistributionSetsAll(final Pageable pageReq, final Boolean deleted) {
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(1);
if (deleted != null) {
specList.add(DistributionSetSpecification.isDeleted(deleted));
}
return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq);
}
@Override
public Page<DistributionSet> findDistributionSetsAllOrderedByLinkTarget(final Pageable pageable,
public Page<DistributionSet> findByFilterAndAssignedInstalledDsOrderedByLinkTarget(final Pageable pageable,
final DistributionSetFilterBuilder distributionSetFilterBuilder, final String assignedOrInstalled) {
final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder
@@ -421,7 +403,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
.setAssignedTargetId(null).build();
// first fine the distribution sets filtered by the given filter
// parameters
final Page<DistributionSet> findDistributionSetsByFilters = findDistributionSetsByFilters(pageable,
final Page<DistributionSet> findDistributionSetsByFilters = findByDistributionSetFilter(pageable,
dsFilterWithNoTargetLinked);
final List<DistributionSet> resultSet = new ArrayList<>(findDistributionSetsByFilters.getContent());
@@ -446,8 +428,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSet> findDistributionSetByNameAndVersion(final String distributionName,
final String version) {
public Optional<DistributionSet> getByNameAndVersion(final String distributionName, final String version) {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification
.equalsNameAndVersionIgnoreCase(distributionName, version);
return Optional.ofNullable(distributionSetRepository.findOne(spec));
@@ -455,7 +436,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Long countDistributionSetsAll() {
public long count() {
final Specification<JpaDistributionSet> spec = DistributionSetSpecification.isDeleted(Boolean.FALSE);
return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(Arrays.asList(spec)));
@@ -465,7 +446,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetMetadata> createDistributionSetMetadata(final Long dsId, final Collection<MetaData> md) {
public List<DistributionSetMetadata> createMetaData(final Long dsId, final Collection<MetaData> md) {
md.forEach(meta -> checkAndThrowAlreadyIfDistributionSetMetadataExists(
new DsMetadataCompositeKey(dsId, meta.getKey())));
@@ -482,10 +463,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetMetadata updateDistributionSetMetadata(final Long dsId, final MetaData md) {
public DistributionSetMetadata updateMetaData(final Long dsId, final MetaData md) {
// check if exists otherwise throw entity not found exception
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) findDistributionSetMetadata(dsId,
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(dsId,
md.getKey()).orElseThrow(
() -> new EntityNotFoundException(DistributionSetMetadata.class, dsId, md.getKey()));
toUpdate.setValue(md.getValue());
@@ -499,8 +480,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteDistributionSetMetadata(final Long distributionSetId, final String key) {
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) findDistributionSetMetadata(
public void deleteMetaData(final Long distributionSetId, final String key) {
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(
distributionSetId, key).orElseThrow(
() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, key));
@@ -535,13 +516,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
* of the DS to touch
*/
private JpaDistributionSet touch(final Long distId) {
return touch(findDistributionSetById(distId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distId)));
return touch(get(distId).orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distId)));
}
@Override
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
final Pageable pageable) {
public Page<DistributionSetMetadata> findMetaDataByDistributionSetId(final Pageable pageable,
final Long distributionSetId) {
throwExceptionIfDistributionSetDoesNotExist(distributionSetId);
return convertMdPage(distributionSetMetadataRepository
@@ -552,8 +532,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
final String rsqlParam, final Pageable pageable) {
public Page<DistributionSetMetadata> findMetaDataByDistributionSetIdAndRsql(final Pageable pageable,
final Long distributionSetId, final String rsqlParam) {
throwExceptionIfDistributionSetDoesNotExist(distributionSetId);
@@ -575,14 +555,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSetMetadata> findDistributionSetMetadata(final Long setId, final String key) {
public Optional<DistributionSetMetadata> getMetaDataByDistributionSetId(final Long setId, final String key) {
throwExceptionIfDistributionSetDoesNotExist(setId);
return Optional.ofNullable(distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(setId, key)));
}
@Override
public Optional<DistributionSet> findDistributionSetByAction(final Long actionId) {
public Optional<DistributionSet> getByAction(final Long actionId) {
if (!actionRepository.exists(actionId)) {
throw new EntityNotFoundException(Action.class, actionId);
}
@@ -591,7 +571,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public boolean isDistributionSetInUse(final Long setId) {
public boolean isInUse(final Long setId) {
throwExceptionIfDistributionSetDoesNotExist(setId);
return actionRepository.countByDistributionSetId(setId) > 0;
@@ -693,7 +673,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
allDs.stream().map(DistributionSet::getId).collect(Collectors.toList()));
}
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
allDs.forEach(ds -> ds.addTag(distributionSetTag));
@@ -711,10 +691,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unAssignTag(final Long dsId, final Long dsTagId) {
final JpaDistributionSet set = (JpaDistributionSet) findDistributionSetByIdWithDetails(dsId)
final JpaDistributionSet set = (JpaDistributionSet) getWithDetails(dsId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, dsId));
final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId)
final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
set.removeTag(distributionSetTag);
@@ -730,10 +710,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteDistributionSet(final Long setId) {
public void delete(final Long setId) {
throwExceptionIfDistributionSetDoesNotExist(setId);
deleteDistributionSet(Arrays.asList(setId));
delete(Arrays.asList(setId));
}
private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) {
@@ -743,12 +723,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public List<DistributionSet> findDistributionSetsById(final Collection<Long> ids) {
public List<DistributionSet> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetRepository.findAll(ids));
}
@Override
public Page<DistributionSet> findDistributionSetsByTag(final Pageable pageable, final Long tagId) {
public Page<DistributionSet> findByTag(final Pageable pageable, final Long tagId) {
throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId);
return convertDsPage(distributionSetRepository.findByTag(pageable, tagId), pageable);
@@ -762,17 +742,40 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Page<DistributionSet> findDistributionSetsByTag(final Pageable pageable, final String rsqlParam,
final Long tagId) {
public Page<DistributionSet> findByRsqlAndTag(final Pageable pageable, final String rsqlParam, final Long tagId) {
throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId);
final Specification<JpaDistributionSet> spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyReplacer);
return convertDsPage(distributionSetRepository.findAll((Specification<JpaDistributionSet>) (root, query,
cb) -> cb.and(DistributionSetSpecification.hasTag(tagId).toPredicate(root, query, cb),
spec.toPredicate(root, query, cb)),
pageable), pageable);
return convertDsPage(findByCriteriaAPI(pageable, Arrays.asList(spec, DistributionSetSpecification.hasTag(tagId),
DistributionSetSpecification.isDeleted(false))), pageable);
}
@Override
public Slice<DistributionSet> findAll(final Pageable pageable) {
return convertDsPage(criteriaNoCountDao.findAll(DistributionSetSpecification.isDeleted(false), pageable,
JpaDistributionSet.class), pageable);
}
@Override
public Page<DistributionSet> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaDistributionSet> spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class,
virtualPropertyReplacer);
return convertDsPage(
findByCriteriaAPI(pageable, Arrays.asList(spec, DistributionSetSpecification.isDeleted(false))),
pageable);
}
@Override
public Optional<DistributionSet> get(final Long id) {
return Optional.ofNullable(distributionSetRepository.findOne(id));
}
@Override
public boolean exists(final Long id) {
return distributionSetRepository.exists(id);
}
}

View File

@@ -14,8 +14,9 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
import org.eclipse.hawkbit.repository.TagFields;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.builder.GenericTagUpdate;
import org.eclipse.hawkbit.repository.builder.TagCreate;
import org.eclipse.hawkbit.repository.builder.TagUpdate;
@@ -23,19 +24,16 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -43,111 +41,35 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* JP>A implementation of {@link TagManagement}.
* JPA implementation of {@link TargetTagManagement}.
*
*/
@Transactional(readOnly = true)
@Validated
public class JpaTagManagement implements TagManagement {
public class JpaDistributionSetTagManagement implements DistributionSetTagManagement {
@Autowired
private TargetTagRepository targetTagRepository;
private final DistributionSetTagRepository distributionSetTagRepository;
@Autowired
private TargetRepository targetRepository;
private final DistributionSetRepository distributionSetRepository;
@Autowired
private DistributionSetTagRepository distributionSetTagRepository;
private final VirtualPropertyReplacer virtualPropertyReplacer;
@Autowired
private DistributionSetRepository distributionSetRepository;
private final NoCountPagingRepository criteriaNoCountDao;
@Autowired
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public Optional<TargetTag> findTargetTag(final String name) {
return targetTagRepository.findByNameEquals(name);
JpaDistributionSetTagManagement(final DistributionSetTagRepository distributionSetTagRepository,
final DistributionSetRepository distributionSetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) {
this.distributionSetTagRepository = distributionSetTagRepository;
this.distributionSetRepository = distributionSetRepository;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.criteriaNoCountDao = criteriaNoCountDao;
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag createTargetTag(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c;
return targetTagRepository.save(create.buildTargetTag());
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<TargetTag> createTargetTags(final Collection<TagCreate> tt) {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection<JpaTagCreate> targetTags = (Collection) tt;
return Collections.unmodifiableList(targetTags.stream()
.map(ttc -> targetTagRepository.save(ttc.buildTargetTag())).collect(Collectors.toList()));
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTargetTag(final String targetTagName) {
if (!targetTagRepository.existsByName(targetTagName)) {
throw new EntityNotFoundException(TargetTag.class, targetTagName);
}
// finally delete the tag itself
targetTagRepository.deleteByName(targetTagName);
}
@Override
public Page<TargetTag> findAllTargetTags(final String rsqlParam, final Pageable pageable) {
final Specification<JpaTargetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer);
return convertTPage(targetTagRepository.findAll(spec, pageable), pageable);
}
private static Page<TargetTag> convertTPage(final Page<JpaTargetTag> findAll, final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Page<DistributionSetTag> convertDsPage(final Page<JpaDistributionSetTag> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
public long countTargetTags() {
return targetTagRepository.count();
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag updateTargetTag(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u;
final JpaTargetTag tag = targetTagRepository.findById(update.getId())
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, update.getId()));
update.getName().ifPresent(tag::setName);
update.getDescription().ifPresent(tag::setDescription);
update.getColour().ifPresent(tag::setColour);
return targetTagRepository.save(tag);
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetTag updateDistributionSetTag(final TagUpdate u) {
public DistributionSetTag update(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u;
final JpaDistributionSetTag tag = distributionSetTagRepository.findById(update.getId())
@@ -161,7 +83,7 @@ public class JpaTagManagement implements TagManagement {
}
@Override
public Optional<DistributionSetTag> findDistributionSetTag(final String name) {
public Optional<DistributionSetTag> getByName(final String name) {
return distributionSetTagRepository.findByNameEquals(name);
}
@@ -169,7 +91,7 @@ public class JpaTagManagement implements TagManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetTag createDistributionSetTag(final TagCreate c) {
public DistributionSetTag create(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c;
return distributionSetTagRepository.save(create.buildDistributionSetTag());
}
@@ -178,7 +100,7 @@ public class JpaTagManagement implements TagManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetTag> createDistributionSetTags(final Collection<TagCreate> dst) {
public List<DistributionSetTag> create(final Collection<TagCreate> dst) {
@SuppressWarnings({ "rawtypes", "unchecked" })
final Collection<JpaTagCreate> creates = (Collection) dst;
@@ -192,7 +114,7 @@ public class JpaTagManagement implements TagManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteDistributionSetTag(final String tagName) {
public void delete(final String tagName) {
if (!distributionSetTagRepository.existsByName(tagName)) {
throw new EntityNotFoundException(DistributionSetTag.class, tagName);
}
@@ -201,27 +123,12 @@ public class JpaTagManagement implements TagManagement {
}
@Override
public Optional<TargetTag> findTargetTagById(final Long id) {
return Optional.ofNullable(targetTagRepository.findOne(id));
public Slice<DistributionSetTag> findAll(final Pageable pageable) {
return convertDsPage(criteriaNoCountDao.findAll(pageable, JpaDistributionSetTag.class), pageable);
}
@Override
public Optional<DistributionSetTag> findDistributionSetTagById(final Long id) {
return Optional.ofNullable(distributionSetTagRepository.findOne(id));
}
@Override
public Page<TargetTag> findAllTargetTags(final Pageable pageable) {
return convertTPage(targetTagRepository.findAll(pageable), pageable);
}
@Override
public Page<DistributionSetTag> findAllDistributionSetTags(final Pageable pageable) {
return convertDsPage(distributionSetTagRepository.findAll(pageable), pageable);
}
@Override
public Page<DistributionSetTag> findAllDistributionSetTags(final String rsqlParam, final Pageable pageable) {
public Page<DistributionSetTag> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaDistributionSetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class,
virtualPropertyReplacer);
@@ -229,17 +136,7 @@ public class JpaTagManagement implements TagManagement {
}
@Override
public Page<TargetTag> findAllTargetTags(final Pageable pageable, final String controllerId) {
if (!targetRepository.existsByControllerId(controllerId)) {
throw new EntityNotFoundException(Target.class, controllerId);
}
return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable);
}
@Override
public Page<DistributionSetTag> findDistributionSetTagsByDistributionSet(final Pageable pageable,
final Long setId) {
public Page<DistributionSetTag> findByDistributionSet(final Pageable pageable, final Long setId) {
if (!distributionSetRepository.exists(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
@@ -247,4 +144,58 @@ public class JpaTagManagement implements TagManagement {
return convertDsPage(distributionSetTagRepository.findAll(TagSpecification.ofDistributionSet(setId), pageable),
pageable);
}
private static Page<DistributionSetTag> convertDsPage(final Page<JpaDistributionSetTag> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Slice<DistributionSetTag> convertDsPage(final Slice<JpaDistributionSetTag> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAll(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(DistributionSetTag.class, ids,
setsFound.stream().map(DistributionSetTag::getId).collect(Collectors.toList()));
}
distributionSetTagRepository.delete(setsFound);
}
@Override
public List<DistributionSetTag> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTagRepository.findAll(ids));
}
@Override
public Optional<DistributionSetTag> get(final Long id) {
return Optional.ofNullable(distributionSetTagRepository.findOne(id));
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Long id) {
distributionSetTagRepository.delete(id);
}
@Override
public boolean exists(final Long id) {
return distributionSetTagRepository.exists(id);
}
@Override
public long count() {
return distributionSetTagRepository.count();
}
}

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -27,6 +28,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
@@ -34,10 +36,12 @@ import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
/**
@@ -56,21 +60,24 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final NoCountPagingRepository criteriaNoCountDao;
JpaDistributionSetTypeManagement(final DistributionSetTypeRepository distributionSetTypeRepository,
final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final DistributionSetRepository distributionSetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer) {
final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) {
this.distributionSetTypeRepository = distributionSetTypeRepository;
this.softwareModuleTypeRepository = softwareModuleTypeRepository;
this.distributionSetRepository = distributionSetRepository;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.criteriaNoCountDao = criteriaNoCountDao;
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType updateDistributionSetType(final DistributionSetTypeUpdate u) {
public DistributionSetType update(final DistributionSetTypeUpdate u) {
final GenericDistributionSetTypeUpdate update = (GenericDistributionSetTypeUpdate) u;
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(update.getId());
@@ -82,9 +89,9 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(update.getId());
update.getMandatory().ifPresent(
mand -> softwareModuleTypeRepository.findByIdIn(mand).forEach(type::addMandatoryModuleType));
update.getOptional().ifPresent(
opt -> softwareModuleTypeRepository.findByIdIn(opt).forEach(type::addOptionalModuleType));
mand -> softwareModuleTypeRepository.findAll(mand).forEach(type::addMandatoryModuleType));
update.getOptional()
.ifPresent(opt -> softwareModuleTypeRepository.findAll(opt).forEach(type::addOptionalModuleType));
}
return distributionSetTypeRepository.save(type);
@@ -96,8 +103,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final Long dsTypeId,
final Collection<Long> softwareModulesTypeIds) {
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
.findByIdIn(softwareModulesTypeIds);
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
if (modules.size() < softwareModulesTypeIds.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
@@ -119,8 +125,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
public DistributionSetType assignOptionalSoftwareModuleTypes(final Long dsTypeId,
final Collection<Long> softwareModulesTypeIds) {
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
.findByIdIn(softwareModulesTypeIds);
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
if (modules.size() < softwareModulesTypeIds.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
@@ -149,37 +154,32 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
}
@Override
public Page<DistributionSetType> findDistributionSetTypesAll(final String rsqlParam, final Pageable pageable) {
final Specification<JpaDistributionSetType> spec = RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class,
virtualPropertyReplacer);
return convertDsTPage(distributionSetTypeRepository.findAll(spec, pageable));
public Page<DistributionSetType> findByRsql(final Pageable pageable, final String rsqlParam) {
return convertPage(findByCriteriaAPI(pageable,
Arrays.asList(RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class, virtualPropertyReplacer),
DistributionSetTypeSpecification.isDeleted(false))),
pageable);
}
@Override
public Page<DistributionSetType> findDistributionSetTypesAll(final Pageable pageable) {
return convertDsTPage(distributionSetTypeRepository.findByDeleted(pageable, false));
public Slice<DistributionSetType> findAll(final Pageable pageable) {
return convertPage(criteriaNoCountDao.findAll(DistributionSetTypeSpecification.isDeleted(false), pageable,
JpaDistributionSetType.class), pageable);
}
@Override
public Long countDistributionSetTypesAll() {
public long count() {
return distributionSetTypeRepository.countByDeleted(false);
}
@Override
public Optional<DistributionSetType> findDistributionSetTypeByName(final String name) {
public Optional<DistributionSetType> getByName(final String name) {
return Optional
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)));
}
@Override
public Optional<DistributionSetType> findDistributionSetTypeById(final Long typeId) {
return Optional
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(typeId)));
}
@Override
public Optional<DistributionSetType> findDistributionSetTypeByKey(final String key) {
public Optional<DistributionSetType> getByKey(final String key) {
return Optional.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)));
}
@@ -187,7 +187,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType createDistributionSetType(final DistributionSetTypeCreate c) {
public DistributionSetType create(final DistributionSetTypeCreate c) {
final JpaDistributionSetTypeCreate create = (JpaDistributionSetTypeCreate) c;
return distributionSetTypeRepository.save(create.build());
@@ -197,7 +197,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteDistributionSetType(final Long typeId) {
public void delete(final Long typeId) {
final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(typeId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, typeId));
@@ -214,21 +214,12 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetType> createDistributionSetTypes(final Collection<DistributionSetTypeCreate> types) {
return types.stream().map(this::createDistributionSetType).collect(Collectors.toList());
}
@Override
public Long countDistributionSetsByType(final Long typeId) {
if (!distributionSetTypeRepository.exists(typeId)) {
throw new EntityNotFoundException(DistributionSetType.class, typeId);
}
return distributionSetRepository.countByTypeId(typeId);
public List<DistributionSetType> create(final Collection<DistributionSetTypeCreate> types) {
return types.stream().map(this::create).collect(Collectors.toList());
}
private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final Long setId) {
return (JpaDistributionSetType) findDistributionSetTypeById(setId)
return (JpaDistributionSetType) get(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, setId));
}
@@ -243,8 +234,54 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
}
}
private static Page<DistributionSetType> convertDsTPage(final Page<JpaDistributionSetType> findAll) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()));
private static Page<DistributionSetType> convertPage(final Page<JpaDistributionSetType> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Slice<DistributionSetType> convertPage(final Slice<JpaDistributionSetType> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
private Page<JpaDistributionSetType> findByCriteriaAPI(final Pageable pageable,
final List<Specification<JpaDistributionSetType>> specList) {
if (CollectionUtils.isEmpty(specList)) {
return distributionSetTypeRepository.findAll(pageable);
}
return distributionSetTypeRepository.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable);
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaDistributionSetType> setsFound = distributionSetTypeRepository.findAll(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(DistributionSetType.class, ids,
setsFound.stream().map(DistributionSetType::getId).collect(Collectors.toList()));
}
distributionSetTypeRepository.delete(setsFound);
}
@Override
public List<DistributionSetType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(distributionSetTypeRepository.findAll(ids));
}
@Override
public Optional<DistributionSetType> get(final Long id) {
return Optional.ofNullable(distributionSetTypeRepository.findOne(id));
}
@Override
public boolean exists(final Long id) {
return distributionSetTypeRepository.exists(id);
}
}

View File

@@ -85,12 +85,12 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
private RolloutStatusCache rolloutStatusCache;
@Override
public Optional<RolloutGroup> findRolloutGroupById(final Long rolloutGroupId) {
public Optional<RolloutGroup> get(final Long rolloutGroupId) {
return Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId));
}
@Override
public Page<RolloutGroup> findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable pageable) {
public Page<RolloutGroup> findByRollout(final Pageable pageable, final Long rolloutId) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable);
@@ -105,8 +105,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Page<RolloutGroup> findRolloutGroupsAll(final Long rolloutId, final String rsqlParam,
final Pageable pageable) {
public Page<RolloutGroup> findByRolloutAndRsql(final Pageable pageable, final Long rolloutId,
final String rsqlParam) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Specification<JpaRolloutGroup> specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class,
@@ -130,7 +130,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Page<RolloutGroup> findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) {
public Page<RolloutGroup> findByRolloutWithDetailedStatus(final Pageable pageable, final Long rolloutId) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
final Page<JpaRolloutGroup> rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable);
@@ -155,8 +155,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Optional<RolloutGroup> findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) {
final Optional<RolloutGroup> rolloutGroup = findRolloutGroupById(rolloutGroupId);
public Optional<RolloutGroup> getWithDetailedStatus(final Long rolloutGroupId) {
final Optional<RolloutGroup> rolloutGroup = get(rolloutGroupId);
if (!rolloutGroup.isPresent()) {
return rolloutGroup;
@@ -201,8 +201,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final String rsqlParam,
final Pageable pageable) {
public Page<Target> findTargetsOfRolloutGroupByRsql(final Pageable pageable, final Long rolloutGroupId,
final String rsqlParam) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
@@ -219,7 +219,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Page<Target> findRolloutGroupTargets(final Long rolloutGroupId, final Pageable page) {
public Page<Target> findTargetsOfRolloutGroup(final Pageable page, final Long rolloutGroupId) {
final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId)
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId));
@@ -237,7 +237,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Page<TargetWithActionStatus> findAllTargetsWithActionStatus(final Pageable pageRequest,
public Page<TargetWithActionStatus> findAllTargetsOfRolloutGroupWithActionStatus(final Pageable pageRequest,
final Long rolloutGroupId) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
@@ -269,7 +269,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public Long countTargetsOfRolloutsGroup(@NotNull final Long rolloutGroupId) {
public long countTargetsOfRolloutsGroup(@NotNull final Long rolloutGroupId) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
@@ -287,7 +287,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
}
@Override
public long countRolloutGroupsByRolloutId(final Long rolloutId) {
public long countByRollout(final Long rolloutId) {
throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId);
return rolloutGroupRepository.countByRolloutId(rolloutId);

View File

@@ -165,7 +165,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Page<Rollout> findAllByPredicate(final String rsqlParam, final Pageable pageable, final boolean deleted) {
public Page<Rollout> findByRsql(final Pageable pageable, final String rsqlParam, final boolean deleted) {
final List<Specification<JpaRollout>> specList = Lists.newArrayListWithExpectedSize(2);
specList.add(RSQLUtility.parse(rsqlParam, RolloutFields.class, virtualPropertyReplacer));
specList.add(RolloutSpecification.isDeletedWithDistributionSet(deleted));
@@ -186,7 +186,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Optional<Rollout> findRolloutById(final Long rolloutId) {
public Optional<Rollout> get(final Long rolloutId) {
return Optional.ofNullable(rolloutRepository.findOne(rolloutId));
}
@@ -194,8 +194,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout createRollout(final RolloutCreate rollout, final int amountGroup,
final RolloutGroupConditions conditions) {
public Rollout create(final RolloutCreate rollout, final int amountGroup, final RolloutGroupConditions conditions) {
RolloutHelper.verifyRolloutGroupParameter(amountGroup, quotaManagement);
final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build());
return createRolloutGroups(amountGroup, conditions, savedRollout);
@@ -205,7 +204,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout createRollout(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
final RolloutGroupConditions conditions) {
RolloutHelper.verifyRolloutGroupParameter(groups.size(), quotaManagement);
final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build());
@@ -214,7 +213,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
private JpaRollout createRollout(final JpaRollout rollout) {
final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery());
final Long totalTargets = targetManagement.countByRsql(rollout.getTargetFilterQuery());
if (totalTargets == 0) {
throw new ValidationException("Rollout does not match any existing targets");
}
@@ -320,9 +319,9 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
private void handleCreateRollout(final JpaRollout rollout) {
LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId());
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(),
new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")))
.getContent();
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(
new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")),
rollout.getId()).getContent();
int readyGroups = 0;
int totalTargets = 0;
@@ -368,7 +367,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
RolloutGroupStatus.READY, group);
final long targetsInGroupFilter = runInNewTransaction("countAllTargetsByTargetFilterQueryAndNotInRolloutGroups",
count -> targetManagement.countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(readyGroups,
count -> targetManagement.countByRsqlAndNotInRolloutGroups(readyGroups,
groupTargetFilter));
final long expectedInGroup = Math.round(group.getTargetPercentage() / 100 * (double) targetsInGroupFilter);
final long currentlyInGroup = runInNewTransaction("countRolloutTargetGroupByRolloutGroup",
@@ -410,7 +409,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
RolloutGroupStatus.READY, group);
final Page<Target> targets = targetManagement
.findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter);
.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter);
createAssignmentOfTargetsToGroup(targets, group);
@@ -428,7 +427,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
final String targetFilter, final Long createdAt) {
final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt);
final long totalTargets = targetManagement.countTargetByTargetFilterQuery(baseFilter);
final long totalTargets = targetManagement.countByRsql(baseFilter);
if (totalTargets == 0) {
throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
}
@@ -441,7 +440,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout startRollout(final Long rolloutId) {
public Rollout start(final Long rolloutId) {
LOGGER.debug("startRollout called for rollout {}", rolloutId);
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
@@ -531,7 +530,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
final ActionType actionType = rollout.getActionType();
final long forceTime = rollout.getForcedTime();
final Page<Target> targets = targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageRequest,
final Page<Target> targets = targetManagement.findByInRolloutGroupWithoutAction(pageRequest,
groupId);
if (targets.getTotalElements() > 0) {
createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime, rollout, group);
@@ -812,7 +811,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
LOGGER.debug(
"handleReadyRollout called for rollout {} with autostart beyond define time. Switch to STARTING",
rollout.getId());
startRollout(rollout.getId());
start(rollout.getId());
}
}
@@ -820,7 +819,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteRollout(final long rolloutId) {
public void delete(final Long rolloutId) {
final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId);
if (jpaRollout == null) {
@@ -915,17 +914,17 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Long countRolloutsAll() {
public long count() {
return rolloutRepository.count(RolloutSpecification.isDeletedWithDistributionSet(false));
}
@Override
public Long countRolloutsAllByFilters(final String searchText) {
public long countByFilters(final String searchText) {
return rolloutRepository.count(JpaRolloutHelper.likeNameOrDescription(searchText, false));
}
@Override
public Slice<Rollout> findRolloutWithDetailedStatusByFilters(final Pageable pageable, final String searchText,
public Slice<Rollout> findByFiltersWithDetailedStatus(final Pageable pageable, final String searchText,
final boolean deleted) {
final Slice<JpaRollout> findAll = findByCriteriaAPI(pageable,
Arrays.asList(JpaRolloutHelper.likeNameOrDescription(searchText, deleted)));
@@ -934,7 +933,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Optional<Rollout> findRolloutByName(final String rolloutName) {
public Optional<Rollout> getByName(final String rolloutName) {
return rolloutRepository.findByName(rolloutName);
}
@@ -942,7 +941,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout updateRollout(final RolloutUpdate u) {
public Rollout update(final RolloutUpdate u) {
final GenericRolloutUpdate update = (GenericRolloutUpdate) u;
final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(update.getId());
@@ -954,7 +953,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
update.getForcedTime().ifPresent(rollout::setForcedTime);
update.getStartAt().ifPresent(rollout::setStartAt);
update.getSet().ifPresent(setId -> {
final DistributionSet set = distributionSetManagement.findDistributionSetById(setId)
final DistributionSet set = distributionSetManagement.get(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
rollout.setDistributionSet(set);
@@ -975,7 +974,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Page<Rollout> findAllRolloutsWithDetailedStatus(final Pageable pageable, final boolean deleted) {
public Page<Rollout> findAllWithDetailedStatus(final Pageable pageable, final boolean deleted) {
Page<JpaRollout> rollouts;
final Specification<JpaRollout> spec = RolloutSpecification.isDeletedWithDistributionSet(deleted);
rollouts = rolloutRepository.findAll(spec, pageable);
@@ -984,8 +983,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
}
@Override
public Optional<Rollout> findRolloutWithDetailedStatus(final Long rolloutId) {
final Optional<Rollout> rollout = findRolloutById(rolloutId);
public Optional<Rollout> getWithDetailedStatus(final Long rolloutId) {
final Optional<Rollout> rollout = get(rolloutId);
if (!rollout.isPresent()) {
return rollout;

View File

@@ -113,7 +113,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModule updateSoftwareModule(final SoftwareModuleUpdate u) {
public SoftwareModule update(final SoftwareModuleUpdate u) {
final GenericSoftwareModuleUpdate update = (GenericSoftwareModuleUpdate) u;
final JpaSoftwareModule module = softwareModuleRepository.findById(update.getId())
@@ -129,7 +129,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModule createSoftwareModule(final SoftwareModuleCreate c) {
public SoftwareModule create(final SoftwareModuleCreate c) {
final JpaSoftwareModuleCreate create = (JpaSoftwareModuleCreate) c;
return softwareModuleRepository.save(create.build());
@@ -139,12 +139,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModule> createSoftwareModule(final Collection<SoftwareModuleCreate> swModules) {
return swModules.stream().map(this::createSoftwareModule).collect(Collectors.toList());
public List<SoftwareModule> create(final Collection<SoftwareModuleCreate> swModules) {
return swModules.stream().map(this::create).collect(Collectors.toList());
}
@Override
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final Long typeId) {
public Slice<SoftwareModule> findByType(final Pageable pageable, final Long typeId) {
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
final List<Specification<JpaSoftwareModule>> specList = Lists.newArrayListWithExpectedSize(2);
@@ -152,7 +152,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
specList.add(SoftwareModuleSpecification.equalType(typeId));
specList.add(SoftwareModuleSpecification.isDeletedFalse());
return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable);
return convertSmPage(findByCriteriaAPI(pageable, specList), pageable);
}
private void throwExceptionIfSoftwareModuleTypeDoesNotExist(final Long typeId) {
@@ -176,12 +176,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Optional<SoftwareModule> findSoftwareModuleById(final Long id) {
public Optional<SoftwareModule> get(final Long id) {
return Optional.ofNullable(softwareModuleRepository.findOne(id));
}
@Override
public Optional<SoftwareModule> findSoftwareModuleByNameAndVersion(final String name, final String version,
public Optional<SoftwareModule> getByNameAndVersionAndType(final String name, final String version,
final Long typeId) {
throwExceptionIfSoftwareModuleTypeDoesNotExist(typeId);
@@ -193,7 +193,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
return distributionSetRepository.countByModulesId(moduleId) <= 0;
}
private Slice<JpaSoftwareModule> findSwModuleByCriteriaAPI(final Pageable pageable,
private Slice<JpaSoftwareModule> findByCriteriaAPI(final Pageable pageable,
final List<Specification<JpaSoftwareModule>> specList) {
return criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable,
JpaSoftwareModule.class);
@@ -213,7 +213,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteSoftwareModules(final Collection<Long> ids) {
public void delete(final Collection<Long> ids) {
final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids);
if (swModulesToDelete.size() < ids.size()) {
@@ -245,7 +245,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Slice<SoftwareModule> findSoftwareModulesAll(final Pageable pageable) {
public Slice<SoftwareModule> findAll(final Pageable pageable) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(2);
@@ -261,18 +261,18 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
specList.add(spec);
return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable);
return convertSmPage(findByCriteriaAPI(pageable, specList), pageable);
}
@Override
public Long countSoftwareModulesAll() {
public long count() {
final Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.isDeletedFalse();
return countSwModuleByCriteriaAPI(Arrays.asList(spec));
}
@Override
public Page<SoftwareModule> findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) {
public Page<SoftwareModule> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaSoftwareModule> spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class,
virtualPropertyReplacer);
@@ -281,12 +281,12 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
public List<SoftwareModule> findSoftwareModulesById(final Collection<Long> ids) {
public List<SoftwareModule> get(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleRepository.findByIdIn(ids));
}
@Override
public Slice<SoftwareModule> findSoftwareModuleByFilters(final Pageable pageable, final String searchText,
public Slice<SoftwareModule> findByTextAndType(final Pageable pageable, final String searchText,
final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(4);
@@ -315,11 +315,11 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
specList.add(spec);
return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable);
return convertSmPage(findByCriteriaAPI(pageable, specList), pageable);
}
@Override
public Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
public Slice<AssignedSoftwareModule> findAllOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) {
final List<AssignedSoftwareModule> resultList = new ArrayList<>();
@@ -408,7 +408,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Long countSoftwareModuleByFilters(final String searchText, final Long typeId) {
public long countByTextAndType(final String searchText, final Long typeId) {
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
@@ -431,7 +431,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Page<SoftwareModule> findSoftwareModuleByAssignedTo(final Pageable pageable, final Long setId) {
public Page<SoftwareModule> findByAssignedTo(final Pageable pageable, final Long setId) {
if (!distributionSetRepository.exists(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
@@ -443,7 +443,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata createSoftwareModuleMetadata(final Long moduleId, final MetaData md) {
public SoftwareModuleMetadata createMetaData(final Long moduleId, final MetaData md) {
checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, md);
@@ -461,8 +461,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleMetadata> createSoftwareModuleMetadata(final Long moduleId,
final Collection<MetaData> md) {
public List<SoftwareModuleMetadata> createMetaData(final Long moduleId, final Collection<MetaData> md) {
md.forEach(meta -> checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, meta));
final JpaSoftwareModule module = touch(moduleId);
@@ -477,10 +476,10 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata updateSoftwareModuleMetadata(final Long moduleId, final MetaData md) {
public SoftwareModuleMetadata updateMetaData(final Long moduleId, final MetaData md) {
// check if exists otherwise throw entity not found exception
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId,
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(moduleId,
md.getKey()).orElseThrow(
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, md.getKey()));
metadata.setValue(md.getValue());
@@ -515,30 +514,21 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
* of the module to touch
*/
private JpaSoftwareModule touch(final Long moduleId) {
return touch(findSoftwareModuleById(moduleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId)));
return touch(get(moduleId).orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId)));
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) {
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) findSoftwareModuleMetadata(moduleId, key)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key));
public void deleteMetaData(final Long moduleId, final String key) {
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(moduleId,
key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key));
touch(metadata.getSoftwareModule());
softwareModuleMetadataRepository.delete(metadata.getId());
}
@Override
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long swId,
final Pageable pageable) {
throwExceptionIfSoftwareModuleDoesNotExist(swId);
return softwareModuleMetadataRepository.findBySoftwareModuleId(swId, pageable);
}
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
if (!softwareModuleRepository.exists(swId)) {
throw new EntityNotFoundException(SoftwareModule.class, swId);
@@ -546,8 +536,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
}
@Override
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId,
final String rsqlParam, final Pageable pageable) {
public Page<SoftwareModuleMetadata> findMetaDataByRsql(final Pageable pageable, final Long softwareModuleId,
final String rsqlParam) {
throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId);
@@ -564,18 +554,23 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
pageable);
}
@Override
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Pageable pageable,
final Long softwareModuleId) {
throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId);
private static Page<SoftwareModuleMetadata> convertMdPage(final Page<JpaSoftwareModuleMetadata> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
return convertSmMdPage(softwareModuleMetadataRepository.findAll((root, query, cb) -> cb.equal(
root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId),
@Override
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleId(final Pageable pageable, final Long swId) {
throwExceptionIfSoftwareModuleDoesNotExist(swId);
return convertMdPage(softwareModuleMetadataRepository.findAll(
(Specification<JpaSoftwareModuleMetadata>) (root, query, cb) -> cb
.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), swId),
pageable), pageable);
}
@Override
public Optional<SoftwareModuleMetadata> findSoftwareModuleMetadata(final Long moduleId, final String key) {
public Optional<SoftwareModuleMetadata> getMetaDataBySoftwareModuleId(final Long moduleId, final String key) {
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key)));
@@ -589,13 +584,13 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteSoftwareModule(final Long moduleId) {
deleteSoftwareModules(Arrays.asList(moduleId));
public void delete(final Long moduleId) {
delete(Arrays.asList(moduleId));
}
@Override
public List<SoftwareModuleType> findSoftwareModuleTypesById(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleTypeRepository.findByIdIn(ids));
public boolean exists(final Long id) {
return softwareModuleRepository.exists(id);
}
}

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
@@ -30,6 +31,7 @@ import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -52,24 +54,27 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
private final SoftwareModuleRepository softwareModuleRepository;
private final NoCountPagingRepository criteriaNoCountDao;
JpaSoftwareModuleTypeManagement(final DistributionSetTypeRepository distributionSetTypeRepository,
final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SoftwareModuleRepository softwareModuleRepository) {
final SoftwareModuleRepository softwareModuleRepository, final NoCountPagingRepository criteriaNoCountDao) {
this.distributionSetTypeRepository = distributionSetTypeRepository;
this.softwareModuleTypeRepository = softwareModuleTypeRepository;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.softwareModuleRepository = softwareModuleRepository;
this.criteriaNoCountDao = criteriaNoCountDao;
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleType updateSoftwareModuleType(final SoftwareModuleTypeUpdate u) {
public SoftwareModuleType update(final SoftwareModuleTypeUpdate u) {
final GenericSoftwareModuleTypeUpdate update = (GenericSoftwareModuleTypeUpdate) u;
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) findSoftwareModuleTypeById(update.getId())
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) get(update.getId())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, update.getId()));
update.getDescription().ifPresent(type::setDescription);
@@ -79,36 +84,33 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
}
@Override
public Page<SoftwareModuleType> findSoftwareModuleTypesAll(final String rsqlParam, final Pageable pageable) {
public Page<SoftwareModuleType> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaSoftwareModuleType> spec = RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class,
virtualPropertyReplacer);
return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable);
return convertPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable);
}
@Override
public Page<SoftwareModuleType> findSoftwareModuleTypesAll(final Pageable pageable) {
return softwareModuleTypeRepository.findByDeleted(pageable, false);
public Slice<SoftwareModuleType> findAll(final Pageable pageable) {
return convertPage(criteriaNoCountDao.findAll(
(targetRoot, query, cb) -> cb.equal(targetRoot.<Boolean> get(JpaSoftwareModuleType_.deleted), false),
pageable, JpaSoftwareModuleType.class), pageable);
}
@Override
public Long countSoftwareModuleTypesAll() {
public long count() {
return softwareModuleTypeRepository.countByDeleted(false);
}
@Override
public Optional<SoftwareModuleType> findSoftwareModuleTypeByKey(final String key) {
public Optional<SoftwareModuleType> getByKey(final String key) {
return softwareModuleTypeRepository.findByKey(key);
}
@Override
public Optional<SoftwareModuleType> findSoftwareModuleTypeById(final Long smTypeId) {
return Optional.ofNullable(softwareModuleTypeRepository.findOne(smTypeId));
}
@Override
public Optional<SoftwareModuleType> findSoftwareModuleTypeByName(final String name) {
public Optional<SoftwareModuleType> getByName(final String name) {
return softwareModuleTypeRepository.findByName(name);
}
@@ -116,7 +118,7 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleType createSoftwareModuleType(final SoftwareModuleTypeCreate c) {
public SoftwareModuleType create(final SoftwareModuleTypeCreate c) {
final JpaSoftwareModuleTypeCreate create = (JpaSoftwareModuleTypeCreate) c;
return softwareModuleTypeRepository.save(create.build());
@@ -126,7 +128,7 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteSoftwareModuleType(final Long typeId) {
public void delete(final Long typeId) {
final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(typeId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, typeId));
@@ -143,13 +145,48 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleType> createSoftwareModuleType(final Collection<SoftwareModuleTypeCreate> creates) {
return creates.stream().map(this::createSoftwareModuleType).collect(Collectors.toList());
public List<SoftwareModuleType> create(final Collection<SoftwareModuleTypeCreate> creates) {
return creates.stream().map(this::create).collect(Collectors.toList());
}
private static Page<SoftwareModuleType> convertSmTPage(final Page<JpaSoftwareModuleType> findAll,
private static Page<SoftwareModuleType> convertPage(final Page<JpaSoftwareModuleType> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
private static Slice<SoftwareModuleType> convertPage(final Slice<JpaSoftwareModuleType> findAll,
final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, 0);
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) {
final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAll(ids);
if (setsFound.size() < ids.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, ids,
setsFound.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
}
softwareModuleTypeRepository.delete(setsFound);
}
@Override
public List<SoftwareModuleType> get(final Collection<Long> ids) {
return Collections.unmodifiableList(softwareModuleTypeRepository.findAll(ids));
}
@Override
public Optional<SoftwareModuleType> get(final Long id) {
return Optional.ofNullable(softwareModuleTypeRepository.findOne(id));
}
@Override
public boolean exists(final Long id) {
return softwareModuleTypeRepository.exists(id);
}
}

View File

@@ -74,7 +74,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetFilterQuery createTargetFilterQuery(final TargetFilterQueryCreate c) {
public TargetFilterQuery create(final TargetFilterQueryCreate c) {
final JpaTargetFilterQueryCreate create = (JpaTargetFilterQueryCreate) c;
return targetFilterQueryRepository.save(create.build());
@@ -84,20 +84,20 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTargetFilterQuery(final Long targetFilterQueryId) {
findTargetFilterQueryById(targetFilterQueryId)
public void delete(final Long targetFilterQueryId) {
get(targetFilterQueryId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
targetFilterQueryRepository.delete(targetFilterQueryId);
}
@Override
public Page<TargetFilterQuery> findAllTargetFilterQuery(final Pageable pageable) {
public Page<TargetFilterQuery> findAll(final Pageable pageable) {
return convertPage(targetFilterQueryRepository.findAll(pageable), pageable);
}
@Override
public Long countAllTargetFilterQuery() {
public long count() {
return targetFilterQueryRepository.count();
}
@@ -107,7 +107,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Page<TargetFilterQuery> findTargetFilterQueryByName(final Pageable pageable, final String name) {
public Page<TargetFilterQuery> findByName(final Pageable pageable, final String name) {
List<Specification<JpaTargetFilterQuery>> specList = Collections.emptyList();
if (!StringUtils.isEmpty(name)) {
specList = Collections.singletonList(TargetFilterQuerySpecification.likeName(name));
@@ -116,7 +116,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Page<TargetFilterQuery> findTargetFilterQueryByFilter(final Pageable pageable, final String rsqlFilter) {
public Page<TargetFilterQuery> findByRsql(final Pageable pageable, final String rsqlFilter) {
List<Specification<JpaTargetFilterQuery>> specList = Collections.emptyList();
if (!StringUtils.isEmpty(rsqlFilter)) {
specList = Collections.singletonList(
@@ -126,7 +126,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Page<TargetFilterQuery> findTargetFilterQueryByQuery(final Pageable pageable, final String query) {
public Page<TargetFilterQuery> findByQuery(final Pageable pageable, final String query) {
List<Specification<JpaTargetFilterQuery>> specList = Collections.emptyList();
if (!StringUtils.isEmpty(query)) {
specList = Collections.singletonList(TargetFilterQuerySpecification.equalsQuery(query));
@@ -135,7 +135,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Page<TargetFilterQuery> findTargetFilterQueryByAutoAssignDS(final Pageable pageable, final Long setId,
public Page<TargetFilterQuery> findByAutoAssignDSAndRsql(final Pageable pageable, final Long setId,
final String rsqlFilter) {
final List<Specification<JpaTargetFilterQuery>> specList = Lists.newArrayListWithExpectedSize(2);
@@ -150,7 +150,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Page<TargetFilterQuery> findTargetFilterQueryWithAutoAssignDS(final Pageable pageable) {
public Page<TargetFilterQuery> findWithAutoAssignDS(final Pageable pageable) {
final List<Specification<JpaTargetFilterQuery>> specList = Collections
.singletonList(TargetFilterQuerySpecification.withAutoAssignDS());
return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList), pageable);
@@ -167,18 +167,18 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
@Override
public Optional<TargetFilterQuery> findTargetFilterQueryByName(final String targetFilterQueryName) {
public Optional<TargetFilterQuery> getByName(final String targetFilterQueryName) {
return targetFilterQueryRepository.findByName(targetFilterQueryName);
}
@Override
public Optional<TargetFilterQuery> findTargetFilterQueryById(final Long targetFilterQueryId) {
public Optional<TargetFilterQuery> get(final Long targetFilterQueryId) {
return Optional.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId));
}
@Override
@Transactional
public TargetFilterQuery updateTargetFilterQuery(final TargetFilterQueryUpdate u) {
public TargetFilterQuery update(final TargetFilterQueryUpdate u) {
final GenericTargetFilterQueryUpdate update = (GenericTargetFilterQueryUpdate) u;
final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(update.getId());
@@ -191,7 +191,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override
@Transactional
public TargetFilterQuery updateTargetFilterQueryAutoAssignDS(final Long queryId, final Long dsId) {
public TargetFilterQuery updateAutoAssignDS(final Long queryId, final Long dsId) {
final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(queryId);
targetFilterQuery.setAutoAssignDistributionSet(
@@ -201,7 +201,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
}
private JpaDistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
return (JpaDistributionSet) distributionSetManagement.findDistributionSetByIdWithDetails(setId)
return (JpaDistributionSet) distributionSetManagement.getWithDetails(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
}

View File

@@ -116,28 +116,28 @@ public class JpaTargetManagement implements TargetManagement {
private VirtualPropertyReplacer virtualPropertyReplacer;
@Override
public Optional<Target> findTargetByControllerID(final String controllerId) {
public Optional<Target> getByControllerID(final String controllerId) {
return targetRepository.findByControllerId(controllerId);
}
@Override
public List<Target> findTargetsByControllerID(final Collection<String> controllerIDs) {
public List<Target> getByControllerID(final Collection<String> controllerIDs) {
return Collections.unmodifiableList(
targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
}
@Override
public Long countTargetsAll() {
public long count() {
return targetRepository.count();
}
@Override
public Slice<Target> findTargetsAll(final Pageable pageable) {
public Slice<Target> findAll(final Pageable pageable) {
return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable);
}
@Override
public Slice<Target> findTargetsByTargetFilterQuery(final Long targetFilterQueryId, final Pageable pageable) {
public Slice<Target> findByTargetFilterQuery(final Pageable pageable, final Long targetFilterQueryId) {
final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
@@ -146,7 +146,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findTargetsAll(final String targetFilterQuery, final Pageable pageable) {
public Page<Target> findByRsql(final Pageable pageable, final String targetFilterQuery) {
return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class, virtualPropertyReplacer),
pageable);
}
@@ -159,7 +159,7 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target updateTarget(final TargetUpdate u) {
public Target update(final TargetUpdate u) {
final JpaTargetUpdate update = (JpaTargetUpdate) u;
final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(update.getControllerId())
@@ -177,7 +177,7 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTargets(final Collection<Long> targetIDs) {
public void delete(final Collection<Long> targetIDs) {
final List<JpaTarget> targets = targetRepository.findAll(targetIDs);
if (targets.size() < targetIDs.size()) {
@@ -197,7 +197,7 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTarget(final String controllerID) {
public void deleteByControllerID(final String controllerID) {
final Target target = targetRepository.findByControllerId(controllerID)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID));
@@ -205,15 +205,15 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) {
public Page<Target> findByAssignedDistributionSet(final Pageable pageReq, final Long distributionSetID) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID);
}
@Override
public Page<Target> findTargetByAssignedDistributionSet(final Long distributionSetID, final String rsqlParam,
final Pageable pageReq) {
public Page<Target> findByAssignedDistributionSetAndRsql(final Pageable pageReq, final Long distributionSetID,
final String rsqlParam) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer);
@@ -242,14 +242,14 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) {
public Page<Target> findByInstalledDistributionSet(final Pageable pageReq, final Long distributionSetID) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetID);
return targetRepository.findByInstalledDistributionSetId(pageReq, distributionSetID);
}
@Override
public Page<Target> findTargetByInstalledDistributionSet(final Long distributionSetId, final String rsqlParam,
final Pageable pageable) {
public Page<Target> findByInstalledDistributionSetAndRsql(final Pageable pageable, final Long distributionSetId,
final String rsqlParam) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
final Specification<JpaTarget> spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer);
@@ -264,27 +264,22 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findTargetByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) {
public Page<Target> findByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) {
return targetRepository.findByUpdateStatus(pageable, status);
}
@Override
public Slice<Target> findTargetByFilters(final Pageable pageable, final Collection<TargetUpdateStatus> status,
final Boolean overdueState, final String searchText, final Long installedOrAssignedDistributionSetId,
final Boolean selectTargetWithNoTag, final String... tagNames) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(
new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
selectTargetWithNoTag, tagNames));
public Slice<Target> findByFilters(final Pageable pageable, final FilterParams filterParams) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
return findByCriteriaAPI(pageable, specList);
}
@Override
public Long countTargetByFilters(final Collection<TargetUpdateStatus> status, final Boolean overdueState,
public long countByFilters(final Collection<TargetUpdateStatus> status, final Boolean overdueState,
final String searchText, final Long installedOrAssignedDistributionSetId,
final Boolean selectTargetWithNoTag, final String... tagNames) {
final List<Specification<JpaTarget>> specList = buildSpecificationList(
new FilterParams(installedOrAssignedDistributionSetId, status, overdueState, searchText,
selectTargetWithNoTag, tagNames));
final List<Specification<JpaTarget>> specList = buildSpecificationList(new FilterParams(status, overdueState,
searchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, tagNames));
return countByCriteriaAPI(specList);
}
@@ -421,7 +416,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Slice<Target> findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable,
public Slice<Target> findByFilterOrderByLinkedDistributionSet(final Pageable pageable,
final Long orderByDistributionId, final FilterParams filterParams) {
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<JpaTarget> query = cb.createQuery(JpaTarget.class);
@@ -475,22 +470,22 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Long countTargetByAssignedDistributionSet(final Long distId) {
public long countByAssignedDistributionSet(final Long distId) {
throwEntityNotFoundIfDsDoesNotExist(distId);
return targetRepository.countByAssignedDistributionSetId(distId);
}
@Override
public Long countTargetByInstalledDistributionSet(final Long distId) {
public long countByInstalledDistributionSet(final Long distId) {
throwEntityNotFoundIfDsDoesNotExist(distId);
return targetRepository.countByInstalledDistributionSetId(distId);
}
@Override
public Page<Target> findAllTargetsByTargetFilterQueryAndNonDS(final Pageable pageRequest,
final Long distributionSetId, final String targetFilterQuery) {
public Page<Target> findByTargetFilterQueryAndNonDS(final Pageable pageRequest, final Long distributionSetId,
final String targetFilterQuery) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
@@ -505,7 +500,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Pageable pageRequest,
public Page<Target> findByTargetFilterQueryAndNotInRolloutGroups(final Pageable pageRequest,
final Collection<Long> groups, final String targetFilterQuery) {
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
@@ -517,7 +512,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findAllTargetsInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest,
public Page<Target> findByInRolloutGroupWithoutAction(@NotNull final Pageable pageRequest,
@NotNull final Long group) {
if (!rolloutGroupRepository.exists(group)) {
throw new EntityNotFoundException(RolloutGroup.class, group);
@@ -529,8 +524,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(final Collection<Long> groups,
final String targetFilterQuery) {
public long countByRsqlAndNotInRolloutGroups(final Collection<Long> groups, final String targetFilterQuery) {
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
virtualPropertyReplacer);
final List<Specification<JpaTarget>> specList = Arrays.asList(spec,
@@ -540,7 +534,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Long countTargetsByTargetFilterQueryAndNonDS(final Long distributionSetId, final String targetFilterQuery) {
public long countByRsqlAndNonDS(final Long distributionSetId, final String targetFilterQuery) {
throwEntityNotFoundIfDsDoesNotExist(distributionSetId);
final Specification<JpaTarget> spec = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
@@ -556,7 +550,7 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target createTarget(final TargetCreate c) {
public Target create(final TargetCreate c) {
final JpaTargetCreate create = (JpaTargetCreate) c;
return targetRepository.save(create.build());
}
@@ -565,12 +559,12 @@ public class JpaTargetManagement implements TargetManagement {
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> createTargets(final Collection<TargetCreate> targets) {
return targets.stream().map(this::createTarget).collect(Collectors.toList());
public List<Target> create(final Collection<TargetCreate> targets) {
return targets.stream().map(this::create).collect(Collectors.toList());
}
@Override
public Page<Target> findTargetsByTag(final Pageable pageable, final Long tagId) {
public Page<Target> findByTag(final Pageable pageable, final Long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
return convertPage(targetRepository.findByTag(pageable, tagId), pageable);
@@ -583,7 +577,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Page<Target> findTargetsByTag(final Pageable pageable, final String rsqlParam, final Long tagId) {
public Page<Target> findByRsqlAndTag(final Pageable pageable, final String rsqlParam, final Long tagId) {
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
@@ -595,7 +589,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Long countTargetByTargetFilterQuery(final Long targetFilterQueryId) {
public long countByTargetFilterQuery(final Long targetFilterQueryId) {
final TargetFilterQuery targetFilterQuery = targetFilterQueryRepository.findById(targetFilterQueryId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
@@ -605,7 +599,7 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Long countTargetByTargetFilterQuery(final String targetFilterQuery) {
public long countByRsql(final String targetFilterQuery) {
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
virtualPropertyReplacer);
return targetRepository.count((root, query, cb) -> {
@@ -615,18 +609,18 @@ public class JpaTargetManagement implements TargetManagement {
}
@Override
public Optional<Target> findTargetById(final Long id) {
public Optional<Target> get(final Long id) {
return Optional.ofNullable(targetRepository.findOne(id));
}
@Override
public List<Target> findTargetsById(final Collection<Long> ids) {
public List<Target> get(final Collection<Long> ids) {
return Collections.unmodifiableList(targetRepository.findAll(ids));
}
@Override
public Map<String, String> getControllerAttributes(final String controllerId) {
final JpaTarget target = (JpaTarget) findTargetByControllerID(controllerId)
final JpaTarget target = (JpaTarget) getByControllerID(controllerId)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
return target.getControllerAttributes();

View File

@@ -0,0 +1,153 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TagFields;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.builder.GenericTagUpdate;
import org.eclipse.hawkbit.repository.builder.TagCreate;
import org.eclipse.hawkbit.repository.builder.TagUpdate;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.builder.JpaTagCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
/**
* JPA implementation of {@link TargetTagManagement}.
*
*/
@Transactional(readOnly = true)
@Validated
public class JpaTargetTagManagement implements TargetTagManagement {
private final TargetTagRepository targetTagRepository;
private final TargetRepository targetRepository;
private final VirtualPropertyReplacer virtualPropertyReplacer;
JpaTargetTagManagement(final TargetTagRepository targetTagRepository, final TargetRepository targetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer) {
this.targetTagRepository = targetTagRepository;
this.targetRepository = targetRepository;
this.virtualPropertyReplacer = virtualPropertyReplacer;
}
@Override
public Optional<TargetTag> getByName(final String name) {
return targetTagRepository.findByNameEquals(name);
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag create(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c;
return targetTagRepository.save(create.buildTargetTag());
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<TargetTag> create(final Collection<TagCreate> tt) {
@SuppressWarnings({ "unchecked", "rawtypes" })
final Collection<JpaTagCreate> targetTags = (Collection) tt;
return Collections.unmodifiableList(targetTags.stream()
.map(ttc -> targetTagRepository.save(ttc.buildTargetTag())).collect(Collectors.toList()));
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final String targetTagName) {
if (!targetTagRepository.existsByName(targetTagName)) {
throw new EntityNotFoundException(TargetTag.class, targetTagName);
}
// finally delete the tag itself
targetTagRepository.deleteByName(targetTagName);
}
@Override
public Page<TargetTag> findByRsql(final Pageable pageable, final String rsqlParam) {
final Specification<JpaTargetTag> spec = RSQLUtility.parse(rsqlParam, TagFields.class, virtualPropertyReplacer);
return convertTPage(targetTagRepository.findAll(spec, pageable), pageable);
}
private static Page<TargetTag> convertTPage(final Page<JpaTargetTag> findAll, final Pageable pageable) {
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
}
@Override
public long count() {
return targetTagRepository.count();
}
@Override
@Transactional
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag update(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u;
final JpaTargetTag tag = targetTagRepository.findById(update.getId())
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, update.getId()));
update.getName().ifPresent(tag::setName);
update.getDescription().ifPresent(tag::setDescription);
update.getColour().ifPresent(tag::setColour);
return targetTagRepository.save(tag);
}
@Override
public Optional<TargetTag> get(final Long id) {
return Optional.ofNullable(targetTagRepository.findOne(id));
}
@Override
public Page<TargetTag> findAll(final Pageable pageable) {
return convertTPage(targetTagRepository.findAll(pageable), pageable);
}
@Override
public Page<TargetTag> findByTarget(final Pageable pageable, final String controllerId) {
if (!targetRepository.existsByControllerId(controllerId)) {
throw new EntityNotFoundException(Target.class, controllerId);
}
return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable);
}
}

View File

@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.PropertiesQuotaManagement;
@@ -28,9 +29,9 @@ import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.TenantStatsManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetBuilder;
@@ -165,8 +166,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
* @return DistributionSetTypeBuilder bean
*/
@Bean
DistributionSetTypeBuilder distributionSetTypeBuilder(final SoftwareModuleManagement softwareManagement) {
return new JpaDistributionSetTypeBuilder(softwareManagement);
DistributionSetTypeBuilder distributionSetTypeBuilder(
final SoftwareModuleTypeManagement softwareModuleTypeManagement) {
return new JpaDistributionSetTypeBuilder(softwareModuleTypeManagement);
}
/**
@@ -369,9 +371,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
final DistributionSetTypeRepository distributionSetTypeRepository,
final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final DistributionSetRepository distributionSetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer) {
final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) {
return new JpaDistributionSetTypeManagement(distributionSetTypeRepository, softwareModuleTypeRepository,
distributionSetRepository, virtualPropertyReplacer);
distributionSetRepository, virtualPropertyReplacer, criteriaNoCountDao);
}
/**
@@ -430,14 +432,30 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
}
/**
* {@link JpaTagManagement} bean.
* {@link JpaTargetTagManagement} bean.
*
* @return a new {@link TagManagement}
* @return a new {@link TargetTagManagement}
*/
@Bean
@ConditionalOnMissingBean
TagManagement tagManagement() {
return new JpaTagManagement();
TargetTagManagement targetTagManagement(final TargetTagRepository targetTagRepository,
final TargetRepository targetRepository, final VirtualPropertyReplacer virtualPropertyReplacer) {
return new JpaTargetTagManagement(targetTagRepository, targetRepository, virtualPropertyReplacer);
}
/**
* {@link JpaDistributionSetTagManagement} bean.
*
* @return a new {@link JpaDistributionSetTagManagement}
*/
@Bean
@ConditionalOnMissingBean
DistributionSetTagManagement distributionSetTagManagement(
final DistributionSetTagRepository distributionSetTagRepository,
final DistributionSetRepository distributionSetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer, final NoCountPagingRepository criteriaNoCountDao) {
return new JpaDistributionSetTagManagement(distributionSetTagRepository, distributionSetRepository,
virtualPropertyReplacer, criteriaNoCountDao);
}
/**
@@ -462,9 +480,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
final DistributionSetTypeRepository distributionSetTypeRepository,
final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SoftwareModuleRepository softwareModuleRepository) {
final SoftwareModuleRepository softwareModuleRepository, final NoCountPagingRepository criteriaNoCountDao) {
return new JpaSoftwareModuleTypeManagement(distributionSetTypeRepository, softwareModuleTypeRepository,
virtualPropertyReplacer, softwareModuleRepository);
virtualPropertyReplacer, softwareModuleRepository, criteriaNoCountDao);
}
@Bean
@@ -537,7 +555,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
*/
@Bean
@ConditionalOnMissingBean
public EntityFactory entityFactory() {
EntityFactory entityFactory() {
return new JpaEntityFactory();
}

View File

@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.repository.jpa;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
@@ -26,15 +24,4 @@ public interface SoftwareModuleMetadataRepository
extends PagingAndSortingRepository<JpaSoftwareModuleMetadata, SwMetadataCompositeKey>,
JpaSpecificationExecutor<JpaSoftwareModuleMetadata> {
/**
* finds all software module meta data of the given software module id.
*
* @param swId
* the ID of the software module to retrieve the meta data
* @param pageable
* the page request to page the result set
* @return the paged result of all meta data of an given software module id
*/
Page<SoftwareModuleMetadata> findBySoftwareModuleId(final Long swId, Pageable pageable);
}

View File

@@ -14,7 +14,6 @@ import java.util.Optional;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.springframework.data.domain.Page;
@@ -68,18 +67,6 @@ public interface SoftwareModuleTypeRepository
*/
Optional<SoftwareModuleType> findByName(String name);
/**
* retrieves all software module types with a given
* {@link SoftwareModuleType#getId()}.
*
* @param ids
* to search for
* @return {@link List} of found {@link SoftwareModule}s
*/
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT sm FROM JpaSoftwareModuleType sm WHERE sm.id IN ?1")
List<JpaSoftwareModuleType> findByIdIn(Iterable<Long> ids);
/**
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
* reasons (this is a "delete everything" query after all) we add the tenant
@@ -93,4 +80,9 @@ public interface SoftwareModuleTypeRepository
@Transactional
@Query("DELETE FROM JpaSoftwareModuleType t WHERE t.tenant = :tenant")
void deleteByTenant(@Param("tenant") String tenant);
@Override
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
@Query("SELECT d FROM JpaSoftwareModuleType d WHERE d.id IN ?1")
List<JpaSoftwareModuleType> findAll(Iterable<Long> ids);
}

View File

@@ -105,7 +105,7 @@ public class AutoAssignChecker {
final PageRequest pageRequest = new PageRequest(0, PAGE_SIZE);
final Page<TargetFilterQuery> filterQueries = targetFilterQueryManagement
.findTargetFilterQueryWithAutoAssignDS(pageRequest);
.findWithAutoAssignDS(pageRequest);
for (final TargetFilterQuery filterQuery : filterQueries) {
checkByTargetFilterQueryAndAssignDS(filterQuery);
@@ -176,7 +176,7 @@ public class AutoAssignChecker {
private List<TargetWithActionType> getTargetsWithActionType(final String targetFilterQuery, final Long dsId,
final int count) {
final Page<Target> targets = targetManagement
.findAllTargetsByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery);
.findByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery);
return targets.getContent().stream().map(t -> new TargetWithActionType(t.getControllerId(),
Action.ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME)).collect(Collectors.toList());

View File

@@ -47,7 +47,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
}
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) {
return distributionSetTypeManagement.findDistributionSetTypeByKey(distributionSetTypekey)
return distributionSetTypeManagement.getByKey(distributionSetTypekey)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey));
}
@@ -57,7 +57,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
return Collections.emptyList();
}
final Collection<SoftwareModule> module = softwareModuleManagement.findSoftwareModulesById(softwareModuleId);
final Collection<SoftwareModule> module = softwareModuleManagement.get(softwareModuleId);
if (module.size() < softwareModuleId.size()) {
throw new EntityNotFoundException(SoftwareModule.class, softwareModuleId);
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa.builder;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeUpdate;
@@ -21,10 +21,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
*/
public class JpaDistributionSetTypeBuilder implements DistributionSetTypeBuilder {
private final SoftwareModuleManagement softwareModuleManagement;
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
public JpaDistributionSetTypeBuilder(final SoftwareModuleManagement softwareManagement) {
this.softwareModuleManagement = softwareManagement;
public JpaDistributionSetTypeBuilder(final SoftwareModuleTypeManagement softwareModuleTypeManagement) {
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
}
@Override
@@ -34,7 +34,7 @@ public class JpaDistributionSetTypeBuilder implements DistributionSetTypeBuilder
@Override
public DistributionSetTypeCreate create() {
return new JpaDistributionSetTypeCreate(softwareModuleManagement);
return new JpaDistributionSetTypeCreate(softwareModuleTypeManagement);
}
}

View File

@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.builder;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.builder.AbstractDistributionSetTypeUpdateCreate;
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -26,10 +26,10 @@ import org.springframework.util.CollectionUtils;
public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpdateCreate<DistributionSetTypeCreate>
implements DistributionSetTypeCreate {
private final SoftwareModuleManagement softwareModuleManagement;
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
JpaDistributionSetTypeCreate(final SoftwareModuleManagement softwareManagement) {
this.softwareModuleManagement = softwareManagement;
JpaDistributionSetTypeCreate(final SoftwareModuleTypeManagement softwareModuleTypeManagement) {
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
}
@Override
@@ -48,8 +48,7 @@ public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpd
return Collections.emptyList();
}
final Collection<SoftwareModuleType> module = softwareModuleManagement
.findSoftwareModuleTypesById(softwareModuleTypeId);
final Collection<SoftwareModuleType> module = softwareModuleTypeManagement.get(softwareModuleTypeId);
if (module.size() < softwareModuleTypeId.size()) {
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId);
}

View File

@@ -44,7 +44,7 @@ public class JpaRolloutCreate extends AbstractRolloutUpdateCreate<RolloutCreate>
}
private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
return distributionSetManagement.findDistributionSetById(setId)
return distributionSetManagement.get(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
}
}

View File

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

View File

@@ -36,7 +36,7 @@ public class JpaTargetFilterQueryCreate extends AbstractTargetFilterQueryUpdateC
}
private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) {
return distributionSetManagement.findDistributionSetById(setId)
return distributionSetManagement.get(setId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId));
}

View File

@@ -37,7 +37,7 @@ import com.google.common.base.Splitter;
/**
* Entity to store the status for a specific action.
*/
@Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"),
@Table(name = "sp_action_status", indexes = {
@Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"),
@Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") })
@NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") })

View File

@@ -60,8 +60,7 @@ import org.springframework.context.ApplicationEvent;
@Entity
@Table(name = "sp_distribution_set", uniqueConstraints = {
@UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = {
@Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"),
@Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"),
@Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,complete"),
@Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") })
@NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"),
@NamedAttributeNode("tags"), @NamedAttributeNode("type") })

View File

@@ -19,7 +19,6 @@ import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@@ -52,9 +51,8 @@ import org.hibernate.validator.constraints.NotEmpty;
*
*/
@Entity
@Table(name = "sp_rollout", indexes = {
@Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "tenant" }, name = "uk_rollout"))
@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name",
"tenant" }, name = "uk_rollout"))
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")

View File

@@ -17,7 +17,6 @@ import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@@ -44,9 +43,8 @@ import org.eclipse.persistence.descriptors.DescriptorEvent;
*
*/
@Entity
@Table(name = "sp_rolloutgroup", indexes = {
@Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "rollout", "tenant" }, name = "uk_rolloutgroup"))
@Table(name = "sp_rolloutgroup", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout",
"tenant" }, name = "uk_rolloutgroup"))
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")

View File

@@ -32,9 +32,9 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
private static final long serialVersionUID = 1L;
@Id
@ManyToOne(optional = false, targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "sw_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw"))
private SoftwareModule softwareModule;
private JpaSoftwareModule softwareModule;
public JpaSoftwareModuleMetadata() {
// default public constructor for JPA
@@ -42,7 +42,7 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
public JpaSoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) {
super(key, value);
this.softwareModule = softwareModule;
this.softwareModule = (JpaSoftwareModule) softwareModule;
}
public SwMetadataCompositeKey getId() {
@@ -54,7 +54,7 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
return softwareModule;
}
public void setSoftwareModule(final SoftwareModule softwareModule) {
public void setSoftwareModule(final JpaSoftwareModule softwareModule) {
this.softwareModule = softwareModule;
}

View File

@@ -74,7 +74,6 @@ import org.slf4j.LoggerFactory;
@Entity
@Table(name = "sp_target", indexes = {
@Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"),
@Index(name = "sp_idx_target_02", columnList = "tenant,name"),
@Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"),
@Index(name = "sp_idx_target_04", columnList = "tenant,created_at"),
@Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = {

View File

@@ -13,7 +13,6 @@ import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@@ -30,9 +29,8 @@ import org.hibernate.validator.constraints.NotEmpty;
*
*/
@Entity
@Table(name = "sp_target_filter_query", indexes = {
@Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = {
"name", "tenant" }, name = "uk_tenant_custom_filter_name"))
@Table(name = "sp_target_filter_query", uniqueConstraints = @UniqueConstraint(columnNames = { "name",
"tenant" }, name = "uk_tenant_custom_filter_name"))
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
// sub entities
@SuppressWarnings("squid:S2160")

View File

@@ -74,7 +74,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
context.setSyntaxErrorContext(errorContext);
try {
targetManagement.findTargetsAll(rsqlQuery, new PageRequest(0, 1));
targetManagement.findByRsql(new PageRequest(0, 1), rsqlQuery);
context.setSyntaxError(false);
suggestionContext.getSuggestions().addAll(getLogicalOperatorSuggestion(rsqlQuery));
} catch (final RSQLParameterSyntaxException | RSQLParserException ex) {

View File

@@ -0,0 +1,8 @@
ALTER TABLE sp_action_status DROP INDEX sp_idx_action_status_01;
ALTER TABLE sp_rollout DROP INDEX sp_idx_rollout_01;
ALTER TABLE sp_rolloutgroup DROP INDEX sp_idx_rolloutgroup_01;
ALTER TABLE sp_target DROP INDEX sp_idx_target_02;
ALTER TABLE sp_target_filter_query DROP INDEX sp_idx_target_filter_query_01;
ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_01;
ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_02;
CREATE INDEX sp_idx_distribution_set_01 ON sp_distribution_set (tenant, deleted, complete);

View File

@@ -0,0 +1,8 @@
ALTER TABLE sp_action_status DROP INDEX sp_idx_action_status_01;
ALTER TABLE sp_rollout DROP INDEX sp_idx_rollout_01;
ALTER TABLE sp_rolloutgroup DROP INDEX sp_idx_rolloutgroup_01;
ALTER TABLE sp_target DROP INDEX sp_idx_target_02;
ALTER TABLE sp_target_filter_query DROP INDEX sp_idx_target_filter_query_01;
ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_01;
ALTER TABLE sp_distribution_set DROP INDEX sp_idx_distribution_set_02;
CREATE INDEX sp_idx_distribution_set_01 ON sp_distribution_set (tenant, deleted, complete);