Add POST REST method for assigning tag to multiple DS (#2280)

!!! the PUT method is deprecated for removal

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-02-13 14:49:55 +02:00
committed by GitHub
parent 99bb88ce55
commit 059fd26fae
3 changed files with 24 additions and 5 deletions

View File

@@ -379,13 +379,24 @@ public interface MgmtDistributionSetTagRestApi {
"and the client has to wait another second.", "and the client has to wait another second.",
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))) content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
}) })
@PutMapping(value = MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING, @PostMapping(value = MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING,
consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE },
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> assignDistributionSets( ResponseEntity<Void> assignDistributionSets(
@PathVariable("distributionsetTagId") Long distributionsetTagId, @PathVariable("distributionsetTagId") Long distributionsetTagId,
@RequestBody List<Long> distributionsetIds); @RequestBody List<Long> distributionsetIds);
/**
* @deprecated since 0.8.0, use {@link #assignDistributionSet(Long, Long)} (POST) instead.
*/
@Deprecated(forRemoval = true, since = "0.8.0")
@PutMapping(value = MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING,
consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE },
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> assignDistributionSetsPut(
@PathVariable("distributionsetTagId") Long distributionsetTagId,
@RequestBody List<Long> distributionsetIds);
/** /**
* Handles the DELETE request to unassign one distribution set from the given tag id. * Handles the DELETE request to unassign one distribution set from the given tag id.
* *

View File

@@ -25,6 +25,8 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice; import org.springframework.data.domain.Slice;
@@ -159,6 +161,13 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
private static final Logger LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE");
@Override
public ResponseEntity<Void> assignDistributionSetsPut(final Long distributionsetTagId, final List<Long> distributionsetIds) {
LOGGER.debug("[DEPRECATED] Deprecated usage of assignDistributionSetsPut. Use assignDistributionSets (POST) instead.");
return assignDistributionSets(distributionsetTagId, distributionsetIds);
}
@Override @Override
public ResponseEntity<Void> unassignDistributionSet( public ResponseEntity<Void> unassignDistributionSet(
final Long distributionsetTagId, final Long distributionsetTagId,

View File

@@ -344,10 +344,9 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(2); final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(2);
mvc.perform( mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).toList()))
.content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).toList())) .contentType(MediaType.APPLICATION_JSON))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());