From a1a3881c477d1ef8c01b984b6660d3747794564f Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 13 Feb 2025 14:32:28 +0200 Subject: [PATCH] Remove deprecated REST Mgmt Methods (#2278) Signed-off-by: Avgustin Marinov --- .../hawkbit-mgmt-resource-deprecated/pom.xml | 79 ------ .../deprecated/DeprecatedMgmtResource.java | 266 ------------------ .../deprecated/DeprecatedMgmtRestApi.java | 209 -------------- .../DistributionSetTagAssignmentResult.java | 41 --- .../deprecated/TargetTagAssignmentResult.java | 41 --- ...gmtAssignedDistributionSetRequestBody.java | 38 --- .../model/MgmtAssignedTargetRequestBody.java | 38 --- ...MgmtDistributionSetTagAssigmentResult.java | 45 --- .../model/MgmtTargetTagAssigmentResult.java | 45 --- .../MgmtDeprecatedResourceTest.java | 205 -------------- hawkbit-mgmt/pom.xml | 3 - 11 files changed, 1010 deletions(-) delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/pom.xml delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtTargetTagAssigmentResult.java delete mode 100644 hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/pom.xml b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/pom.xml deleted file mode 100644 index 25d36be47..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-mgmt-parent - ${revision} - - - hawkbit-mgmt-resource-deprecated - hawkBit :: Management :: REST Resources (DEPRECATED) - - - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - - - org.eclipse.hawkbit - hawkbit-mgmt-resource - ${project.version} - - - - - org.eclipse.hawkbit - hawkbit-repository-test - ${project.version} - test - - - org.eclipse.hawkbit - hawkbit-rest-core - ${project.version} - tests - test - - - org.eclipse.hawkbit - hawkbit-mgmt-resource - ${project.version} - tests - test - - - javax.el - javax.el-api - test - - - org.springframework.boot - spring-boot-starter-json - test - - - org.springframework.security - spring-security-aspects - test - - - org.springframework - spring-context-support - test - - - \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java deleted file mode 100644 index a3f1ab00e..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.function.BiFunction; -import java.util.function.Supplier; - -import jakarta.persistence.EntityManager; - -import lombok.extern.slf4j.Slf4j; -import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; -import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; -import org.eclipse.hawkbit.mgmt.rest.resource.MgmtDistributionSetMapper; -import org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetMapper; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtAssignedDistributionSetRequestBody; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtAssignedTargetRequestBody; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtDistributionSetTagAssigmentResult; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtTargetTagAssigmentResult; -import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.DistributionSetTagManagement; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetTagManagement; -import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; -import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; -import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; -import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository; -import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository; -import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification; -import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; -import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.eclipse.hawkbit.utils.TenantConfigHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.ResponseEntity; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.web.bind.annotation.RestController; - -/** - * REST Resource handling for {@link DistributionSetTag} CRUD operations. - */ -@Slf4j -@RestController -@SuppressWarnings("java:S5738") // will be removed at some point -public class DeprecatedMgmtResource implements DeprecatedMgmtRestApi { - - // logger that logs usage of deprecated API - private static final Logger DEPRECATED_USAGE_LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE"); - - private final DistributionSetRepository distributionSetRepository; - private final DistributionSetTagManagement distributionSetTagManagement; - private final DistributionSetManagement distributionSetManagement; - private final TargetRepository targetRepository; - private final TargetTagRepository targetTagRepository; - private final TargetManagement targetManagement; - private final TargetTagManagement targetTagManagement; - private final PlatformTransactionManager txManager; - private final EntityManager entityManager; - private final TenantConfigHelper tenantConfigHelper; - - @SuppressWarnings("squid:S107") - DeprecatedMgmtResource( - final DistributionSetRepository distributionSetRepository, final DistributionSetTagManagement distributionSetTagManagement, - final DistributionSetManagement distributionSetManagement, - final TargetRepository targetRepository, final TargetTagRepository targetTagRepository, final TargetManagement targetManagement, - final TargetTagManagement targetTagManagement, - final PlatformTransactionManager txManager, final EntityManager entityManager, - final SystemSecurityContext securityContext, final TenantConfigurationManagement configurationManagement) { - this.distributionSetRepository = distributionSetRepository; - this.distributionSetTagManagement = distributionSetTagManagement; - this.distributionSetManagement = distributionSetManagement; - this.targetRepository = targetRepository; - this.targetTagRepository = targetTagRepository; - this.targetManagement = targetManagement; - this.targetTagManagement = targetTagManagement; - this.txManager = txManager; - this.entityManager = entityManager; - tenantConfigHelper = TenantConfigHelper.usingContext(securityContext, configurationManagement); - } - - @Override - public ResponseEntity toggleDistributionSetTagAssignment( - final Long distributionsetTagId, - final List assignedDSRequestBodies) { - DEPRECATED_USAGE_LOGGER.debug("[DEPRECATED] Deprecated POST /rest/v1/distributionsettags/{distributionsetTagId}/assigned/toggleTagAssignment called"); - log.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); - - final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); - - final DistributionSetTagAssignmentResult assigmentResult = - DeploymentHelper.runInNewTransaction( - txManager, - "toggleDistributionSetTagAssignment", - status -> toggleDistributionSetTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName())); - - final MgmtDistributionSetTagAssigmentResult tagAssigmentResultRest = new MgmtDistributionSetTagAssigmentResult(); - tagAssigmentResultRest.setAssignedDistributionSets( - MgmtDistributionSetMapper.toResponseDistributionSets(assigmentResult.getAssignedEntity())); - tagAssigmentResultRest.setUnassignedDistributionSets( - MgmtDistributionSetMapper.toResponseDistributionSets(assigmentResult.getUnassignedEntity())); - - log.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(), assigmentResult.getUnassigned()); - - return ResponseEntity.ok(tagAssigmentResultRest); - } - - @Override - public ResponseEntity> assignDistributionSetsByRequestBody( - final Long distributionsetTagId, - final List assignedDSRequestBodies) { - DEPRECATED_USAGE_LOGGER.debug("[DEPRECATED] Deprecated POST /rest/v1/distributionsettags/{distributionsetTagId}/assigned called"); - log.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); - final List assignedDs = this.distributionSetManagement - .assignTag(findDistributionSetIds(assignedDSRequestBodies), distributionsetTagId); - log.debug("Assigned DistributionSet {}", assignedDs.size()); - return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs)); - } - - @Override - public ResponseEntity toggleTargetTagAssignment( - final Long targetTagId, final List assignedTargetRequestBodies) { - DEPRECATED_USAGE_LOGGER.debug("[DEPRECATED] Deprecated POST /rest/v1/targettags/{targetTagId}/assigned/toggleTagAssignment called"); - log.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); - - final TargetTag targetTag = targetTagManagement.get(targetTagId) - .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId)); - final TargetTagAssignmentResult assigmentResult = - DeploymentHelper.runInNewTransaction( - txManager, - "toggleDistributionSetTagAssignment", - status -> toggleTargetTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName())); - - final MgmtTargetTagAssigmentResult tagAssigmentResultRest = new MgmtTargetTagAssigmentResult(); - tagAssigmentResultRest.setAssignedTargets( - MgmtTargetMapper.toResponse(assigmentResult.getAssignedEntity(), tenantConfigHelper)); - tagAssigmentResultRest.setUnassignedTargets( - MgmtTargetMapper.toResponse(assigmentResult.getUnassignedEntity(), tenantConfigHelper)); - return ResponseEntity.ok(tagAssigmentResultRest); - } - - @Override - public ResponseEntity> assignTargetsByRequestBody( - final Long targetTagId, final List assignedTargetRequestBodies) { - DEPRECATED_USAGE_LOGGER.debug("[DEPRECATED] Deprecated POST /rest/v1/targettags/{targetTagId}/assigned called"); - log.debug("Assign targets {} for target tag {}", assignedTargetRequestBodies, targetTagId); - final List assignedTarget = targetManagement - .assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTagId); - return ResponseEntity.ok(MgmtTargetMapper.toResponse(assignedTarget, tenantConfigHelper)); - } - - private DistributionSetTagAssignmentResult toggleDistributionSetTagAssignment(final Collection ids, final String tagName) { - return updateTag( - ids, - () -> distributionSetTagManagement - .findByName(tagName) - .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)), - (allDs, distributionSetTag) -> { - final List toBeChangedDSs = allDs.stream().filter(set -> set.addTag(distributionSetTag)).toList(); - - final DistributionSetTagAssignmentResult result; - // un-assignment case - if (toBeChangedDSs.isEmpty()) { - final List toRemoveSize = new ArrayList<>(); - for (final JpaDistributionSet set : allDs) { - if (set.removeTag(distributionSetTag)) { - toRemoveSize.add(set); - } - } - result = new DistributionSetTagAssignmentResult(ids.size() - toRemoveSize.size(), - Collections.emptyList(), - toRemoveSize.stream().map(distributionSetRepository::save).map(DistributionSet.class::cast).toList(), - distributionSetTag); - } else { - result = new DistributionSetTagAssignmentResult(ids.size() - toBeChangedDSs.size(), - toBeChangedDSs.stream().map(distributionSetRepository::save).map(DistributionSet.class::cast).toList(), - Collections.emptyList(), distributionSetTag); - } - return result; - }); - } - - private T updateTag( - final Collection dsIds, final Supplier tagSupplier, - final BiFunction, DistributionSetTag, T> updater) { - final List allDs = dsIds.size() == 1 ? - distributionSetRepository.findById(dsIds.iterator().next()).map(List::of).orElseGet(Collections::emptyList) : - distributionSetRepository.findAll(DistributionSetSpecification.byIdsFetch(dsIds)); - if (allDs.size() < dsIds.size()) { - throw new EntityNotFoundException(DistributionSet.class, dsIds, allDs.stream().map(DistributionSet::getId).toList()); - } - - final DistributionSetTag distributionSetTag = tagSupplier.get(); - try { - return updater.apply(allDs, distributionSetTag); - } finally { - // No reason to save the tag - entityManager.detach(distributionSetTag); - } - } - - private TargetTagAssignmentResult toggleTargetTagAssignment(final Collection controllerIds, final String tagName) { - final TargetTag tag = targetTagRepository - .findByNameEquals(tagName) - .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagName)); - final List allTargets = targetRepository - .findAll(TargetSpecifications.byControllerIdWithTagsInJoin(controllerIds)); - if (allTargets.size() < controllerIds.size()) { - throw new EntityNotFoundException(Target.class, controllerIds, - allTargets.stream().map(Target::getControllerId).toList()); - } - - final List alreadyAssignedTargets = targetRepository.findAll( - TargetSpecifications.hasTagName(tagName).and(TargetSpecifications.hasControllerIdIn(controllerIds))); - - // all are already assigned -> unassign - if (alreadyAssignedTargets.size() == allTargets.size()) { - - alreadyAssignedTargets.forEach(target -> target.removeTag(tag)); - return new TargetTagAssignmentResult(0, Collections.emptyList(), - Collections.unmodifiableList(alreadyAssignedTargets), tag); - } - - allTargets.removeAll(alreadyAssignedTargets); - // some or none are assigned -> assign - allTargets.forEach(target -> target.addTag(tag)); - final TargetTagAssignmentResult result = new TargetTagAssignmentResult(alreadyAssignedTargets.size(), - targetRepository.saveAll(allTargets), Collections.emptyList(), tag); - - // no reason to persist the tag - entityManager.detach(tag); - return result; - } - - private static List findDistributionSetIds( - final List assignedDistributionSetRequestBodies) { - return assignedDistributionSetRequestBodies.stream() - .map(MgmtAssignedDistributionSetRequestBody::getDistributionSetId).toList(); - } - - private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) { - return distributionSetTagManagement.get(distributionsetTagId) - .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId)); - } - - private List findTargetControllerIds( - final List assignedTargetRequestBodies) { - return assignedTargetRequestBodies.stream().map(MgmtAssignedTargetRequestBody::getControllerId).toList(); - } -} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java deleted file mode 100644 index 1860c6ed1..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java +++ /dev/null @@ -1,209 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated; - -import java.util.List; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.extensions.Extension; -import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; -import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; -import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtAssignedDistributionSetRequestBody; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtAssignedTargetRequestBody; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtDistributionSetTagAssigmentResult; -import org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model.MgmtTargetTagAssigmentResult; -import org.eclipse.hawkbit.rest.OpenApiConfiguration; -import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; -import org.springframework.hateoas.MediaTypes; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; - -/** - * REST Resource handling for DistributionSetTag CRUD operations. - * - * @deprecated since 0.6.0 - */ -// no request mapping specified here to avoid CVE-2021-22044 in Feign client -@Deprecated(forRemoval = true, since = "0.6.0") -@Tag(name = "Deprecated operations", description = "Deprecated REST operations.", - extensions = @Extension(name = OpenApiConfiguration.X_HAWKBIT, properties = @ExtensionProperty(name = "order", value = "2147483647"))) -@SuppressWarnings("java:S1133") // will be removed at some point -public interface DeprecatedMgmtRestApi { - - /** - * Handles the POST request to toggle the assignment of distribution sets by the given tag id.
- * From {@link org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi} - * - * @param distributionsetTagId the ID of the distribution set tag to retrieve - * @param assignedDSRequestBodies list of distribution set ids to be toggled - * @return the list of assigned distribution sets and unassigned distribution sets. - * @deprecated since 0.6.0 with toggle assignment deprecation - */ - @Operation(summary = "[DEPRECATED] Toggle the assignment of distribution sets by the given tag id", - description = "Handles the POST request of toggle distribution assignment. The request body must always be a list of distribution " + - "set ids.", - deprecated = true) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully retrieved"), - @ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))), - @ApiResponse(responseCode = "401", description = "The request requires user authentication.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", - description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) or " + - "data volume restriction applies.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " + - "user in another request at the same time. You may retry your modification request.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " + - "supported by the server for this resource.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " + - "and the client has to wait another second.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))) - }) - @PostMapping(value = MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + - MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING + "/toggleTagAssignment") - @Deprecated(forRemoval = true, since = "0.6.0") - ResponseEntity toggleDistributionSetTagAssignment( - @PathVariable("distributionsetTagId") Long distributionsetTagId, - @RequestBody List assignedDSRequestBodies); - - /** - * Handles the POST request to assign distribution sets to the given tag id..
- * From {@link org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi} - * - * @param distributionsetTagId the ID of the distribution set tag to retrieve - * @param assignedDSRequestBodies list of distribution sets ids to be assigned - * @return the list of assigned distribution set. - * @deprecated since 0.6.0 in favor or assign by ds ids - */ - @Operation(summary = "[DEPRECATED] Assign distribution sets to the given tag id", - description = "Handles the POST request of distribution assignment. Already assigned distribution will be ignored.", - deprecated = true) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully retrieved"), - @ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))), - @ApiResponse(responseCode = "401", description = "The request requires user authentication.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "403", - description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) or " + - "data volume restriction applies.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " + - "user in another request at the same time. You may retry your modification request.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " + - "supported by the server for this resource.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), - @ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " + - "and the client has to wait another second.", - content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))) - }) - @PostMapping(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 }) - @Deprecated(forRemoval = true, since = "0.6.0") - ResponseEntity> assignDistributionSetsByRequestBody( - @PathVariable("distributionsetTagId") Long distributionsetTagId, - @RequestBody List assignedDSRequestBodies); - - /** - * Handles the POST request to toggle the assignment of targets by the given tag id.
- * From {@link org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi} - * - * @param targetTagId the ID of the target tag to retrieve - * @param assignedTargetRequestBodies list of controller ids to be toggled - * @return the list of assigned targets and unassigned targets. - * @deprecated since 0.6.0 - not very usable with very unclear logic - */ - @Operation(summary = "[DEPRECATED] Toggles target tag assignment", description = "Handles the POST request of toggle target " + - "assignment. The request body must always be a list of controller ids.", - deprecated = true) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully retrieved"), - @ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))), - @ApiResponse(responseCode = "401", description = "The request requires user authentication."), - @ApiResponse(responseCode = "403", description = "Insufficient permissions, entity is not allowed to be " + - "changed (i.e. read-only) or data volume restriction applies."), - @ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource."), - @ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json."), - @ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " + - "user in another request at the same time. You may retry your modification request."), - @ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " + - "supported by the server for this resource."), - @ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts and the client has to wait another second.") - }) - @PostMapping(value = MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + - MgmtRestConstants.TARGET_TAG_TARGETS_REQUEST_MAPPING + "/toggleTagAssignment", - consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, - produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) - @Deprecated(forRemoval = true, since = "0.6.0") - ResponseEntity toggleTargetTagAssignment( - @PathVariable("targetTagId") Long targetTagId, - @RequestBody List assignedTargetRequestBodies); - - /** - * Handles the POST request to assign targets to the given tag id.
- * From {@link org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi} - * - * @param targetTagId the ID of the target tag to retrieve - * @param assignedTargetRequestBodies list of controller ids to be assigned - * @return the list of assigned targets. - * @deprecated since 0.6.0 in favour of {@link org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi#assignTargets} - */ - @Operation(summary = "[DEPRECATED] Assign target(s) to given tagId and return targets", - description = "Handles the POST request of target assignment. Already assigned target will be ignored.", - deprecated = true) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Successfully assigned"), - @ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters", - content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))), - @ApiResponse(responseCode = "401", description = "The request requires user authentication."), - @ApiResponse(responseCode = "403", description = "Insufficient permissions, entity is not allowed to be " + - "changed (i.e. read-only) or data volume restriction applies."), - @ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource."), - @ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json."), - @ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " + - "user in another request at the same time. You may retry your modification request."), - @ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " + - "supported by the server for this resource."), - @ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " + - "and the client has to wait another second.") - }) - @PostMapping(value = MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TAG_TARGETS_REQUEST_MAPPING, - consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, - produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) - @Deprecated(forRemoval = true, since = "0.6.0") - ResponseEntity> assignTargetsByRequestBody( - @PathVariable("targetTagId") Long targetTagId, - @RequestBody List assignedTargetRequestBodies); -} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java deleted file mode 100644 index aefaac2fb..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated; - -import java.util.List; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; -import org.eclipse.hawkbit.repository.model.AbstractAssignmentResult; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; - -/** - * Result object for {@link DistributionSetTag} assignments. - * - * @deprecated since 0.6.0 with toggle deprecation - */ -@Deprecated(forRemoval = true, since = "0.6.0") -@Getter -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@SuppressWarnings("java:S1133") // will be removed at some point -public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult { - - private final DistributionSetTag distributionSetTag; - - public DistributionSetTagAssignmentResult(final int alreadyAssigned, - final List assigned, final List unassigned, - final DistributionSetTag distributionSetTag) { - super(alreadyAssigned, assigned, unassigned); - this.distributionSetTag = distributionSetTag; - } -} diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java deleted file mode 100644 index 834dad670..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated; - -import java.util.List; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; -import org.eclipse.hawkbit.repository.model.AbstractAssignmentResult; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; - -/** - * Result object for {@link TargetTag} assignments. - * - * @deprecated since 0.6.0 with deprecation of toggle assignments - */ -@Deprecated(forRemoval = true, since = "0.6.0") -@Getter -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@SuppressWarnings("java:S1133") // will be removed at some point -public class TargetTagAssignmentResult extends AbstractAssignmentResult { - - private final TargetTag targetTag; - - public TargetTagAssignmentResult( - final int alreadyAssigned, final List assigned, final List unassigned, - final TargetTag targetTag) { - super(alreadyAssigned, assigned, unassigned); - this.targetTag = targetTag; - } -} diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java deleted file mode 100644 index 9b06a8121..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedDistributionSetRequestBody.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.ToString; -import lombok.experimental.Accessors; - -/** - * Request Body for PUT. - * - * @deprecated since 0.6.0 with toggle assigment deprecation - */ -@Data -@Accessors(chain = true) -@ToString -@JsonInclude(Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -@Deprecated(forRemoval = true, since = "0.6.0") -@SuppressWarnings("java:S1133") // will be removed at some point -public class MgmtAssignedDistributionSetRequestBody { - - @JsonProperty(value = "id", required = true) - @Schema(example = "24") - private Long distributionSetId; -} diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java deleted file mode 100644 index 1ff62d5d9..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtAssignedTargetRequestBody.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.ToString; -import lombok.experimental.Accessors; - -/** - * Request Body for PUT. - * - * @deprecated Since 0.6.0 - */ -@Data -@Accessors(chain = true) -@ToString -@JsonInclude(Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -@Deprecated(forRemoval = true, since = "0.6.0") -@SuppressWarnings("java:S1133") // will be removed at some point -public class MgmtAssignedTargetRequestBody { - - @JsonProperty(required = true) - @Schema(example = "Target1") - private String controllerId; -} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java deleted file mode 100644 index 4aa6b5c51..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtDistributionSetTagAssigmentResult.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.ToString; -import lombok.experimental.Accessors; -import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet; - -/** - * A json annotated rest model for DSAssigmentResult to RESTful API representation. - * - * @deprecated since 0.6.0 with deprecation of toggle assignments - */ -@Data -@Accessors(chain = true) -@ToString -@JsonInclude(Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -@Deprecated(forRemoval = true, since = "0.6.0") -@SuppressWarnings("java:S1133") // will be removed at some point -public class MgmtDistributionSetTagAssigmentResult { - - @JsonProperty - @Schema(description = "Assigned distribution sets") - private List assignedDistributionSets; - - @JsonProperty - @Schema(description = "Unassigned distribution sets") - private List unassignedDistributionSets; -} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtTargetTagAssigmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtTargetTagAssigmentResult.java deleted file mode 100644 index c0f0a4f4d..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/json/model/MgmtTargetTagAssigmentResult.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated.json.model; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.ToString; -import lombok.experimental.Accessors; -import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; - -/** - * A json annotated rest model for TargetTagAssigmentResult to RESTful API representation. - * - * @deprecated since 0.6.0 with deprecation of toggle assignments - */ -@Data -@Accessors(chain = true) -@ToString -@JsonInclude(Include.NON_NULL) -@JsonIgnoreProperties(ignoreUnknown = true) -@Deprecated(forRemoval = true, since = "0.6.0") -@SuppressWarnings("java:S1133") // will be removed at some point -public class MgmtTargetTagAssigmentResult { - - @JsonProperty - @Schema(description = "Assigned targets") - private List assignedTargets; - - @JsonProperty - @Schema(description = "Unassigned targets") - private List unassignedTargets; -} \ No newline at end of file diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java deleted file mode 100644 index cb52d8bc5..000000000 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/MgmtDeprecatedResourceTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.mgmt.rest.resource.deprecated; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; -import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.mgmt.rest.resource.AbstractManagementApiIntegrationTest; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.test.matcher.Expect; -import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; -import org.eclipse.hawkbit.rest.util.JsonBuilder; -import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; - -@Feature("Component Tests - Management API") -@Story("Distribution Set Tag Resource") -class MgmtDeprecatedResourceTest extends AbstractManagementApiIntegrationTest { - - @Test - @Description("Verifies that tag assignments done through toggle API command are correctly assigned or unassigned.") - @ExpectEvents({ - @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), - @Expect(type = DistributionSetCreatedEvent.class, count = 2), - @Expect(type = DistributionSetUpdatedEvent.class, count = 4) }) - void toggleDistributionSetTagAssignment() throws Exception { - final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); - final int setsAssigned = 2; - final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - - // 2 DistributionSetUpdateEvent - ResultActions result = toggle(tag, sets); - - List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - - assertThat(updated.stream().map(DistributionSet::getId).toList()) - .containsAll(sets.stream().map(DistributionSet::getId).toList()); - - result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "assignedDistributionSets")) - .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "assignedDistributionSets")); - - // 2 DistributionSetUpdateEvent - result = toggle(tag, sets); - - updated = distributionSetManagement.findAll(PAGE).getContent(); - - result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "unassignedDistributionSets")) - .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "unassignedDistributionSets")); - - assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE)).isEmpty(); - } - - @Test - @Description("Verifies that tag assignments done through tag API command are correctly stored in the repository.") - @ExpectEvents({ - @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), - @Expect(type = DistributionSetCreatedEvent.class, count = 2), - @Expect(type = DistributionSetUpdatedEvent.class, count = 2) }) - void assignDistributionSetsWithRequestBody() throws Exception { - final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); - final int setsAssigned = 2; - final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - - final ResultActions result = mvc - .perform( - post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") - .content(JsonBuilder - .ids(sets.stream().map(DistributionSet::getId).toList())) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)); - - final List updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent(); - - assertThat(updated.stream().map(DistributionSet::getId).toList()) - .containsAll(sets.stream().map(DistributionSet::getId).toList()); - - result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0))) - .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1))); - } - - @Test - @Description("Verifes that tag assignments done through toggle API command are correctly assigned or unassigned.") - @ExpectEvents({ - @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 2), - @Expect(type = TargetUpdatedEvent.class, count = 4) }) - void toggleTargetTagAssignment() throws Exception { - final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); - final int targetsAssigned = 2; - final List targets = testdataFactory.createTargets(targetsAssigned); - - ResultActions result = toggle(tag, targets); - - List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); - - assertThat(updated.stream().map(Target::getControllerId).toList()) - .containsAll(targets.stream().map(Target::getControllerId).toList()); - - result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "assignedTargets")) - .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "assignedTargets")); - - result = toggle(tag, targets); - - updated = targetManagement.findAll(PAGE).getContent(); - - result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "unassignedTargets")) - .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "unassignedTargets")); - - assertThat(targetManagement.findByTag(PAGE, tag.getId())).isEmpty(); - } - - @Test - @Description("Verifies that tag assignments done through tag API command are correctly stored in the repository.") - @ExpectEvents({ - @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 2), - @Expect(type = TargetUpdatedEvent.class, count = 2) }) - void assignTargetsByRequestBody() throws Exception { - final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); - final int targetsAssigned = 2; - final List targets = testdataFactory.createTargets(targetsAssigned); - - final ResultActions result = mvc - .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") - .content(controllerIdsOld( - targets.stream().map(Target::getControllerId).toList())) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)); - - final List updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); - - assertThat(updated.stream().map(Target::getControllerId).toList()) - .containsAll(targets.stream().map(Target::getControllerId).toList()); - - result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0))) - .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1))); - } - - private ResultActions toggle(final DistributionSetTag tag, final List sets) throws Exception { - return mvc - .perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() - + "/assigned/toggleTagAssignment").content( - JsonBuilder.ids(sets.stream().map(DistributionSet::getId).toList())) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)); - } - - private static String controllerIdsOld(final Collection ids) throws JSONException { - final JSONArray list = new JSONArray(); - for (final String smID : ids) { - list.put(new JSONObject().put("controllerId", smID)); - } - - return list.toString(); - } - - private ResultActions toggle(final TargetTag tag, final List targets) throws Exception { - return mvc - .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() - + "/assigned/toggleTagAssignment") - .content(controllerIdsOld( - targets.stream().map(Target::getControllerId).toList())) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)); - } -} \ No newline at end of file diff --git a/hawkbit-mgmt/pom.xml b/hawkbit-mgmt/pom.xml index a13b2fc6f..1cc505955 100644 --- a/hawkbit-mgmt/pom.xml +++ b/hawkbit-mgmt/pom.xml @@ -27,8 +27,5 @@ hawkbit-mgmt-resource hawkbit-mgmt-starter hawkbit-mgmt-server - - - hawkbit-mgmt-resource-deprecated \ No newline at end of file