Move deprecated repository and mgmt rest methods in separate module (#2177)
Some already deprecated management REST methods are moved in separate module (together with used only for them repository api and impl) in order to have cleanly separate deprecatd REST API.
The new module is hawkbit-mgmt-resource-deprecated. It is inculded, by default, in hawkbit-mgmt-stater.
* when we decide to remove the deprecated REST API implementation completely - will be easily remved - just module and refs
* deprecated REST API could be excluded (by removing the module from runtime) even before that for the runtimes.
* after removal, for some time (untill the usad management and repository APIs are compatible) it will be possible to refer (and include) the deprecated method implementation together with the next hawkBit versions.
The deprecated methods are:
* POST /rest/v1/distributionsettags/{distributionsetTagId}/assigned/toggleTagAssignment
* POST /rest/v1/distributionsettags/{distributionsetTagId}/assigned
* POST /rest/v1/targettags/{targetTagId}/assigned/toggleTagAssignment
* POST /rest/v1/targettags/{targetTagId}/assigned
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* 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.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.beans.factory.annotation.Autowired;
|
||||
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
|
||||
public class DeprecatedMgmtResource implements DeprecatedMgmtRestApi {
|
||||
|
||||
// logger that logs usage of deprecated API
|
||||
private static final Logger DEPRECATED_USAGE_LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE");
|
||||
|
||||
@Autowired
|
||||
private DistributionSetRepository distributionSetRepository;
|
||||
@Autowired
|
||||
private DistributionSetTagManagement distributionSetTagManagement;
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
@Autowired
|
||||
private TargetRepository targetRepository;
|
||||
@Autowired
|
||||
private TargetTagRepository targetTagRepository;
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
@Autowired
|
||||
private TargetTagManagement targetTagManagement;
|
||||
@Autowired
|
||||
private PlatformTransactionManager txManager;
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
DeprecatedMgmtResource(final SystemSecurityContext securityContext, final TenantConfigurationManagement configurationManagement) {
|
||||
tenantConfigHelper = TenantConfigHelper.usingContext(securityContext, configurationManagement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSetTagAssigmentResult> toggleDistributionSetTagAssignment(
|
||||
final Long distributionsetTagId,
|
||||
final List<MgmtAssignedDistributionSetRequestBody> 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<List<MgmtDistributionSet>> assignDistributionSetsByRequestBody(
|
||||
final Long distributionsetTagId,
|
||||
final List<MgmtAssignedDistributionSetRequestBody> 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<DistributionSet> assignedDs = this.distributionSetManagement
|
||||
.assignTag(findDistributionSetIds(assignedDSRequestBodies), distributionsetTagId);
|
||||
log.debug("Assigned DistributionSet {}", assignedDs.size());
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetTagAssigmentResult> toggleTargetTagAssignment(
|
||||
final Long targetTagId, final List<MgmtAssignedTargetRequestBody> 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<List<MgmtTarget>> assignTargetsByRequestBody(
|
||||
final Long targetTagId, final List<MgmtAssignedTargetRequestBody> 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<Target> assignedTarget = targetManagement
|
||||
.assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTagId);
|
||||
return ResponseEntity.ok(MgmtTargetMapper.toResponse(assignedTarget, tenantConfigHelper));
|
||||
}
|
||||
|
||||
private DistributionSetTagAssignmentResult toggleDistributionSetTagAssignment(final Collection<Long> ids, final String tagName) {
|
||||
return updateTag(
|
||||
ids,
|
||||
() -> distributionSetTagManagement
|
||||
.findByName(tagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)),
|
||||
(allDs, distributionSetTag) -> {
|
||||
final List<JpaDistributionSet> toBeChangedDSs = allDs.stream().filter(set -> set.addTag(distributionSetTag))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final DistributionSetTagAssignmentResult result;
|
||||
// un-assignment case
|
||||
if (toBeChangedDSs.isEmpty()) {
|
||||
for (final JpaDistributionSet set : allDs) {
|
||||
if (set.removeTag(distributionSetTag)) {
|
||||
toBeChangedDSs.add(set);
|
||||
}
|
||||
}
|
||||
result = new DistributionSetTagAssignmentResult(ids.size() - toBeChangedDSs.size(),
|
||||
Collections.emptyList(),
|
||||
Collections.unmodifiableList(
|
||||
toBeChangedDSs.stream().map(distributionSetRepository::save).collect(Collectors.toList())),
|
||||
distributionSetTag);
|
||||
} else {
|
||||
result = new DistributionSetTagAssignmentResult(ids.size() - toBeChangedDSs.size(),
|
||||
Collections.unmodifiableList(
|
||||
toBeChangedDSs.stream().map(distributionSetRepository::save).collect(Collectors.toList())),
|
||||
Collections.emptyList(), distributionSetTag);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
private <T> T updateTag(
|
||||
final Collection<Long> dsIds, final Supplier<DistributionSetTag> tagSupplier,
|
||||
final BiFunction<List<JpaDistributionSet>, DistributionSetTag, T> updater) {
|
||||
final List<JpaDistributionSet> 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<String> controllerIds, final String tagName) {
|
||||
final TargetTag tag = targetTagRepository
|
||||
.findByNameEquals(tagName)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagName));
|
||||
final List<JpaTarget> 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<JpaTarget> 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<Long> findDistributionSetIds(
|
||||
final List<MgmtAssignedDistributionSetRequestBody> assignedDistributionSetRequestBodies) {
|
||||
return assignedDistributionSetRequestBodies.stream()
|
||||
.map(MgmtAssignedDistributionSetRequestBody::getDistributionSetId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {
|
||||
return distributionSetTagManagement.get(distributionsetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId));
|
||||
}
|
||||
|
||||
private List<String> findTargetControllerIds(
|
||||
final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies) {
|
||||
return assignedTargetRequestBodies.stream().map(MgmtAssignedTargetRequestBody::getControllerId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/**
|
||||
* 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.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.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.
|
||||
*/
|
||||
// no request mapping specified here to avoid CVE-2021-22044 in Feign client
|
||||
@Deprecated(forRemoval = true)
|
||||
@Tag(name = "Deprecated Management API", description = "Deprecated REST operations.")
|
||||
public interface DeprecatedMgmtRestApi {
|
||||
|
||||
/**
|
||||
* Handles the POST request to toggle the assignment of distribution sets by
|
||||
* the given tag id.</br>
|
||||
* 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<MgmtDistributionSetTagAssigmentResult> toggleDistributionSetTagAssignment(
|
||||
@PathVariable("distributionsetTagId") Long distributionsetTagId,
|
||||
@RequestBody List<MgmtAssignedDistributionSetRequestBody> assignedDSRequestBodies);
|
||||
|
||||
/**
|
||||
* Handles the POST request to assign distribution sets to the given tag id..</br>
|
||||
* 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<List<MgmtDistributionSet>> assignDistributionSetsByRequestBody(
|
||||
@PathVariable("distributionsetTagId") Long distributionsetTagId,
|
||||
@RequestBody List<MgmtAssignedDistributionSetRequestBody> assignedDSRequestBodies);
|
||||
|
||||
/**
|
||||
* Handles the POST request to toggle the assignment of targets by the given tag id.<br/>
|
||||
* 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<MgmtTargetTagAssigmentResult> toggleTargetTagAssignment(
|
||||
@PathVariable("targetTagId") Long targetTagId,
|
||||
@RequestBody List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies);
|
||||
|
||||
/**
|
||||
* Handles the POST request to assign targets to the given tag id.<br/>
|
||||
* 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<List<MgmtTarget>> assignTargetsByRequestBody(
|
||||
@PathVariable("targetTagId") Long targetTagId,
|
||||
@RequestBody List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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)
|
||||
public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult<DistributionSet> {
|
||||
|
||||
private final DistributionSetTag distributionSetTag;
|
||||
|
||||
public DistributionSetTagAssignmentResult(final int alreadyAssigned,
|
||||
final List<DistributionSet> assigned, final List<DistributionSet> unassigned,
|
||||
final DistributionSetTag distributionSetTag) {
|
||||
super(alreadyAssigned, assigned, unassigned);
|
||||
this.distributionSetTag = distributionSetTag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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)
|
||||
public class TargetTagAssignmentResult extends AbstractAssignmentResult<Target> {
|
||||
|
||||
private final TargetTag targetTag;
|
||||
|
||||
public TargetTagAssignmentResult(
|
||||
final int alreadyAssigned, final List<? extends Target> assigned, final List<? extends Target> unassigned,
|
||||
final TargetTag targetTag) {
|
||||
super(alreadyAssigned, assigned, unassigned);
|
||||
this.targetTag = targetTag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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")
|
||||
public class MgmtAssignedDistributionSetRequestBody {
|
||||
|
||||
@JsonProperty(value = "id", required = true)
|
||||
@Schema(example = "24")
|
||||
private Long distributionSetId;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ToString
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Deprecated(forRemoval = true, since = "0.6.0")
|
||||
public class MgmtAssignedTargetRequestBody {
|
||||
|
||||
@JsonProperty(required = true)
|
||||
@Schema(example = "Target1")
|
||||
private String controllerId;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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")
|
||||
public class MgmtDistributionSetTagAssigmentResult {
|
||||
|
||||
@JsonProperty
|
||||
@Schema(description = "Assigned distribution sets")
|
||||
private List<MgmtDistributionSet> assignedDistributionSets;
|
||||
|
||||
@JsonProperty
|
||||
@Schema(description = "Unassigned distribution sets")
|
||||
private List<MgmtDistributionSet> unassignedDistributionSets;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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")
|
||||
public class MgmtTargetTagAssigmentResult {
|
||||
|
||||
@JsonProperty
|
||||
@Schema(description = "Assigned targets")
|
||||
private List<MgmtTarget> assignedTargets;
|
||||
|
||||
@JsonProperty
|
||||
@Schema(description = "Unassigned targets")
|
||||
private List<MgmtTarget> unassignedTargets;
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
* 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")
|
||||
public 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) })
|
||||
public void toggleDistributionSetTagAssignment() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final int setsAssigned = 2;
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
|
||||
|
||||
// 2 DistributionSetUpdateEvent
|
||||
ResultActions result = toggle(tag, sets);
|
||||
|
||||
List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
|
||||
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.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) })
|
||||
public void assignDistributionSetsWithRequestBody() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final int setsAssigned = 2;
|
||||
final List<DistributionSet> 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<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
|
||||
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.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) })
|
||||
public void toggleTargetTagAssignment() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 2;
|
||||
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
|
||||
|
||||
ResultActions result = toggle(tag, targets);
|
||||
|
||||
List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
|
||||
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.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) })
|
||||
public void assignTargetsByRequestBody() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 2;
|
||||
final List<Target> 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).collect(Collectors.toList())))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
|
||||
|
||||
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
|
||||
assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
|
||||
result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0)))
|
||||
.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1)));
|
||||
}
|
||||
|
||||
private ResultActions toggle(final DistributionSetTag tag, final List<DistributionSet> 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).collect(Collectors.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<String> 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<Target> targets) throws Exception {
|
||||
return mvc
|
||||
.perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId()
|
||||
+ "/assigned/toggleTagAssignment")
|
||||
.content(controllerIdsOld(
|
||||
targets.stream().map(Target::getControllerId).collect(Collectors.toList())))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user