Refactor Management interfaces: find/get pattern (#2609)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -132,7 +132,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSet> getDistributionSet(final Long distributionSetId) {
|
||||
final DistributionSet foundDs = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final DistributionSet foundDs = distributionSetManagement.get(distributionSetId);
|
||||
|
||||
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(foundDs);
|
||||
MgmtDistributionSetMapper.addLinks(foundDs, response);
|
||||
@@ -211,7 +211,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final Long distributionSetId, final String rsqlParam,
|
||||
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
// check if distribution set exists otherwise throw exception immediately
|
||||
distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
distributionSetManagement.get(distributionSetId);
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
|
||||
final Page<Target> targetsInstalledDS;
|
||||
if (rsqlParam != null) {
|
||||
|
||||
@@ -160,7 +160,7 @@ class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
|
||||
}
|
||||
|
||||
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {
|
||||
return distributionSetTagManagement.get(distributionsetTagId)
|
||||
return distributionSetTagManagement.find(distributionsetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId));
|
||||
}
|
||||
}
|
||||
@@ -180,12 +180,12 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
}
|
||||
|
||||
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) {
|
||||
return distributionSetTypeManagement.get(distributionSetTypeId)
|
||||
return distributionSetTypeManagement.find(distributionSetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypeId));
|
||||
}
|
||||
|
||||
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
|
||||
return softwareModuleTypeManagement.get(softwareModuleTypeId)
|
||||
return softwareModuleTypeManagement.find(softwareModuleTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,11 @@ import java.io.InputStream;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNoLongerExistsException;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNoLongerExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -53,7 +52,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
*/
|
||||
@Override
|
||||
public ResponseEntity<InputStream> downloadArtifact(final Long softwareModuleId, final Long artifactId) {
|
||||
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
|
||||
final SoftwareModule module = softwareModuleManagement.find(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
if (module.isDeleted()) {
|
||||
throw new ArtifactBinaryNoLongerExistsException();
|
||||
@@ -61,9 +60,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
final Artifact artifact = module.getArtifact(artifactId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId));
|
||||
|
||||
final DbArtifact file = artifactManagement
|
||||
.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted())
|
||||
.orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
|
||||
final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
|
||||
final HttpServletRequest request = RequestResponseContextHolder.getHttpServletRequest();
|
||||
final String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
|
||||
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
|
||||
|
||||
@@ -273,7 +273,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtRolloutResponseBody> retryRollout(final Long rolloutId) {
|
||||
final Rollout rolloutForRetry = rolloutManagement.get(rolloutId)
|
||||
final Rollout rolloutForRetry = rolloutManagement.find(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
if (rolloutForRetry.isDeleted()) {
|
||||
throw new EntityNotFoundException(Rollout.class, rolloutId);
|
||||
|
||||
@@ -278,7 +278,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
}
|
||||
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId, final Long artifactId) {
|
||||
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
|
||||
final SoftwareModule module = softwareModuleManagement.find(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
|
||||
if (artifactId != null && module.getArtifact(artifactId).isEmpty()) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
}
|
||||
|
||||
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
|
||||
return softwareModuleTypeManagement.get(softwareModuleTypeId)
|
||||
return softwareModuleTypeManagement.find(softwareModuleTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
|
||||
}
|
||||
|
||||
private TargetFilterQuery findFilterWithExceptionIfNotFound(final Long filterId) {
|
||||
return filterManagement.get(filterId)
|
||||
return filterManagement.find(filterId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, filterId));
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
targetManagement.unassignType(targetId);
|
||||
return null;
|
||||
} else {
|
||||
return targetTypeManagement.get(targetRest.getTargetType())
|
||||
return targetTypeManagement.find(targetRest.getTargetType())
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetRest.getTargetType()));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -193,6 +193,6 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
}
|
||||
|
||||
private TargetTag findTargetTagById(final Long targetTagId) {
|
||||
return tagManagement.get(targetTagId).orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
return tagManagement.find(targetTagId).orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
}
|
||||
|
||||
private TargetType findTargetTypeWithExceptionIfNotFound(final Long targetTypeId) {
|
||||
return targetTypeManagement.get(targetTypeId)
|
||||
return targetTypeManagement.find(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public final class MgmtTargetMapper {
|
||||
.description(targetRest.getDescription()).securityToken(targetRest.getSecurityToken())
|
||||
.address(targetRest.getAddress())
|
||||
.targetType(Optional.ofNullable(targetRest.getTargetType())
|
||||
.map(targetTypeId -> targetTypeManagement.get(targetTypeId)
|
||||
.map(targetTypeId -> targetTypeManagement.find(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId)))
|
||||
.map(TargetType.class::cast)
|
||||
.orElse(null))
|
||||
|
||||
Reference in New Issue
Block a user