diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java index 26788760e..cd66b1aec 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetRestApi.java @@ -2,7 +2,7 @@ * Copyright (c) 2015 Bosch Software Innovations GmbH and others. * * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ @@ -55,7 +55,7 @@ public interface MgmtDistributionSetRestApi { * JsonResponseExceptionHandler is handling the response. */ @RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity> getDistributionSets( + ResponseEntity> getDistributionSets( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -74,7 +74,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getDistributionSet( + ResponseEntity getDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId); /** @@ -90,7 +90,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity> createDistributionSets( + ResponseEntity> createDistributionSets( @RequestBody final List sets); /** @@ -102,7 +102,7 @@ public interface MgmtDistributionSetRestApi { * */ @RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}") - public ResponseEntity deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId); + ResponseEntity deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId); /** * Handles the UPDATE request for a single DistributionSet . @@ -117,7 +117,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}", consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity updateDistributionSet( + ResponseEntity updateDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate); @@ -145,7 +145,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedTargets", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity> getAssignedTargets( + ResponseEntity> getAssignedTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -176,7 +176,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/installedTargets", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity> getInstalledTargets( + ResponseEntity> getInstalledTargets( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @@ -199,7 +199,7 @@ public interface MgmtDistributionSetRestApi { @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedTargets", consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity createAssignedTarget( + ResponseEntity createAssignedTarget( @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final List targetIds); @@ -225,8 +225,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity> getMetadata( - @PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity> getMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -244,8 +243,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata/{metadataKey}", produces = { MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity getMetadataValue( - @PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity getMetadataValue(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey); /** @@ -260,7 +258,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}/metadata/{metadataKey}", produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MetadataRest metadata); /** @@ -273,7 +271,7 @@ public interface MgmtDistributionSetRestApi { * @return status OK if the delete request is successful */ @RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/metadata/{metadataKey}") - public ResponseEntity deleteMetadata(@PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity deleteMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey); /** @@ -289,8 +287,7 @@ public interface MgmtDistributionSetRestApi { @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/metadata", consumes = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }) - public ResponseEntity> createMetadata( - @PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity> createMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final List metadataRest); /** @@ -309,7 +306,7 @@ public interface MgmtDistributionSetRestApi { @RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedSM", consumes = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final List softwareModuleIDs); /** @@ -327,8 +324,7 @@ public interface MgmtDistributionSetRestApi { * {@code distributionSetId} exists. */ @RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/assignedSM/{softwareModuleId}") - public ResponseEntity deleteAssignSoftwareModules( - @PathVariable("distributionSetId") final Long distributionSetId, + ResponseEntity deleteAssignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("softwareModuleId") final Long softwareModuleId); /** @@ -354,7 +350,7 @@ public interface MgmtDistributionSetRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedSM", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - public ResponseEntity> getAssignedSoftwareModules( + ResponseEntity> getAssignedSoftwareModules( @PathVariable("distributionSetId") final Long distributionSetId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index 2db11f489..42199181e 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleAssigment; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetFields; @@ -51,6 +52,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -79,8 +83,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity> getDistributionSets(final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getDistributionSets( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -100,7 +107,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity getDistributionSet(final Long distributionSetId) { + public ResponseEntity getDistributionSet( + @PathVariable("distributionSetId") final Long distributionSetId) { final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponse(foundDs), HttpStatus.OK); @@ -108,7 +116,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @Override public ResponseEntity> createDistributionSets( - final List sets) { + @RequestBody final List sets) { LOG.debug("creating {} distribution sets", sets.size()); // set default Ds type if ds type is null @@ -124,7 +132,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity deleteDistributionSet(final Long distributionSetId) { + public ResponseEntity deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) { final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId); this.distributionSetManagement.deleteDistributionSet(set); @@ -133,8 +141,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity updateDistributionSet(final Long distributionSetId, - final MgmtDistributionSetRequestBodyPut toUpdate) { + public ResponseEntity updateDistributionSet( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) { final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId); if (toUpdate.getDescription() != null) { @@ -154,8 +163,12 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity> getAssignedTargets(final Long distributionSetId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getAssignedTargets( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately @@ -179,8 +192,12 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity> getInstalledTargets(final Long distributionSetId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getInstalledTargets( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -206,8 +223,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity createAssignedTarget(final Long distributionSetId, - final List targetIds) { + public ResponseEntity createAssignedTarget( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestBody final List targetIds) { final DistributionSetAssignmentResult assignDistributionSet = this.deployManagament.assignDistributionSet( distributionSetId, @@ -220,8 +238,12 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity> getMetadata(final Long distributionSetId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getMetadata( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { // check if distribution set exists otherwise throw exception // immediately @@ -250,7 +272,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity getMetadataValue(final Long distributionSetId, final String metadataKey) { + public ResponseEntity getMetadataValue( + @PathVariable("distributionSetId") final Long distributionSetId, + @PathVariable("metadataKey") final String metadataKey) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -260,8 +284,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity updateMetadata(final Long distributionSetId, final String metadataKey, - final MetadataRest metadata) { + public ResponseEntity updateMetadata(@PathVariable("distributionSetId") final Long distributionSetId, + @PathVariable("metadataKey") final String metadataKey, @RequestBody final MetadataRest metadata) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -271,7 +295,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity deleteMetadata(final Long distributionSetId, final String metadataKey) { + public ResponseEntity deleteMetadata(@PathVariable("distributionSetId") final Long distributionSetId, + @PathVariable("metadataKey") final String metadataKey) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -280,8 +305,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity> createMetadata(final Long distributionSetId, - final List metadataRest) { + public ResponseEntity> createMetadata( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestBody final List metadataRest) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -293,8 +319,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity assignSoftwareModules(final Long distributionSetId, - final List softwareModuleIDs) { + public ResponseEntity assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, + @RequestBody final List softwareModuleIDs) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -314,7 +340,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity deleteAssignSoftwareModules(final Long distributionSetId, final Long softwareModuleId) { + public ResponseEntity deleteAssignSoftwareModules( + @PathVariable("distributionSetId") final Long distributionSetId, + @PathVariable("softwareModuleId") final Long softwareModuleId) { // check if distribution set and software module exist otherwise throw // exception immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); @@ -324,8 +352,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { } @Override - public ResponseEntity> getAssignedSoftwareModules(final Long distributionSetId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) { + public ResponseEntity> getAssignedSoftwareModules( + @PathVariable("distributionSetId") final Long distributionSetId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam) { // check if distribution set exists otherwise throw exception // immediately final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index 5d0131fec..907bbb574 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtDistributionSetTagAssigmentRe import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagFields; @@ -36,6 +37,9 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -53,8 +57,11 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity> getDistributionSetTags(final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getDistributionSetTags( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -80,13 +87,15 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity getDistributionSetTag(final Long distributionsetTagId) { + public ResponseEntity getDistributionSetTag( + @PathVariable("distributionsetTagId") final Long distributionsetTagId) { final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); return new ResponseEntity<>(MgmtTagMapper.toResponse(tag), HttpStatus.OK); } @Override - public ResponseEntity> createDistributionSetTags(final List tags) { + public ResponseEntity> createDistributionSetTags( + @RequestBody final List tags) { LOG.debug("creating {} ds tags", tags.size()); final List createdTags = this.tagManagement @@ -96,8 +105,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity updateDistributionSetTag(final Long distributionsetTagId, - final MgmtTagRequestBodyPut restDSTagRest) { + public ResponseEntity updateDistributionSetTag( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @RequestBody final MgmtTagRequestBodyPut restDSTagRest) { LOG.debug("update {} ds tag", restDSTagRest); final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId); @@ -111,7 +121,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity deleteDistributionSetTag(final Long distributionsetTagId) { + public ResponseEntity deleteDistributionSetTag( + @PathVariable("distributionsetTagId") final Long distributionsetTagId) { LOG.debug("Delete {} distribution set tag", distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); @@ -121,15 +132,18 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity> getAssignedDistributionSets(final Long distributionsetTagId) { + public ResponseEntity> getAssignedDistributionSets( + @PathVariable("distributionsetTagId") final Long distributionsetTagId) { final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); return new ResponseEntity<>( - MgmtDistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), HttpStatus.OK); + MgmtDistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), + HttpStatus.OK); } @Override - public ResponseEntity toggleTagAssignment(final Long distributionsetTagId, - final List assignedDSRequestBodies) { + public ResponseEntity toggleTagAssignment( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @RequestBody final List assignedDSRequestBodies) { LOG.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); @@ -151,8 +165,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity> assignDistributionSets(final Long distributionsetTagId, - final List assignedDSRequestBodies) { + public ResponseEntity> assignDistributionSets( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @RequestBody final List assignedDSRequestBodies) { LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); @@ -163,7 +178,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity unassignDistributionSets(final Long distributionsetTagId) { + public ResponseEntity unassignDistributionSets( + @PathVariable("distributionsetTagId") final Long distributionsetTagId) { LOG.debug("Unassign all DS for ds tag {}", distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); if (tag.getAssignedToDistributionSet() == null) { @@ -178,7 +194,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes } @Override - public ResponseEntity unassignDistributionSet(final Long distributionsetTagId, final Long distributionsetId) { + public ResponseEntity unassignDistributionSet( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @PathVariable("distributionsetId") final Long distributionsetId) { LOG.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); this.distributionSetManagement.unAssignTag(distributionsetId, tag); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java index 0e5adccdc..8d5239d9e 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java @@ -86,14 +86,15 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Override public ResponseEntity getDistributionSetType( - @PathVariable final Long distributionSetTypeId) { + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toResponse(foundType), HttpStatus.OK); } @Override - public ResponseEntity deleteDistributionSetType(@PathVariable final Long distributionSetTypeId) { + public ResponseEntity deleteDistributionSetType( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); distributionSetManagement.deleteDistributionSetType(module); @@ -103,7 +104,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Override public ResponseEntity updateDistributionSetType( - @PathVariable final Long distributionSetTypeId, + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -115,7 +116,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR final DistributionSetType updatedDistributionSetType = distributionSetManagement .updateDistributionSetType(type); - return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toResponse(updatedDistributionSetType), HttpStatus.OK); + return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toResponse(updatedDistributionSetType), + HttpStatus.OK); } @Override @@ -140,7 +142,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Override public ResponseEntity> getMandatoryModules( - @PathVariable final Long distributionSetTypeId) { + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toListResponse(foundType.getMandatoryModuleTypes()), @@ -148,8 +150,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity getMandatoryModule(@PathVariable final Long distributionSetTypeId, - @PathVariable final Long softwareModuleTypeId) { + public ResponseEntity getMandatoryModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -164,8 +167,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity getOptionalModule(@PathVariable final Long distributionSetTypeId, - @PathVariable final Long softwareModuleTypeId) { + public ResponseEntity getOptionalModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -181,7 +185,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Override public ResponseEntity> getOptionalModules( - @PathVariable final Long distributionSetTypeId) { + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -190,8 +194,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity removeMandatoryModule(@PathVariable final Long distributionSetTypeId, - @PathVariable final Long softwareModuleTypeId) { + public ResponseEntity removeMandatoryModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -210,8 +215,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity removeOptionalModule(@PathVariable final Long distributionSetTypeId, - @PathVariable final Long softwareModuleTypeId) { + public ResponseEntity removeOptionalModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId); @@ -229,8 +235,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity addMandatoryModule(@PathVariable final Long distributionSetTypeId, - @RequestBody final MgmtId smtId) { + public ResponseEntity addMandatoryModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); @@ -244,8 +250,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR } @Override - public ResponseEntity addOptionalModule(@PathVariable final Long distributionSetTypeId, - @RequestBody final MgmtId smtId) { + public ResponseEntity addOptionalModule( + @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtId smtId) { final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java index ec06c3c8a..ddd7180cf 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @@ -53,8 +54,9 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi */ @Override @ResponseBody - public ResponseEntity downloadArtifact(final Long softwareModuleId, final Long artifactId, - final HttpServletResponse servletResponse, final HttpServletRequest request) { + public ResponseEntity downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("artifactId") final Long artifactId, final HttpServletResponse servletResponse, + final HttpServletRequest request) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); if (null == module || !module.getLocalArtifact(artifactId).isPresent()) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java index ec2eced90..ca4959810 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java @@ -26,6 +26,8 @@ import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; /** @@ -57,7 +59,8 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi { * successful */ @Override - public ResponseEntity downloadArtifactByDownloadId(final String downloadId, + @ResponseBody + public ResponseEntity downloadArtifactByDownloadId(@PathVariable("downloadId") final String downloadId, final HttpServletResponse response) { try { final ValueWrapper cacheWrapper = cache.get(downloadId); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index ba1017cf3..37d5c6fdc 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -15,6 +15,7 @@ import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody; import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBody; import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; @@ -41,7 +42,9 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -63,8 +66,11 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { private DistributionSetManagement distributionSetManagement; @Override - public ResponseEntity> getRollouts(final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getRollouts( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -85,13 +91,14 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { } @Override - public ResponseEntity getRollout(final Long rolloutId) { + public ResponseEntity getRollout(@PathVariable("rolloutId") final Long rolloutId) { final Rollout findRolloutById = findRolloutOrThrowException(rolloutId); return new ResponseEntity<>(MgmtRolloutMapper.toResponseRollout(findRolloutById), HttpStatus.OK); } @Override - public ResponseEntity create(@RequestBody final MgmtRolloutRestRequestBody rolloutRequestBody) { + public ResponseEntity create( + @RequestBody final MgmtRolloutRestRequestBody rolloutRequestBody) { // first check the given RSQL query if it's well formed, otherwise and // exception is thrown @@ -142,7 +149,8 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { } @Override - public ResponseEntity start(final Long rolloutId, final boolean startAsync) { + public ResponseEntity start(@PathVariable("rolloutId") final Long rolloutId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_ASYNC, defaultValue = "false") final boolean startAsync) { final Rollout rollout = findRolloutOrThrowException(rolloutId); if (startAsync) { this.rolloutManagement.startRolloutAsync(rollout); @@ -153,22 +161,26 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { } @Override - public ResponseEntity pause(final Long rolloutId) { + public ResponseEntity pause(@PathVariable("rolloutId") final Long rolloutId) { final Rollout rollout = findRolloutOrThrowException(rolloutId); this.rolloutManagement.pauseRollout(rollout); return ResponseEntity.ok().build(); } @Override - public ResponseEntity resume(final Long rolloutId) { + public ResponseEntity resume(@PathVariable("rolloutId") final Long rolloutId) { final Rollout rollout = findRolloutOrThrowException(rolloutId); this.rolloutManagement.resumeRollout(rollout); return ResponseEntity.ok().build(); } @Override - public ResponseEntity> getRolloutGroups(final Long rolloutId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getRolloutGroups( + @PathVariable("rolloutId") final Long rolloutId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final Rollout rollout = findRolloutOrThrowException(rolloutId); final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); @@ -191,15 +203,20 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { } @Override - public ResponseEntity getRolloutGroup(final Long rolloutId, final Long groupId) { + public ResponseEntity getRolloutGroup(@PathVariable("rolloutId") final Long rolloutId, + @PathVariable("groupId") final Long groupId) { findRolloutOrThrowException(rolloutId); final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId); return ResponseEntity.ok(MgmtRolloutMapper.toResponseRolloutGroup(rolloutGroup)); } @Override - public ResponseEntity> getRolloutGroupTargets(final Long rolloutId, final Long groupId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId, + @PathVariable("groupId") final Long groupId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { findRolloutOrThrowException(rolloutId); final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 51b543366..866120c5b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -42,6 +42,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @@ -61,7 +62,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { private SoftwareManagement softwareManagement; @Override - public ResponseEntity uploadArtifact(@PathVariable final Long softwareModuleId, + public ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam("file") final MultipartFile file, @RequestParam(value = "filename", required = false) final String optionalFileName, @RequestParam(value = "md5sum", required = false) final String md5Sum, @@ -92,15 +93,18 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity> getArtifacts(@PathVariable final Long softwareModuleId) { + @ResponseBody + public ResponseEntity> getArtifacts( + @PathVariable("softwareModuleId") final Long softwareModuleId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); return new ResponseEntity<>(MgmtSoftwareModuleMapper.artifactsToResponse(module.getArtifacts()), HttpStatus.OK); } @Override - public ResponseEntity getArtifact(@PathVariable final Long softwareModuleId, - @PathVariable final Long artifactId) { + @ResponseBody + public ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("artifactId") final Long artifactId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(module.getLocalArtifact(artifactId).get()), @@ -108,8 +112,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity deleteArtifact(@PathVariable final Long softwareModuleId, - @PathVariable final Long artifactId) { + @ResponseBody + public ResponseEntity deleteArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("artifactId") final Long artifactId) { findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); artifactManagement.deleteLocalArtifact(artifactId); @@ -147,7 +152,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity getSoftwareModule(@PathVariable final Long softwareModuleId) { + public ResponseEntity getSoftwareModule( + @PathVariable("softwareModuleId") final Long softwareModuleId) { final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponse(findBaseSoftareModule), HttpStatus.OK); @@ -166,7 +172,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity updateSoftwareModule(@PathVariable final Long softwareModuleId, + public ResponseEntity updateSoftwareModule( + @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); @@ -183,7 +190,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity deleteSoftwareModule(@PathVariable final Long softwareModuleId) { + public ResponseEntity deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); softwareManagement.deleteSoftwareModule(module); @@ -192,7 +199,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity> getMetadata(@PathVariable final Long softwareModuleId, + public ResponseEntity> getMetadata( + @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @@ -222,19 +230,17 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity getMetadataValue(@PathVariable final Long softwareModuleId, - @PathVariable final String metadataKey) { - // check if distribution set exists otherwise throw exception - // immediately + public ResponseEntity getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); + final SoftwareModuleMetadata findOne = softwareManagement + .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); return ResponseEntity. ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne)); } @Override - public ResponseEntity updateMetadata(@PathVariable final Long softwareModuleId, - @PathVariable final String metadataKey, @RequestBody final MetadataRest metadata) { - // check if software module exists otherwise throw exception immediately + public ResponseEntity updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("metadataKey") final String metadataKey, @RequestBody final MetadataRest metadata) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); final SoftwareModuleMetadata updated = softwareManagement .updateSoftwareModuleMetadata(new SoftwareModuleMetadata(metadataKey, sw, metadata.getValue())); @@ -242,18 +248,17 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } @Override - public ResponseEntity deleteMetadata(@PathVariable final Long softwareModuleId, - @PathVariable final String metadataKey) { - // check if software module exists otherwise throw exception immediately + public ResponseEntity deleteMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); softwareManagement.deleteSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); return ResponseEntity.ok().build(); } @Override - public ResponseEntity> createMetadata(@PathVariable final Long softwareModuleId, + public ResponseEntity> createMetadata( + @PathVariable("softwareModuleId") final Long softwareModuleId, @RequestBody final List metadataRest) { - // check if software module exists otherwise throw exception immediately final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); final List created = softwareManagement @@ -273,4 +278,5 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { } return module; } + } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java index ab23046b3..deba883f6 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java @@ -14,6 +14,7 @@ import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -30,6 +31,9 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -43,8 +47,11 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes private SoftwareManagement softwareManagement; @Override - public ResponseEntity> getTypes(final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getTypes( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -69,14 +76,16 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes } @Override - public ResponseEntity getSoftwareModuleType(final Long softwareModuleTypeId) { + public ResponseEntity getSoftwareModuleType( + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final SoftwareModuleType foundType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId); return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(foundType), HttpStatus.OK); } @Override - public ResponseEntity deleteSoftwareModuleType(final Long softwareModuleTypeId) { + public ResponseEntity deleteSoftwareModuleType( + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) { final SoftwareModuleType module = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId); this.softwareManagement.deleteSoftwareModuleType(module); @@ -85,8 +94,9 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes } @Override - public ResponseEntity updateSoftwareModuleType(final Long softwareModuleTypeId, - final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) { + public ResponseEntity updateSoftwareModuleType( + @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId, + @RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) { final SoftwareModuleType type = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId); // only description can be modified @@ -100,7 +110,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes @Override public ResponseEntity> createSoftwareModuleTypes( - final List softwareModuleTypes) { + @RequestBody final List softwareModuleTypes) { final List createdSoftwareModules = this.softwareManagement .createSoftwareModuleType(MgmtSoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes)); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index 449c57362..4a7c760e3 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -49,6 +49,8 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -66,7 +68,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { private DeploymentManagement deploymentManagement; @Override - public ResponseEntity getTarget(final String targetId) { + public ResponseEntity getTarget(@PathVariable("targetId") final String targetId) { final Target findTarget = findTargetWithExceptionIfNotFound(targetId); // to single response include poll status final MgmtTarget response = MgmtTargetMapper.toResponse(findTarget); @@ -77,8 +79,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity> getTargets(final int pagingOffsetParam, final int pagingLimitParam, - final String sortParam, final String rsqlParam) { + public ResponseEntity> getTargets( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -102,7 +107,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity> createTargets(final List targets) { + public ResponseEntity> createTargets(@RequestBody final List targets) { LOG.debug("creating {} targets", targets.size()); final Iterable createdTargets = this.targetManagement .createTargets(MgmtTargetMapper.fromRequest(targets)); @@ -111,7 +116,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity updateTarget(final String targetId, final MgmtTargetRequestBody targetRest) { + public ResponseEntity updateTarget(@PathVariable("targetId") final String targetId, + @RequestBody final MgmtTargetRequestBody targetRest) { final Target existingTarget = findTargetWithExceptionIfNotFound(targetId); LOG.debug("updating target {}", existingTarget.getId()); if (targetRest.getDescription() != null) { @@ -126,7 +132,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity deleteTarget(final String targetId) { + public ResponseEntity deleteTarget(@PathVariable("targetId") final String targetId) { final Target target = findTargetWithExceptionIfNotFound(targetId); this.targetManagement.deleteTargets(target.getId()); LOG.debug("{} target deleted, return status {}", targetId, HttpStatus.OK); @@ -134,7 +140,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity getAttributes(final String targetId) { + public ResponseEntity getAttributes(@PathVariable("targetId") final String targetId) { final Target foundTarget = findTargetWithExceptionIfNotFound(targetId); final Map controllerAttributes = foundTarget.getTargetInfo().getControllerAttributes(); if (controllerAttributes.isEmpty()) { @@ -148,8 +154,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity> getActionHistory(final String targetId, final int pagingOffsetParam, - final int pagingLimitParam, final String sortParam, final String rsqlParam) { + public ResponseEntity> getActionHistory(@PathVariable("targetId") final String targetId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final Target foundTarget = findTargetWithExceptionIfNotFound(targetId); @@ -175,7 +184,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity getAction(final String targetId, final Long actionId) { + public ResponseEntity getAction(@PathVariable("targetId") final String targetId, + @PathVariable("actionId") final Long actionId) { final Target target = findTargetWithExceptionIfNotFound(targetId); final Action action = findActionWithExceptionIfNotFound(actionId); @@ -204,8 +214,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity cancelAction(final String targetId, final Long actionId, - @RequestParam(required = false, defaultValue = "false") final boolean force) { + public ResponseEntity cancelAction(@PathVariable("targetId") final String targetId, + @PathVariable("actionId") final Long actionId, + @RequestParam(value = "force", required = false, defaultValue = "false") final boolean force) { final Target target = findTargetWithExceptionIfNotFound(targetId); final Action action = findActionWithExceptionIfNotFound(actionId); @@ -221,8 +232,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity> getActionStatusList(final String targetId, final Long actionId, - final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) { + public ResponseEntity> getActionStatusList( + @PathVariable("targetId") final String targetId, @PathVariable("actionId") final Long actionId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam) { final Target target = findTargetWithExceptionIfNotFound(targetId); @@ -247,7 +261,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity getAssignedDistributionSet(final String targetId) { + public ResponseEntity getAssignedDistributionSet( + @PathVariable("targetId") final String targetId) { final Target findTarget = findTargetWithExceptionIfNotFound(targetId); final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper .toResponse(findTarget.getAssignedDistributionSet()); @@ -261,8 +276,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity postAssignedDistributionSet(final String targetId, - final MgmtDistributionSetAssigment dsId) { + public ResponseEntity postAssignedDistributionSet(@PathVariable("targetId") final String targetId, + @RequestBody final MgmtDistributionSetAssigment dsId) { findTargetWithExceptionIfNotFound(targetId); final ActionType type = (dsId.getType() != null) ? MgmtRestModelMapper.convertActionType(dsId.getType()) @@ -281,7 +296,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } @Override - public ResponseEntity getInstalledDistributionSet(final String targetId) { + public ResponseEntity getInstalledDistributionSet( + @PathVariable("targetId") final String targetId) { final Target findTarget = findTargetWithExceptionIfNotFound(targetId); final MgmtDistributionSet distributionSetRest = MgmtDistributionSetMapper .toResponse(findTarget.getTargetInfo().getInstalledDistributionSet()); @@ -309,4 +325,5 @@ public class MgmtTargetResource implements MgmtTargetRestApi { } return findAction; } + } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index d98518208..03265a76c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTargetTagAssigmentResult; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagFields; @@ -36,7 +37,9 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -54,8 +57,11 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { private TargetManagement targetManagement; @Override - public ResponseEntity> getTargetTags(final int pagingOffsetParam, final int pagingLimitParam, - final String sortParam, final String rsqlParam) { + public ResponseEntity> getTargetTags( + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); @@ -81,7 +87,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity getTargetTag(final Long targetTagId) { + public ResponseEntity getTargetTag(@PathVariable("targetTagId") final Long targetTagId) { final TargetTag tag = findTargetTagById(targetTagId); return new ResponseEntity<>(MgmtTagMapper.toResponse(tag), HttpStatus.OK); } @@ -95,7 +101,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity updateTagretTag(final Long targetTagId, final MgmtTagRequestBodyPut restTargetTagRest) { + public ResponseEntity updateTagretTag(@PathVariable("targetTagId") final Long targetTagId, + @RequestBody final MgmtTagRequestBodyPut restTargetTagRest) { LOG.debug("update {} target tag", restTargetTagRest); final TargetTag targetTag = findTargetTagById(targetTagId); @@ -108,7 +115,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity deleteTargetTag(final Long targetTagId) { + public ResponseEntity deleteTargetTag(@PathVariable("targetTagId") final Long targetTagId) { LOG.debug("Delete {} target tag", targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); @@ -118,15 +125,16 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity> getAssignedTargets(final Long targetTagId) { + public ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId) { final TargetTag targetTag = findTargetTagById(targetTagId); return new ResponseEntity<>(MgmtTargetMapper.toResponseWithLinksAndPollStatus(targetTag.getAssignedToTargets()), HttpStatus.OK); } @Override - public ResponseEntity toggleTagAssignment(final Long targetTagId, - final List assignedTargetRequestBodies) { + public ResponseEntity toggleTagAssignment( + @PathVariable("targetTagId") final Long targetTagId, + @RequestBody final List assignedTargetRequestBodies) { LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); @@ -140,8 +148,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity> assignTargets(final Long targetTagId, - final List assignedTargetRequestBodies) { + public ResponseEntity> assignTargets(@PathVariable("targetTagId") final Long targetTagId, + @RequestBody final List assignedTargetRequestBodies) { LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); final List assignedTarget = this.targetManagement @@ -150,7 +158,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity unassignTargets(final Long targetTagId) { + public ResponseEntity unassignTargets(@PathVariable("targetTagId") final Long targetTagId) { LOG.debug("Unassign all Targets for target tag {}", targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); if (targetTag.getAssignedToTargets() == null) { @@ -162,7 +170,8 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity unassignTarget(final Long targetTagId, final String controllerId) { + public ResponseEntity unassignTarget(@PathVariable("targetTagId") final Long targetTagId, + @PathVariable("controllerId") final String controllerId) { LOG.debug("Unassign target {} for target tag {}", controllerId, targetTagId); final TargetTag targetTag = findTargetTagById(targetTagId); this.targetManagement.unAssignTag(controllerId, targetTag); @@ -177,8 +186,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { return tag; } - private List findTargetControllerIds(final List assignedTargetRequestBodies) { + private List findTargetControllerIds( + final List assignedTargetRequestBodies) { return assignedTargetRequestBodies.stream().map(request -> request.getControllerId()) .collect(Collectors.toList()); } + }