Skip to content

Commit

Permalink
Refactoring of RepostioryManagement and extending classes
Browse files Browse the repository at this point in the history
* createMetaData renamed to putMetaData
* getXXX methods returing Optional are renamed to findXXX
* unified method order (code cosmetics)

Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm committed Jan 8, 2025
1 parent cad18fe commit 7c009cd
Show file tree
Hide file tree
Showing 55 changed files with 814 additions and 858 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusReposit
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(actionStatusRepository.count()).isEqualTo(2);

final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get();
final DistributionSet findDistributionSetByAction = distributionSetManagement.findByAction(action.getId()).get();

getAndVerifyConfirmationBasePayload(
DEFAULT_CONTROLLER_ID, MediaType.APPLICATION_JSON, ds, artifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void deploymentForceAction() throws Exception {
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(countActionStatusAll()).isEqualTo(2);

final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get();
final DistributionSet findDistributionSetByAction = distributionSetManagement.findByAction(action.getId()).get();
getAndVerifyDeploymentBasePayload(DEFAULT_CONTROLLER_ID, MediaType.APPLICATION_JSON, ds, artifact,
artifactSignature, action.getId(),
findDistributionSetByAction.findFirstModuleByType(osType).get().getId(), "forced", "forced");
Expand Down Expand Up @@ -244,9 +244,9 @@ void deploymentAttemptAction() throws Exception {
final Artifact artifactSignature = testdataFactory.createArtifact(nextBytes(ARTIFACT_SIZE),
getOsModule(ds), "test1.signature", ARTIFACT_SIZE);

softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
.key(visibleMetadataOsKey).value(visibleMetadataOsValue).targetVisible(true));
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
.key("metaDataNotVisible").value("withValue").targetVisible(false));

final Target savedTarget = createTargetAndAssertNoActiveActions();
Expand Down Expand Up @@ -279,7 +279,7 @@ void deploymentAttemptAction() throws Exception {
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(countActionStatusAll()).isEqualTo(2);

final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get();
final DistributionSet findDistributionSetByAction = distributionSetManagement.findByAction(action.getId()).get();

getAndVerifyDeploymentBasePayload(DEFAULT_CONTROLLER_ID, MediaType.APPLICATION_JSON, ds, visibleMetadataOsKey,
visibleMetadataOsValue, artifact, artifactSignature, action.getId(), "attempt", "attempt",
Expand Down Expand Up @@ -334,7 +334,7 @@ void deploymentAutoForceAction() throws Exception {
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(countActionStatusAll()).isEqualTo(2);

final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get();
final DistributionSet findDistributionSetByAction = distributionSetManagement.findByAction(action.getId()).get();
getAndVerifyDeploymentBasePayload(DEFAULT_CONTROLLER_ID, MediaType.APPLICATION_JSON, ds, artifact,
artifactSignature, action.getId(),
findDistributionSetByAction.findFirstModuleByType(osType).get().getId(), "forced", "forced");
Expand All @@ -361,9 +361,9 @@ void deploymentDownloadOnlyAction() throws Exception {
final Artifact artifactSignature = testdataFactory.createArtifact(
nextBytes(ARTIFACT_SIZE), getOsModule(ds), "test1.signature", ARTIFACT_SIZE);

softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
.key("metaDataVisible").value("withValue").targetVisible(true));
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(getOsModule(ds))
.key("metaDataNotVisible").value("withValue").targetVisible(false));

final Target savedTarget = createTargetAndAssertNoActiveActions();
Expand Down Expand Up @@ -399,7 +399,7 @@ void deploymentDownloadOnlyAction() throws Exception {
.isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(countActionStatusAll()).isEqualTo(2);

final DistributionSet findDistributionSetByAction = distributionSetManagement.getByAction(action.getId()).get();
final DistributionSet findDistributionSetByAction = distributionSetManagement.findByAction(action.getId()).get();
getAndVerifyDeploymentBasePayload(DEFAULT_CONTROLLER_ID, MediaType.APPLICATION_JSON, ds, "metaDataVisible",
"withValue", artifact, artifactSignature, action.getId(), "forced", "skip",
getOsModule(findDistributionSetByAction));
Expand Down Expand Up @@ -794,7 +794,7 @@ private void assertStatusAndActiveActionsCount(final TargetUpdateStatus status,
}

private Page<ActionStatus> findActionStatusAll(final Pageable pageable) {
return JpaManagementHelper.findAllWithCountBySpec(actionStatusRepository, pageable, null);
return JpaManagementHelper.findAllWithCountBySpec(actionStatusRepository, null, pageable);
}

private static class ActionStatusCondition extends Condition<ActionStatus> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public ResponseEntity<PagedList<MgmtDistributionSet>> getDistributionSets(
final Slice<DistributionSet> findDsPage;
final long countModulesAll;
if (rsqlParam != null) {
findDsPage = distributionSetManagement.findByRsql(pageable, rsqlParam);
findDsPage = distributionSetManagement.findByRsql(rsqlParam, pageable);
countModulesAll = ((Page<DistributionSet>) findDsPage).getTotalElements();
} else {
findDsPage = distributionSetManagement.findAll(pageable);
Expand Down Expand Up @@ -150,7 +150,7 @@ public ResponseEntity<List<MgmtDistributionSet>> createDistributionSets(final Li

//check if there is already deleted DS Type
for (MgmtDistributionSetRequestBodyPost ds : sets) {
final Optional<DistributionSetType> opt = distributionSetTypeManagement.getByKey(ds.getType());
final Optional<DistributionSetType> opt = distributionSetTypeManagement.findByKey(ds.getType());
opt.ifPresent(dsType -> {
if (dsType.isDeleted()) {
final String text = "Cannot create Distribution Set from type with key {0}. Distribution Set Type already deleted!";
Expand Down Expand Up @@ -288,10 +288,10 @@ public ResponseEntity<PagedList<MgmtMetadata>> getMetadata(
final Page<DistributionSetMetadata> metaDataPage;

if (rsqlParam != null) {
metaDataPage = distributionSetManagement.findMetaDataByDistributionSetIdAndRsql(pageable, distributionSetId,
rsqlParam);
metaDataPage = distributionSetManagement.findMetaDataByDistributionSetIdAndRsql(distributionSetId, rsqlParam, pageable
);
} else {
metaDataPage = distributionSetManagement.findMetaDataByDistributionSetId(pageable, distributionSetId);
metaDataPage = distributionSetManagement.findMetaDataByDistributionSetId(distributionSetId, pageable);
}

return ResponseEntity
Expand All @@ -302,7 +302,7 @@ public ResponseEntity<PagedList<MgmtMetadata>> getMetadata(
public ResponseEntity<MgmtMetadata> getMetadataValue(final Long distributionSetId, final String metadataKey) {
// check if distribution set exists otherwise throw exception immediately
final DistributionSetMetadata findOne = distributionSetManagement
.getMetaDataByDistributionSetId(distributionSetId, metadataKey)
.findMetaDataByDistributionSetId(distributionSetId, metadataKey)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, metadataKey));
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(findOne));
}
Expand All @@ -326,7 +326,7 @@ public ResponseEntity<Void> deleteMetadata(final Long distributionSetId, final S
@Override
public ResponseEntity<List<MgmtMetadata>> createMetadata(final Long distributionSetId, final List<MgmtMetadata> metadataRest) {
// check if distribution set exists otherwise throw exception immediately
final List<DistributionSetMetadata> created = distributionSetManagement.createMetaData(distributionSetId,
final List<DistributionSetMetadata> created = distributionSetManagement.putMetaData(distributionSetId,
MgmtDistributionSetMapper.fromRequestDsMetadata(metadataRest, entityFactory));
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);

Expand Down Expand Up @@ -357,7 +357,7 @@ public ResponseEntity<PagedList<MgmtSoftwareModule>> getAssignedSoftwareModules(
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<SoftwareModule> softwaremodules = softwareModuleManagement.findByAssignedTo(pageable, distributionSetId);
final Page<SoftwareModule> softwaremodules = softwareModuleManagement.findByAssignedTo(distributionSetId, pageable);
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(
softwaremodules.getContent()), softwaremodules.getTotalElements()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ResponseEntity<PagedList<MgmtTag>> getDistributionSetTags(
distributionSetTags = distributionSetTagManagement.findAll(pageable);
count = distributionSetTagManagement.count();
} else {
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(pageable, rsqlParam);
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(rsqlParam, pageable);
distributionSetTags = page;
count = page.getTotalElements();
}
Expand Down Expand Up @@ -137,9 +137,9 @@ public ResponseEntity<PagedList<MgmtDistributionSet>> getAssignedDistributionSet
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
Page<DistributionSet> findDistrAll;
if (rsqlParam == null) {
findDistrAll = distributionSetManagement.findByTag(pageable, distributionsetTagId);
findDistrAll = distributionSetManagement.findByTag(distributionsetTagId, pageable);
} else {
findDistrAll = distributionSetManagement.findByRsqlAndTag(pageable, rsqlParam, distributionsetTagId);
findDistrAll = distributionSetManagement.findByRsqlAndTag(rsqlParam, distributionsetTagId, pageable);
}

final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDistrAll.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetType
final Slice<DistributionSetType> findModuleTypessAll;
long countModulesAll;
if (rsqlParam != null) {
findModuleTypessAll = distributionSetTypeManagement.findByRsql(pageable, rsqlParam);
findModuleTypessAll = distributionSetTypeManagement.findByRsql(rsqlParam, pageable);
countModulesAll = ((Page<DistributionSetType>) findModuleTypessAll).getTotalElements();
} else {
findModuleTypessAll = distributionSetTypeManagement.findAll(pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ResponseEntity<PagedList<MgmtSoftwareModule>> getSoftwareModules(
final Slice<SoftwareModule> findModulesAll;
final long countModulesAll;
if (rsqlParam != null) {
findModulesAll = softwareModuleManagement.findByRsql(pageable, rsqlParam);
findModulesAll = softwareModuleManagement.findByRsql(rsqlParam, pageable);
countModulesAll = ((Page<SoftwareModule>) findModulesAll).getTotalElements();
} else {
findModulesAll = softwareModuleManagement.findAll(pageable);
Expand All @@ -191,7 +191,7 @@ public ResponseEntity<List<MgmtSoftwareModule>> createSoftwareModules(final List
log.debug("creating {} softwareModules", softwareModules.size());

for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) {
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.getByKey(sm.getType());
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(sm.getType());
opt.ifPresent(smType -> {
if (smType.isDeleted()) {
final String text = "Cannot create Software Module from type with key {0}. Software Module Type already deleted!";
Expand Down Expand Up @@ -245,7 +245,7 @@ public ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(
final Page<SoftwareModuleMetadata> metaDataPage;

if (rsqlParam != null) {
metaDataPage = softwareModuleManagement.findMetaDataByRsql(pageable, softwareModuleId, rsqlParam);
metaDataPage = softwareModuleManagement.findMetaDataByRsql(softwareModuleId, rsqlParam, pageable);
} else {
metaDataPage = softwareModuleManagement.findMetaDataBySoftwareModuleId(pageable, softwareModuleId);
}
Expand All @@ -257,7 +257,7 @@ public ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(
@Override
public ResponseEntity<MgmtSoftwareModuleMetadata> getMetadataValue(final Long softwareModuleId, final String metadataKey) {
final SoftwareModuleMetadata findOne = softwareModuleManagement
.getMetaDataBySoftwareModuleId(softwareModuleId, metadataKey).orElseThrow(
.findMetaDataBySoftwareModuleId(softwareModuleId, metadataKey).orElseThrow(
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey));

return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne));
Expand All @@ -282,7 +282,7 @@ public ResponseEntity<Void> deleteMetadata(final Long softwareModuleId, final St
@Override
public ResponseEntity<List<MgmtSoftwareModuleMetadata>> createMetadata(
final Long softwareModuleId, final List<MgmtSoftwareModuleMetadata> metadataRest) {
final List<SoftwareModuleMetadata> created = softwareModuleManagement.createMetaData(
final List<SoftwareModuleMetadata> created = softwareModuleManagement.putMetaData(
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, softwareModuleId, metadataRest));

return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResponseEntity<PagedList<MgmtSoftwareModuleType>> getTypes(
final Slice<SoftwareModuleType> findModuleTypessAll;
final long countModulesAll;
if (rsqlParam != null) {
findModuleTypessAll = softwareModuleTypeManagement.findByRsql(pageable, rsqlParam);
findModuleTypessAll = softwareModuleTypeManagement.findByRsql(rsqlParam, pageable);
countModulesAll = ((Page<SoftwareModuleType>) findModuleTypessAll).getTotalElements();
} else {
findModuleTypessAll = softwareModuleTypeManagement.findAll(pageable);
Expand Down
Loading

0 comments on commit 7c009cd

Please sign in to comment.