Refactoring/simplifying rest resources code (#2443)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-06-10 14:06:43 +03:00
committed by GitHub
parent 6167dce214
commit e643707d41
42 changed files with 395 additions and 490 deletions

View File

@@ -9,20 +9,21 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeActionSortParam;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtActionMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -41,10 +42,7 @@ public class MgmtActionResource implements MgmtActionRestApi {
public ResponseEntity<PagedList<MgmtAction>> getActions(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeActionSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeActionSortParam(sortParam));
final Slice<Action> actions;
final long totalActionCount;

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeDistributionSetSortParam;
import java.text.MessageFormat;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collection;
@@ -38,13 +40,18 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleAssi
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDeploymentRequestMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtSoftwareModuleMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetFilterQueryMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetInvalidationManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
@@ -64,7 +71,6 @@ import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -113,11 +119,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Override
public ResponseEntity<PagedList<MgmtDistributionSet>> getDistributionSets(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeDistributionSetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Slice<DistributionSet> findDsPage;
final long countModulesAll;
if (rsqlParam != null) {
@@ -193,39 +195,27 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Override
public ResponseEntity<PagedList<MgmtTarget>> getAssignedTargets(
final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Long distributionSetId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Page<Target> targetsAssignedDS;
if (rsqlParam != null) {
targetsAssignedDS = this.targetManagement.findByAssignedDistributionSetAndRsql(pageable, distributionSetId,
rsqlParam);
targetsAssignedDS = this.targetManagement.findByAssignedDistributionSetAndRsql(pageable, distributionSetId, rsqlParam);
} else {
targetsAssignedDS = this.targetManagement.findByAssignedDistributionSet(pageable, distributionSetId);
}
return ResponseEntity
.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsAssignedDS.getContent(), tenantConfigHelper),
targetsAssignedDS.getTotalElements()));
return ResponseEntity.ok(new PagedList<>(
MgmtTargetMapper.toResponse(targetsAssignedDS.getContent(), tenantConfigHelper), targetsAssignedDS.getTotalElements()));
}
@Override
public ResponseEntity<PagedList<MgmtTarget>> getInstalledTargets(
final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
// check if distribution set exists otherwise throw exception
// immediately
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);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Page<Target> targetsInstalledDS;
if (rsqlParam != null) {
targetsInstalledDS = this.targetManagement.findByInstalledDistributionSetAndRsql(pageable, distributionSetId, rsqlParam);
@@ -233,26 +223,21 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
targetsInstalledDS = this.targetManagement.findByInstalledDistributionSet(pageable, distributionSetId);
}
return ResponseEntity
.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent(), tenantConfigHelper),
targetsInstalledDS.getTotalElements()));
return ResponseEntity.ok(new PagedList<>(
MgmtTargetMapper.toResponse(targetsInstalledDS.getContent(), tenantConfigHelper), targetsInstalledDS.getTotalElements()));
}
@Override
public ResponseEntity<PagedList<MgmtTargetFilterQuery>> getAutoAssignTargetFilterQueries(
final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Long distributionSetId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Page<TargetFilterQuery> targetFilterQueries = targetFilterQueryManagement
.findByAutoAssignDSAndRsql(pageable, distributionSetId, rsqlParam);
return ResponseEntity
.ok(new PagedList<>(MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent(),
tenantConfigHelper.isConfirmationFlowEnabled(), false), targetFilterQueries.getTotalElements()));
return ResponseEntity.ok(new PagedList<>(
MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent(), tenantConfigHelper.isConfirmationFlowEnabled(), false),
targetFilterQueries.getTotalElements()));
}
@Override
@@ -309,7 +294,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
}
@Override
public ResponseEntity<Void> assignSoftwareModules(final Long distributionSetId, final List<MgmtSoftwareModuleAssignment> softwareModuleIDs) {
public ResponseEntity<Void> assignSoftwareModules(final Long distributionSetId,
final List<MgmtSoftwareModuleAssignment> softwareModuleIDs) {
distributionSetManagement.assignSoftwareModules(
distributionSetId,
softwareModuleIDs.stream()
@@ -329,13 +315,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
public ResponseEntity<PagedList<MgmtSoftwareModule>> getAssignedSoftwareModules(
final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
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(distributionSetId, pageable);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Page<SoftwareModule> softwareModules = softwareModuleManagement.findByAssignedTo(distributionSetId, pageable);
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(
softwaremodules.getContent()), softwaremodules.getTotalElements()));
softwareModules.getContent()), softwareModules.getTotalElements()));
}
@Override

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeTagSortParam;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@@ -18,11 +20,12 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -31,7 +34,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -57,12 +59,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override
public ResponseEntity<PagedList<MgmtTag>> getDistributionSetTags(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
final Slice<DistributionSetTag> distributionSetTags;
final long count;
if (rsqlParam == null) {
@@ -79,8 +77,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
}
@Override
public ResponseEntity<MgmtTag> getDistributionSetTag(
final Long distributionsetTagId) {
public ResponseEntity<MgmtTag> getDistributionSetTag(final Long distributionsetTagId) {
final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId);
final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag);
@@ -90,23 +87,19 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
}
@Override
public ResponseEntity<List<MgmtTag>> createDistributionSetTags(
final List<MgmtTagRequestBodyPut> tags) {
public ResponseEntity<List<MgmtTag>> createDistributionSetTags(final List<MgmtTagRequestBodyPut> tags) {
log.debug("creating {} ds tags", tags.size());
final List<DistributionSetTag> createdTags = distributionSetTagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}
@Override
@AuditLog(entity = "DistributionSetTag", type = AuditLog.Type.UPDATE, description = "Update Distribution Set Tag")
public ResponseEntity<MgmtTag> updateDistributionSetTag(
final Long distributionsetTagId,
final MgmtTagRequestBodyPut restDSTagRest) {
public ResponseEntity<MgmtTag> updateDistributionSetTag(final Long distributionSetTagId, final MgmtTagRequestBodyPut restDSTagRest) {
final DistributionSetTag distributionSetTag = distributionSetTagManagement
.update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName())
.update(entityFactory.tag().update(distributionSetTagId).name(restDSTagRest.getName())
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()));
final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag);
@@ -117,8 +110,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override
@AuditLog(entity = "DistributionSetTag", type = AuditLog.Type.DELETE, description = "Delete Distribution Set Tag")
public ResponseEntity<Void> deleteDistributionSetTag(
final Long distributionsetTagId) {
public ResponseEntity<Void> deleteDistributionSetTag(final Long distributionsetTagId) {
log.debug("Delete {} distribution set tag", distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
@@ -129,37 +121,31 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override
public ResponseEntity<PagedList<MgmtDistributionSet>> getAssignedDistributionSets(
final Long distributionsetTagId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
Page<DistributionSet> findDistrAll;
final Long distributionSetTagId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
final Page<DistributionSet> distributionSets;
if (rsqlParam == null) {
findDistrAll = distributionSetManagement.findByTag(distributionsetTagId, pageable);
distributionSets = distributionSetManagement.findByTag(distributionSetTagId, pageable);
} else {
findDistrAll = distributionSetManagement.findByRsqlAndTag(rsqlParam, distributionsetTagId, pageable);
distributionSets = distributionSetManagement.findByRsqlAndTag(rsqlParam, distributionSetTagId, pageable);
}
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDistrAll.getContent());
return ResponseEntity.ok(new PagedList<>(rest, findDistrAll.getTotalElements()));
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(distributionSets.getContent());
return ResponseEntity.ok(new PagedList<>(rest, distributionSets.getTotalElements()));
}
@Override
public ResponseEntity<Void> assignDistributionSet(
final Long distributionsetTagId,
final Long distributionsetId) {
log.debug("Assign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
this.distributionSetManagement.assignTag(List.of(distributionsetId), distributionsetTagId);
public ResponseEntity<Void> assignDistributionSet(final Long distributionSetTagId, final Long distributionSetId) {
log.debug("Assign ds {} for ds tag {}", distributionSetId, distributionSetTagId);
this.distributionSetManagement.assignTag(List.of(distributionSetId), distributionSetTagId);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<Void> assignDistributionSets(final Long distributionsetTagId, final List<Long> distributionsetIds) {
log.debug("Assign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement.assignTag(distributionsetIds, distributionsetTagId);
public ResponseEntity<Void> assignDistributionSets(final Long distributionSetTagId, final List<Long> distributionSetIds) {
log.debug("Assign DistributionSet {} for ds tag {}", distributionSetIds.size(), distributionSetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement.assignTag(distributionSetIds, distributionSetTagId);
log.debug("Assigned DistributionSet {}", assignedDs.size());
return ResponseEntity.ok().build();
}
@@ -173,9 +159,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override
@AuditLog(entity = "DistributionSetTag", type = AuditLog.Type.UPDATE, description = "Unassign Distribution Set From Tag")
public ResponseEntity<Void> unassignDistributionSet(
final Long distributionsetTagId,
final Long distributionsetId) {
public ResponseEntity<Void> unassignDistributionSet(final Long distributionsetTagId, final Long distributionsetId) {
log.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
this.distributionSetManagement.unassignTag(List.of(distributionsetId), distributionsetTagId);
return ResponseEntity.ok().build();
@@ -183,9 +167,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Override
@AuditLog(entity = "DistributionSetTag", type = AuditLog.Type.UPDATE, description = "Unassign Distribution Sets From Tag")
public ResponseEntity<Void> unassignDistributionSets(
final Long distributionsetTagId,
final List<Long> distributionsetIds) {
public ResponseEntity<Void> unassignDistributionSets(final Long distributionsetTagId, final List<Long> distributionsetIds) {
log.debug("Unassign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
final List<DistributionSet> assignedDs = this.distributionSetManagement.unassignTag(distributionsetIds, distributionsetTagId);
log.debug("Unassigned DistributionSet {}", assignedDs.size());

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeDistributionSetTypeSortParam;
import java.util.Collections;
import java.util.List;
@@ -20,10 +22,11 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionS
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetTypeMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtSoftwareModuleTypeMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.SoftwareModuleTypeNotInDistributionSetTypeException;
@@ -32,7 +35,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -57,12 +59,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@Override
public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetTypes(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeDistributionSetTypeSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetTypeSortParam(sortParam));
final Slice<DistributionSetType> findModuleTypessAll;
long countModulesAll;
if (rsqlParam != null) {

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeRolloutSortParam;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -26,6 +28,8 @@ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponse
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRolloutMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
@@ -83,7 +87,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
public ResponseEntity<PagedList<MgmtRolloutResponseBody>> getRollouts(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeRolloutSortParam(sortParam));
final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL;
final Page<Rollout> rollouts;
@@ -205,7 +209,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Long rolloutId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String representationModeParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeRolloutSortParam(sortParam));
final boolean isFullMode = parseRepresentationMode(representationModeParam) == MgmtRepresentationMode.FULL;
final Page<RolloutGroup> rolloutGroups;
@@ -247,8 +251,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Long rolloutId, final Long groupId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
findRolloutOrThrowException(rolloutId);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sortParam);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeRolloutSortParam(sortParam));
final Page<Target> rolloutGroupTargets;
if (rsqlParam == null) {
rolloutGroupTargets = this.rolloutGroupManagement.findTargetsOfRolloutGroup(groupId, pageable);

View File

@@ -9,12 +9,13 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeSoftwareModuleSortParam;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.validation.ValidationException;
@@ -31,10 +32,10 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtSoftwareModuleMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
@@ -48,7 +49,6 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -137,8 +137,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get());
if (!module.isDeleted()) {
if (Boolean.TRUE.equals(useArtifactUrlHandler)) {
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler,
systemManagement);
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler, systemManagement);
} else {
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response);
}
@@ -158,13 +157,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@Override
public ResponseEntity<PagedList<MgmtSoftwareModule>> getSoftwareModules(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeSoftwareModuleSortParam(sortParam));
final Slice<SoftwareModule> findModulesAll;
final long countModulesAll;
if (rsqlParam != null) {

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeSoftwareModuleTypeSortParam;
import java.util.List;
import org.eclipse.hawkbit.audit.AuditLog;
@@ -17,16 +19,15 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtSoftwareModuleTypeMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -47,13 +48,8 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@Override
public ResponseEntity<PagedList<MgmtSoftwareModuleType>> getTypes(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleTypeSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeSoftwareModuleTypeSortParam(sortParam));
final Slice<SoftwareModuleType> findModuleTypessAll;
final long countModulesAll;
if (rsqlParam != null) {

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeTargetFilterQuerySortParam;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@@ -20,9 +22,10 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery;
import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetFilterQueryMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate;
@@ -34,7 +37,6 @@ import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -72,13 +74,9 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
@Override
public ResponseEntity<PagedList<MgmtTargetFilterQuery>> getFilters(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam,
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam,
final String representationModeParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetFilterQuerySortParam(sortParam));
final Slice<TargetFilterQuery> findTargetFiltersAll;
final long countTargetsAll;
if (rsqlParam != null) {
@@ -98,22 +96,18 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
}
@Override
public ResponseEntity<MgmtTargetFilterQuery> createFilter(
final MgmtTargetFilterQueryRequestBody filter) {
final TargetFilterQuery createdTarget = filterManagement
.create(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter));
public ResponseEntity<MgmtTargetFilterQuery> createFilter(final MgmtTargetFilterQueryRequestBody filter) {
final TargetFilterQuery createdTarget = filterManagement.create(MgmtTargetFilterQueryMapper.fromRequest(entityFactory, filter));
final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(createdTarget,
tenantConfigHelper.isConfirmationFlowEnabled(), false);
final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(
createdTarget, tenantConfigHelper.isConfirmationFlowEnabled(), false);
MgmtTargetFilterQueryMapper.addLinks(response);
return new ResponseEntity<>(response, HttpStatus.CREATED);
}
@Override
public ResponseEntity<MgmtTargetFilterQuery> updateFilter(
final Long filterId,
final MgmtTargetFilterQueryRequestBody targetFilterRest) {
public ResponseEntity<MgmtTargetFilterQuery> updateFilter(final Long filterId, final MgmtTargetFilterQueryRequestBody targetFilterRest) {
log.debug("updating target filter query {}", filterId);
final TargetFilterQuery updateFilter = filterManagement
@@ -153,7 +147,6 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
@Override
public ResponseEntity<MgmtTargetFilterQuery> postAssignedDistributionSet(
final Long filterId, final MgmtDistributionSetAutoAssignment autoAssignRequest) {
final boolean confirmationRequired = autoAssignRequest.getConfirmationRequired() == null
? tenantConfigHelper.isConfirmationFlowEnabled()
: autoAssignRequest.getConfirmationRequired();

View File

@@ -9,6 +9,10 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeActionSortParam;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeActionStatusSortParam;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeTargetSortParam;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collection;
import java.util.Collections;
@@ -43,11 +47,14 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAutoConfirm;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAutoConfirmUpdate;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDeploymentRequestMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.ConfirmationManagement;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -63,7 +70,6 @@ import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -107,12 +113,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<PagedList<MgmtTarget>> getTargets(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetSortParam(sortParam));
final Slice<Target> findTargetsAll;
final long countTargetsAll;
if (rsqlParam != null) {
@@ -130,11 +132,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<List<MgmtTarget>> createTargets(final List<MgmtTargetRequestBody> targets) {
log.debug("creating {} targets", targets.size());
final Collection<Target> createdTargets = this.targetManagement
.create(MgmtTargetMapper.fromRequest(entityFactory, targets));
final Collection<Target> createdTargets = this.targetManagement.create(MgmtTargetMapper.fromRequest(entityFactory, targets));
log.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets, tenantConfigHelper),
HttpStatus.CREATED);
return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets, tenantConfigHelper), HttpStatus.CREATED);
}
@Override
@@ -156,7 +156,6 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
updateTarget = this.targetManagement.update(entityFactory.target().update(targetId)
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
.securityToken(targetRest.getSecurityToken()).requestAttributes(targetRest.getRequestAttributes()));
} else {
updateTarget = this.targetManagement.update(
entityFactory.target().update(targetId).name(targetRest.getName()).description(targetRest.getDescription())
@@ -209,15 +208,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity<PagedList<MgmtAction>> getActionHistory(
final String targetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final String targetId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
findTargetWithExceptionIfNotFound(targetId);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeActionSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeActionSortParam(sortParam));
final Slice<Action> activeActions;
final long totalActionCount;
if (rsqlParam != null) {
@@ -264,8 +259,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
} else {
this.deploymentManagement.cancelAction(actionId);
}
// both functions will throw an exception, when action is in wrong
// state, which is mapped by MgmtResponseExceptionHandler.
// both functions will throw an exception, when action is in wrong state, which is mapped by MgmtResponseExceptionHandler.
return ResponseEntity.noContent().build();
}
@@ -273,7 +267,6 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
@AuditLog(entity = "Target", type = AuditLog.Type.UPDATE, description = "Update Target Action")
public ResponseEntity<MgmtAction> updateAction(final String targetId, final Long actionId, final MgmtActionRequestBodyPut actionUpdate) {
Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(targetId)) {
@@ -292,8 +285,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
@AuditLog(entity = "Target", type = AuditLog.Type.UPDATE, description = "Cancel Target Action Confirmation")
public ResponseEntity<Void> updateActionConfirmation(final String targetId, final Long actionId,
final MgmtActionConfirmationRequestBodyPut actionConfirmation) {
public ResponseEntity<Void> updateActionConfirmation(
final String targetId, final Long actionId, final MgmtActionConfirmationRequestBodyPut actionConfirmation) {
log.debug("updateActionConfirmation with data [targetId={}, actionId={}]: {}", targetId, actionId, actionConfirmation);
return getValidatedAction(targetId, actionId)
@@ -346,13 +339,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
log.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, action.getId(), target.getId());
return ResponseEntity.notFound().build();
}
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam);
final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusByAction(
new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action.getId());
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeActionStatusSortParam(sortParam));
final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusByAction(pageable, action.getId());
return ResponseEntity.ok(new PagedList<>(
MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent(), deploymentManagement),
@@ -365,14 +353,14 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.map(ds -> {
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(ds);
MgmtDistributionSetMapper.addLinks(ds, response);
return response;
}).orElse(null);
if (distributionSetRest == null) {
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.ok(distributionSetRest);
}
return ResponseEntity.ok(distributionSetRest);
}
@Override

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeTagSortParam;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@@ -20,9 +22,10 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
@@ -33,7 +36,6 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -62,12 +64,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@Override
public ResponseEntity<PagedList<MgmtTag>> getTargetTags(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
final Page<TargetTag> findTargetsAll;
if (rsqlParam == null) {
findTargetsAll = this.tagManagement.findAll(pageable);
@@ -126,12 +124,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@Override
public ResponseEntity<PagedList<MgmtTarget>> getAssignedTargets(
final Long targetTagId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
final Page<Target> findTargetsAll;
if (rsqlParam == null) {
findTargetsAll = targetManagement.findByTag(pageable, targetTagId);
@@ -194,7 +188,6 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
private TargetTag findTargetTagById(final Long targetTagId) {
return tagManagement.get(targetTagId)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
return tagManagement.get(targetTagId).orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
}
}

View File

@@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeTargetTypeSortParam;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@@ -20,16 +22,16 @@ import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetTypeMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetTypeMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetTypeManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -51,12 +53,8 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
@Override
public ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetTypeSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetTypeSortParam(sortParam));
final Slice<TargetType> findTargetTypesAll;
long countTargetTypesAll;
if (rsqlParam != null) {

View File

@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.audit.AuditLog;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTenantManagementRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTenantManagementMapper;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022 Bosch.IO GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import java.util.Collection;
import java.util.Collections;
@@ -43,7 +43,7 @@ public final class MgmtActionMapper {
.toList());
}
static MgmtAction toResponse(final Action action, final MgmtRepresentationMode repMode) {
public static MgmtAction toResponse(final Action action, final MgmtRepresentationMode repMode) {
final String controllerId = action.getTarget().getControllerId();
if (repMode == MgmtRepresentationMode.COMPACT) {
return MgmtTargetMapper.toResponse(controllerId, action);

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -48,12 +48,12 @@ public final class MgmtDistributionSetMapper {
* @param sets to convert
* @return converted list of {@link DistributionSet}s
*/
static List<DistributionSetCreate> dsFromRequest(
public static List<DistributionSetCreate> dsFromRequest(
final Collection<MgmtDistributionSetRequestBodyPost> sets, final EntityFactory entityFactory) {
return sets.stream().map(dsRest -> fromRequest(dsRest, entityFactory)).toList();
}
static MgmtDistributionSet toResponse(final DistributionSet distributionSet) {
public static MgmtDistributionSet toResponse(final DistributionSet distributionSet) {
if (distributionSet == null) {
return null;
}
@@ -81,7 +81,7 @@ public final class MgmtDistributionSetMapper {
return response;
}
static void addLinks(final DistributionSet distributionSet, final MgmtDistributionSet response) {
public static void addLinks(final DistributionSet distributionSet, final MgmtDistributionSet response) {
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getAssignedSoftwareModules(response.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null))
@@ -94,7 +94,7 @@ public final class MgmtDistributionSetMapper {
.withRel("metadata").expand());
}
static MgmtTargetAssignmentResponseBody toResponse(final DistributionSetAssignmentResult dsAssignmentResult) {
public static MgmtTargetAssignmentResponseBody toResponse(final DistributionSetAssignmentResult dsAssignmentResult) {
final MgmtTargetAssignmentResponseBody result = new MgmtTargetAssignmentResponseBody();
result.setAlreadyAssigned(dsAssignmentResult.getAlreadyAssigned());
result.setAssignedActions(dsAssignmentResult.getAssignedEntity().stream()
@@ -102,8 +102,7 @@ public final class MgmtDistributionSetMapper {
return result;
}
static MgmtTargetAssignmentResponseBody toResponse(
final List<DistributionSetAssignmentResult> dsAssignmentResults) {
public static MgmtTargetAssignmentResponseBody toResponse(final List<DistributionSetAssignmentResult> dsAssignmentResults) {
final MgmtTargetAssignmentResponseBody result = new MgmtTargetAssignmentResponseBody();
final int alreadyAssigned = dsAssignmentResults.stream()
.mapToInt(DistributionSetAssignmentResult::getAlreadyAssigned).sum();
@@ -116,34 +115,32 @@ public final class MgmtDistributionSetMapper {
return result;
}
// TODO - to be made package visible when hawkbit-mgmt-rest-deprecated is removed
public static List<MgmtDistributionSet> toResponseDistributionSets(final Collection<DistributionSet> sets) {
if (sets == null) {
return Collections.emptyList();
}
return new ResponseList<>(
sets.stream().map(MgmtDistributionSetMapper::toResponse).toList());
return new ResponseList<>(sets.stream().map(MgmtDistributionSetMapper::toResponse).toList());
}
static MgmtMetadata toResponseDsMetadata(final String key, String value) {
public static MgmtMetadata toResponseDsMetadata(final String key, String value) {
final MgmtMetadata metadataRest = new MgmtMetadata();
metadataRest.setKey(key);
metadataRest.setValue(value);
return metadataRest;
}
static Map<String, String> fromRequestDsMetadata(final List<MgmtMetadata> metadata) {
public static Map<String, String> fromRequestDsMetadata(final List<MgmtMetadata> metadata) {
return metadata == null
? Collections.emptyMap()
: metadata.stream().collect(Collectors.toMap(MgmtMetadata::getKey, MgmtMetadata::getValue));
}
static List<MgmtMetadata> toResponseDsMetadata(final Map<String, String> metadata) {
public static List<MgmtMetadata> toResponseDsMetadata(final Map<String, String> metadata) {
return metadata.entrySet().stream().map(e -> toResponseDsMetadata(e.getKey(), e.getValue())).toList();
}
static List<MgmtDistributionSet> toResponseFromDsList(final List<DistributionSet> sets) {
public static List<MgmtDistributionSet> toResponseFromDsList(final List<DistributionSet> sets) {
if (sets == null) {
return Collections.emptyList();
}
@@ -157,8 +154,7 @@ public final class MgmtDistributionSetMapper {
* @param dsRest to convert
* @return converted {@link DistributionSet}
*/
private static DistributionSetCreate fromRequest(final MgmtDistributionSetRequestBodyPost dsRest,
final EntityFactory entityFactory) {
private static DistributionSetCreate fromRequest(final MgmtDistributionSetRequestBodyPost dsRest, final EntityFactory entityFactory) {
final List<Long> modules = new ArrayList<>();
if (dsRest.getOs() != null) {
modules.add(dsRest.getOs().getId());

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -17,6 +17,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssignment;
@@ -28,17 +30,12 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.rest.json.model.ResponseList;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
* A mapper which maps repository model to RESTful model representation and back.
*/
final class MgmtDistributionSetTypeMapper {
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtDistributionSetTypeMapper {
// private constructor, utility class
private MgmtDistributionSetTypeMapper() {
}
static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
public static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
if (smTypesRest == null) {
return Collections.emptyList();
}
@@ -46,14 +43,14 @@ final class MgmtDistributionSetTypeMapper {
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}
static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
public static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
if (types == null) {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtDistributionSetTypeMapper::toResponse).toList());
}
static MgmtDistributionSetType toResponse(final DistributionSetType type) {
public static MgmtDistributionSetType toResponse(final DistributionSetType type) {
final MgmtDistributionSetType result = new MgmtDistributionSetType();
MgmtRestModelMapper.mapTypeToType(result, type);
@@ -65,7 +62,7 @@ final class MgmtDistributionSetTypeMapper {
return result;
}
static void addLinks(final MgmtDistributionSetType result) {
public static void addLinks(final MgmtDistributionSetType result) {
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getMandatoryModules(result.getId()))
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES).expand());

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE;
import static org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE;
@@ -55,15 +55,15 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class MgmtRolloutMapper {
public final class MgmtRolloutMapper {
private static final String NOT_SUPPORTED = " is not supported";
static List<MgmtRolloutResponseBody> toResponseRollout(final List<Rollout> rollouts) {
public static List<MgmtRolloutResponseBody> toResponseRollout(final List<Rollout> rollouts) {
return toResponseRollout(rollouts, false);
}
static List<MgmtRolloutResponseBody> toResponseRolloutWithDetails(final List<Rollout> rollouts) {
public static List<MgmtRolloutResponseBody> toResponseRolloutWithDetails(final List<Rollout> rollouts) {
return toResponseRollout(rollouts, true);
}
@@ -75,7 +75,7 @@ final class MgmtRolloutMapper {
return rollouts.stream().map(rollout -> toResponseRollout(rollout, withDetails)).toList();
}
static MgmtRolloutResponseBody toResponseRollout(final Rollout rollout, final boolean withDetails) {
public static MgmtRolloutResponseBody toResponseRollout(final Rollout rollout, final boolean withDetails) {
final MgmtRolloutResponseBody body = new MgmtRolloutResponseBody();
body.setCreatedAt(rollout.getCreatedAt());
body.setCreatedBy(rollout.getCreatedBy());
@@ -125,8 +125,8 @@ final class MgmtRolloutMapper {
return body;
}
static RolloutCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPost restRequest,
final DistributionSet distributionSet) {
public static RolloutCreate fromRequest(
final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPost restRequest, final DistributionSet distributionSet) {
return entityFactory.rollout().create()
.name(restRequest.getName())
.description(restRequest.getDescription())
@@ -138,13 +138,14 @@ final class MgmtRolloutMapper {
.dynamic(restRequest.isDynamic());
}
static RolloutUpdate fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPut restRequest, final long rolloutId) {
public static RolloutUpdate fromRequest(
final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPut restRequest, final long rolloutId) {
return entityFactory.rollout().update(rolloutId)
.name(restRequest.getName())
.description(restRequest.getDescription());
}
static RolloutCreate fromRetriedRollout(final EntityFactory entityFactory, final Rollout rollout) {
public static RolloutCreate fromRetriedRollout(final EntityFactory entityFactory, final Rollout rollout) {
return entityFactory.rollout().create()
.name(rollout.getName().concat("_retry"))
.description(rollout.getDescription())
@@ -156,13 +157,13 @@ final class MgmtRolloutMapper {
.weight(null);
}
static RolloutGroupCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutGroup restRequest) {
public static RolloutGroupCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutGroup restRequest) {
return entityFactory.rolloutGroup().create().name(restRequest.getName())
.description(restRequest.getDescription()).targetFilterQuery(restRequest.getTargetFilterQuery())
.targetPercentage(restRequest.getTargetPercentage()).conditions(fromRequest(restRequest, false));
}
static DynamicRolloutGroupTemplate fromRequest(final MgmtDynamicRolloutGroupTemplate restRequest) {
public static DynamicRolloutGroupTemplate fromRequest(final MgmtDynamicRolloutGroupTemplate restRequest) {
if (restRequest == null) {
return null;
}
@@ -172,8 +173,7 @@ final class MgmtRolloutMapper {
.build();
}
static RolloutGroupConditions fromRequest(final AbstractMgmtRolloutConditionsEntity restRequest,
final boolean withDefaults) {
public static RolloutGroupConditions fromRequest(final AbstractMgmtRolloutConditionsEntity restRequest, final boolean withDefaults) {
final RolloutGroupConditionBuilder conditions = new RolloutGroupConditionBuilder();
if (withDefaults) {
@@ -201,7 +201,7 @@ final class MgmtRolloutMapper {
return conditions.build();
}
static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(
public static List<MgmtRolloutGroupResponseBody> toResponseRolloutGroup(
final List<RolloutGroup> rollouts, final boolean confirmationFlowEnabled, final boolean withDetails) {
if (rollouts == null) {
return Collections.emptyList();
@@ -210,8 +210,8 @@ final class MgmtRolloutMapper {
return rollouts.stream().map(group -> toResponseRolloutGroup(group, withDetails, confirmationFlowEnabled)).toList();
}
static MgmtRolloutGroupResponseBody toResponseRolloutGroup(final RolloutGroup rolloutGroup,
final boolean withDetailedStatus, final boolean confirmationFlowEnabled) {
public static MgmtRolloutGroupResponseBody toResponseRolloutGroup(
final RolloutGroup rolloutGroup, final boolean withDetailedStatus, final boolean confirmationFlowEnabled) {
final MgmtRolloutGroupResponseBody body = new MgmtRolloutGroupResponseBody();
body.setCreatedAt(rolloutGroup.getCreatedAt());
body.setCreatedBy(rolloutGroup.getCreatedBy());

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -30,6 +30,8 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtDownloadArtifactResource;
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResource;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate;
@@ -39,6 +41,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.rest.json.model.ResponseList;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
/**
* A mapper which maps repository model to RESTful model representation and back.
@@ -46,8 +49,8 @@ import org.springframework.hateoas.Link;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtSoftwareModuleMapper {
static List<SoftwareModuleMetadataCreate> fromRequestSwMetadata(final EntityFactory entityFactory,
final Long softwareModuleId, final Collection<MgmtSoftwareModuleMetadata> metadata) {
public static List<SoftwareModuleMetadataCreate> fromRequestSwMetadata(
final EntityFactory entityFactory, final Long softwareModuleId, final Collection<MgmtSoftwareModuleMetadata> metadata) {
if (metadata == null) {
return Collections.emptyList();
}
@@ -59,8 +62,8 @@ public final class MgmtSoftwareModuleMapper {
.toList();
}
static List<SoftwareModuleCreate> smFromRequest(final EntityFactory entityFactory,
final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest) {
public static List<SoftwareModuleCreate> smFromRequest(
final EntityFactory entityFactory, final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest) {
if (smsRest == null) {
return Collections.emptyList();
}
@@ -68,7 +71,7 @@ public final class MgmtSoftwareModuleMapper {
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}
static List<MgmtSoftwareModule> toResponse(final Collection<SoftwareModule> softwareModules) {
public static List<MgmtSoftwareModule> toResponse(final Collection<SoftwareModule> softwareModules) {
if (softwareModules == null) {
return Collections.emptyList();
}
@@ -76,7 +79,7 @@ public final class MgmtSoftwareModuleMapper {
return new ResponseList<>(softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).toList());
}
static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(final Collection<SoftwareModuleMetadata> metadata) {
public static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(final Collection<SoftwareModuleMetadata> metadata) {
if (metadata == null) {
return Collections.emptyList();
}
@@ -84,7 +87,7 @@ public final class MgmtSoftwareModuleMapper {
return metadata.stream().map(MgmtSoftwareModuleMapper::toResponseSwMetadata).toList();
}
static MgmtSoftwareModuleMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) {
public static MgmtSoftwareModuleMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) {
final MgmtSoftwareModuleMetadata metadataRest = new MgmtSoftwareModuleMetadata();
metadataRest.setKey(metadata.getKey());
metadataRest.setValue(metadata.getValue());
@@ -92,7 +95,7 @@ public final class MgmtSoftwareModuleMapper {
return metadataRest;
}
static MgmtSoftwareModule toResponse(final SoftwareModule softwareModule) {
public static MgmtSoftwareModule toResponse(final SoftwareModule softwareModule) {
if (softwareModule == null) {
return null;
}
@@ -114,16 +117,16 @@ public final class MgmtSoftwareModuleMapper {
return response;
}
static void addLinks(final SoftwareModule softwareModule, final MgmtSoftwareModule response) {
public static void addLinks(final SoftwareModule softwareModule, final MgmtSoftwareModule response) {
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getArtifacts(response.getId(), null, null))
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_ARTIFACT).expand());
response.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(softwareModule.getType().getId()))
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_TYPE).expand());
response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getId()))
response.add(WebMvcLinkBuilder.linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getId()))
.withRel("metadata").expand());
}
static MgmtArtifact toResponse(final Artifact artifact) {
public static MgmtArtifact toResponse(final Artifact artifact) {
final MgmtArtifact artifactRest = new MgmtArtifact();
artifactRest.setId(artifact.getId());
artifactRest.setSize(artifact.getSize());
@@ -140,13 +143,13 @@ public final class MgmtSoftwareModuleMapper {
return artifactRest;
}
static void addLinks(final Artifact artifact, final MgmtArtifact response) {
response.add(linkTo(methodOn(MgmtDownloadArtifactResource.class)
public static void addLinks(final Artifact artifact, final MgmtArtifact response) {
response.add(WebMvcLinkBuilder.linkTo(methodOn(MgmtDownloadArtifactResource.class)
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")
.expand());
}
static void addLinks(final Artifact artifact, final MgmtArtifact response,
public static void addLinks(final Artifact artifact, final MgmtArtifact response,
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) {
final List<ArtifactUrl> urls = artifactUrlHandler.getUrls(
new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(),

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -30,9 +30,9 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class MgmtSoftwareModuleTypeMapper {
public final class MgmtSoftwareModuleTypeMapper {
static List<SoftwareModuleTypeCreate> smFromRequest(final EntityFactory entityFactory,
public static List<SoftwareModuleTypeCreate> smFromRequest(final EntityFactory entityFactory,
final Collection<MgmtSoftwareModuleTypeRequestBodyPost> smTypesRest) {
if (smTypesRest == null) {
return Collections.emptyList();
@@ -41,7 +41,7 @@ final class MgmtSoftwareModuleTypeMapper {
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
}
static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
public static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
if (types == null) {
return Collections.emptyList();
}
@@ -49,7 +49,7 @@ final class MgmtSoftwareModuleTypeMapper {
return new ResponseList<>(types.stream().map(MgmtSoftwareModuleTypeMapper::toResponse).toList());
}
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {
public static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {
final MgmtSoftwareModuleType result = new MgmtSoftwareModuleType();
MgmtRestModelMapper.mapTypeToType(result, type);

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -34,9 +34,9 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
* A mapper which maps repository model to RESTful model representation and back.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class MgmtTagMapper {
public final class MgmtTagMapper {
static List<MgmtTag> toResponse(final List<TargetTag> targetTags) {
public static List<MgmtTag> toResponse(final List<TargetTag> targetTags) {
final List<MgmtTag> tagsRest = new ArrayList<>();
if (targetTags == null) {
return tagsRest;
@@ -50,7 +50,7 @@ final class MgmtTagMapper {
return new ResponseList<>(tagsRest);
}
static MgmtTag toResponse(final TargetTag targetTag) {
public static MgmtTag toResponse(final TargetTag targetTag) {
final MgmtTag response = new MgmtTag();
if (targetTag == null) {
return response;
@@ -63,14 +63,14 @@ final class MgmtTagMapper {
return response;
}
static void addLinks(final TargetTag targetTag, final MgmtTag response) {
public static void addLinks(final TargetTag targetTag, final MgmtTag response) {
response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getAssignedTargets(targetTag.getId(),
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("assignedTargets")
null, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null)).withRel("assignedTargets")
.expand());
}
static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
public static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
final List<MgmtTag> tagsRest = new ArrayList<>();
if (distributionSetTags == null) {
return tagsRest;
@@ -84,7 +84,7 @@ final class MgmtTagMapper {
return new ResponseList<>(tagsRest);
}
static MgmtTag toResponse(final DistributionSetTag distributionSetTag) {
public static MgmtTag toResponse(final DistributionSetTag distributionSetTag) {
final MgmtTag response = new MgmtTag();
if (distributionSetTag == null) {
return null;
@@ -99,14 +99,14 @@ final class MgmtTagMapper {
return response;
}
static void addLinks(final DistributionSetTag distributionSetTag, final MgmtTag response) {
public static void addLinks(final DistributionSetTag distributionSetTag, final MgmtTag response) {
response.add(linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets(
distributionSetTag.getId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null))
distributionSetTag.getId(), null, MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null))
.withRel("assignedDistributionSets").expand());
}
static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) {
public static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) {
return tags.stream()
.map(tagRest -> entityFactory.tag().create().name(tagRest.getName())
.description(tagRest.getDescription()).colour(tagRest.getColour()))

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -37,7 +37,7 @@ import org.springframework.util.CollectionUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetFilterQueryMapper {
static List<MgmtTargetFilterQuery> toResponse(
public static List<MgmtTargetFilterQuery> toResponse(
final List<TargetFilterQuery> filters, final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
if (CollectionUtils.isEmpty(filters)) {
return Collections.emptyList();
@@ -45,8 +45,8 @@ public final class MgmtTargetFilterQueryMapper {
return filters.stream().map(filter -> toResponse(filter, confirmationFlowEnabled, isRepresentationFull)).toList();
}
static MgmtTargetFilterQuery toResponse(final TargetFilterQuery filter, final boolean confirmationFlowEnabled,
final boolean isRepresentationFull) {
public static MgmtTargetFilterQuery toResponse(
final TargetFilterQuery filter, final boolean confirmationFlowEnabled, final boolean isRepresentationFull) {
final MgmtTargetFilterQuery targetRest = new MgmtTargetFilterQuery();
targetRest.setId(filter.getId());
targetRest.setName(filter.getName());
@@ -81,16 +81,16 @@ public final class MgmtTargetFilterQueryMapper {
return targetRest;
}
static void addLinks(final MgmtTargetFilterQuery targetRest) {
public static void addLinks(final MgmtTargetFilterQuery targetRest) {
targetRest.add(linkTo(methodOn(MgmtTargetFilterQueryRestApi.class)
.postAssignedDistributionSet(targetRest.getId(), null)).withRel("autoAssignDS").expand());
}
static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetFilterQueryRequestBody filterRest) {
public static TargetFilterQueryCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetFilterQueryRequestBody filterRest) {
return entityFactory.targetFilterQuery().create().name(filterRest.getName()).query(filterRest.getQuery());
}
static AutoAssignDistributionSetUpdate fromRequest(final EntityFactory entityFactory, final long filterId,
public static AutoAssignDistributionSetUpdate fromRequest(final EntityFactory entityFactory, final long filterId,
final MgmtDistributionSetAutoAssignment assignRest) {
final ActionType type = MgmtRestModelMapper.convertActionType(assignRest.getType());

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -75,9 +75,9 @@ public final class MgmtTargetMapper {
.withRel(MgmtRestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET).expand());
response.add(linkTo(methodOn(MgmtTargetRestApi.class).getAttributes(response.getControllerId()))
.withRel(MgmtRestConstants.TARGET_V1_ATTRIBUTES).expand());
response.add(linkTo(methodOn(MgmtTargetRestApi.class).getActionHistory(response.getControllerId(), 0,
response.add(linkTo(methodOn(MgmtTargetRestApi.class).getActionHistory(response.getControllerId(), null, 0,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
ActionFields.ID.getJpaEntityFieldName() + ":" + SortDirection.DESC, null))
ActionFields.ID.getJpaEntityFieldName() + ":" + SortDirection.DESC))
.withRel(MgmtRestConstants.TARGET_V1_ACTIONS).expand());
response.add(linkTo(methodOn(MgmtTargetRestApi.class).getMetadata(response.getControllerId()))
.withRel("metadata").expand());
@@ -130,8 +130,8 @@ public final class MgmtTargetMapper {
* @param target the target
* @return the response
*/
public static MgmtTarget toResponse(final Target target, final TenantConfigHelper configHelper,
final Function<Target, PollStatus> pollStatusResolver) {
public static MgmtTarget toResponse(
final Target target, final TenantConfigHelper configHelper, final Function<Target, PollStatus> pollStatusResolver) {
if (target == null) {
return null;
}
@@ -176,31 +176,28 @@ public final class MgmtTargetMapper {
targetRest.setAutoConfirmActive(target.getAutoConfirmationStatus() != null);
}
targetRest.add(
linkTo(methodOn(MgmtTargetRestApi.class).getTarget(target.getControllerId())).withSelfRel().expand());
targetRest.add(linkTo(methodOn(MgmtTargetRestApi.class).getTarget(target.getControllerId())).withSelfRel().expand());
addPollStatus(target, targetRest, pollStatusResolver == null ? configHelper.pollStatusResolver() : pollStatusResolver);
return targetRest;
}
static List<TargetCreate> fromRequest(final EntityFactory entityFactory,
final Collection<MgmtTargetRequestBody> targetsRest) {
public static List<TargetCreate> fromRequest(final EntityFactory entityFactory, final Collection<MgmtTargetRequestBody> targetsRest) {
if (targetsRest == null) {
return Collections.emptyList();
}
return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest))
.toList();
return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest)).toList();
}
static Map<String, String> fromRequestMetadata(final List<MgmtMetadata> metadata) {
public static Map<String, String> fromRequestMetadata(final List<MgmtMetadata> metadata) {
return metadata == null
? Collections.emptyMap()
: metadata.stream().collect(Collectors.toMap(MgmtMetadata::getKey, MgmtMetadata::getValue));
}
static List<MgmtActionStatus> toActionStatusRestResponse(
public static List<MgmtActionStatus> toActionStatusRestResponse(
final Collection<ActionStatus> actionStatus, final DeploymentManagement deploymentManagement) {
if (actionStatus == null) {
return Collections.emptyList();
@@ -214,7 +211,7 @@ public final class MgmtTargetMapper {
.toList();
}
static MgmtAction toResponse(final String targetId, final Action action) {
public static MgmtAction toResponse(final String targetId, final Action action) {
final MgmtAction result = new MgmtAction();
result.setId(action.getId());
@@ -263,7 +260,7 @@ public final class MgmtTargetMapper {
return result;
}
static MgmtAction toResponseWithLinks(final String controllerId, final Action action) {
public static MgmtAction toResponseWithLinks(final String controllerId, final Action action) {
final MgmtAction result = toResponse(controllerId, action);
if (action.isCancelingOrCanceled()) {
@@ -293,7 +290,7 @@ public final class MgmtTargetMapper {
return result;
}
static List<MgmtAction> toResponse(final String targetId, final Collection<Action> actions) {
public static List<MgmtAction> toResponse(final String targetId, final Collection<Action> actions) {
if (actions == null) {
return Collections.emptyList();
}
@@ -301,14 +298,14 @@ public final class MgmtTargetMapper {
return actions.stream().map(action -> toResponse(targetId, action)).toList();
}
static MgmtMetadata toResponseMetadata(final String key, final String value) {
public static MgmtMetadata toResponseMetadata(final String key, final String value) {
final MgmtMetadata metadataRest = new MgmtMetadata();
metadataRest.setKey(key);
metadataRest.setValue(value);
return metadataRest;
}
static List<MgmtMetadata> toResponseMetadata(final Map<String, String> metadata) {
public static List<MgmtMetadata> toResponseMetadata(final Map<String, String> metadata) {
return metadata.entrySet().stream().map(e -> toResponseMetadata(e.getKey(), e.getValue())).toList();
}
@@ -341,7 +338,7 @@ public final class MgmtTargetMapper {
return null;
}
private static MgmtActionStatus toResponse(final ActionStatus actionStatus, final List<String> messages) {
public static MgmtActionStatus toResponse(final ActionStatus actionStatus, final List<String> messages) {
final MgmtActionStatus result = new MgmtActionStatus();
result.setMessages(messages);

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch.IO GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -35,7 +35,7 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MgmtTargetTypeMapper {
static List<TargetTypeCreate> targetFromRequest(
public static List<TargetTypeCreate> targetFromRequest(
final EntityFactory entityFactory, final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
if (targetTypesRest == null) {
return Collections.emptyList();
@@ -45,14 +45,14 @@ public final class MgmtTargetTypeMapper {
.toList();
}
static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
public static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
if (types == null) {
return Collections.emptyList();
}
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).toList());
}
static MgmtTargetType toResponse(final TargetType type) {
public static MgmtTargetType toResponse(final TargetType type) {
final MgmtTargetType result = new MgmtTargetType();
MgmtRestModelMapper.mapTypeToType(result, type);
@@ -62,7 +62,7 @@ public final class MgmtTargetTypeMapper {
return result;
}
static void addLinks(final MgmtTargetType result) {
public static void addLinks(final MgmtTargetType result) {
result.add(linkTo(methodOn(MgmtTargetTypeRestApi.class).getCompatibleDistributionSets(result.getId()))
.withRel(MgmtRestConstants.TARGETTYPE_V1_DS_TYPES).expand());
}

View File

@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@@ -15,7 +15,9 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtTenantManagementResource;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
/**
* A mapper which maps repository model to RESTful model representation and back.
@@ -34,7 +36,7 @@ public final class MgmtTenantManagementMapper {
restConfValue.setCreatedBy(repoConfValue.getCreatedBy());
restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt());
restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy());
restConfValue.add(linkTo(methodOn(MgmtTenantManagementResource.class).getTenantConfigurationValue(key)).withSelfRel().expand());
restConfValue.add(WebMvcLinkBuilder.linkTo(methodOn(MgmtTenantManagementResource.class).getTenantConfigurationValue(key)).withSelfRel().expand());
return restConfValue;
}

View File

@@ -35,22 +35,6 @@ import org.springframework.data.domain.Sort.Direction;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PagingUtility {
public static int sanitizeOffsetParam(final int offset) {
if (offset < 0) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE;
}
return offset;
}
public static int sanitizePageLimitParam(final int pageLimit) {
if (pageLimit < 1) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE;
} else if (pageLimit > MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT;
}
return pageLimit;
}
public static Sort sanitizeTargetSortParam(final String sortParam) {
if (sortParam == null) {
// default
@@ -149,10 +133,25 @@ public final class PagingUtility {
return Sort.by(SortUtility.parse(RolloutGroupFields.class, sortParam));
}
public static Pageable toPageable(final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
public static Pageable toPageable(final int pagingOffsetParam, final int pagingLimitParam, final Sort sort) {
final int sanitizedOffsetParam = sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = sanitizeRolloutSortParam(sortParam);
return new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
return new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sort);
}
private static int sanitizeOffsetParam(final int offset) {
if (offset < 0) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE;
}
return offset;
}
private static int sanitizePageLimitParam(final int pageLimit) {
if (pageLimit < 1) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE;
} else if (pageLimit > MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT) {
return MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT;
}
return pageLimit;
}
}

View File

@@ -41,6 +41,7 @@ import org.awaitility.Awaitility;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;

View File

@@ -33,6 +33,7 @@ import io.qameta.allure.Story;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.DeletedException;