From bb0fb5da8d16f34aa376de87e7dde68e0ceef380 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 21 Apr 2016 11:29:56 +0200 Subject: [PATCH] Add name of @PathVariable Signed-off-by: SirWayne --- .../rest/resource/DataConversionHelper.java | 6 +-- ...r.java => DdiArtifactStoreController.java} | 22 +++++----- ...Controller.java => DdiRootController.java} | 44 ++++++++----------- hawkbit-mgmt-resource/pom.xml | 7 ++- .../system/rest/api/SystemRestApi.java | 7 +-- .../rest/resource/SystemResourceTest.java | 10 ++--- 6 files changed, 47 insertions(+), 49 deletions(-) rename hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/{ArtifactStoreController.java => DdiArtifactStoreController.java} (84%) rename hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/{RootController.java => DdiRootController.java} (91%) diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java index 2fd151f6e..b662f2b5f 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java @@ -117,12 +117,12 @@ public final class DataConversionHelper { // have changed from 'soft' to 'forced' type and we need to // change the payload of the // response because of eTags. - result.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()) + result.add(linkTo(methodOn(DdiRootController.class, tenantAware.getCurrentTenant()) .getControllerBasedeploymentAction(target.getControllerId(), action.getId(), actions.hashCode(), null)).withRel(DdiRestConstants.DEPLOYMENT_BASE_ACTION)); addedUpdate = true; } else if (action.isCancelingOrCanceled() && !addedCancel) { - result.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()) + result.add(linkTo(methodOn(DdiRootController.class, tenantAware.getCurrentTenant()) .getControllerCancelAction(target.getControllerId(), action.getId(), null)) .withRel(DdiRestConstants.CANCEL_ACTION)); addedCancel = true; @@ -130,7 +130,7 @@ public final class DataConversionHelper { } if (target.getTargetInfo().isRequestControllerAttributes()) { - result.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).putConfigData(null, + result.add(linkTo(methodOn(DdiRootController.class, tenantAware.getCurrentTenant()).putConfigData(null, target.getControllerId(), null)).withRel(DdiRestConstants.CONFIG_DATA_ACTION)); } return result; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/ArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java similarity index 84% rename from hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/ArtifactStoreController.java rename to hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 2a6d544ab..4c24b0238 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/ArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -32,21 +32,20 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; /** - * The {@link ArtifactStoreController} of the HawkBit server controller API that - * is queried by the HawkBit target in order to download artifacts independent - * of their own individual resource. This is offered in addition to the - * {@link RootController#downloadArtifact(String, Long, Long, javax.servlet.http.HttpServletResponse)} + * The {@link DdiArtifactStoreController} of the HawkBit server controller API + * that is queried by the HawkBit target in order to download artifacts + * independent of their own individual resource. This is offered in addition to + * the + * {@link DdiRootController#downloadArtifact(String, Long, Long, javax.servlet.http.HttpServletResponse)} * for legacy controllers that can not be fed with a download URI at runtime. */ @RestController -public class ArtifactStoreController implements DdiArtifactStoreControllerRestApi { +public class DdiArtifactStoreController implements DdiArtifactStoreControllerRestApi { - private static final Logger LOG = LoggerFactory.getLogger(ArtifactStoreController.class); + private static final Logger LOG = LoggerFactory.getLogger(DdiArtifactStoreController.class); @Autowired private ArtifactManagement artifactManagement; @@ -61,9 +60,8 @@ public class ArtifactStoreController implements DdiArtifactStoreControllerRestAp private HawkbitSecurityProperties securityProperties; @Override - public ResponseEntity downloadArtifactByFilename(@PathVariable("fileName") final String fileName, - final HttpServletResponse response, final HttpServletRequest request, - @AuthenticationPrincipal final String targetid) { + public ResponseEntity downloadArtifactByFilename(final String fileName, final HttpServletResponse response, + final HttpServletRequest request, final String targetid) { ResponseEntity result; final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); @@ -100,7 +98,7 @@ public class ArtifactStoreController implements DdiArtifactStoreControllerRestAp } @Override - public ResponseEntity downloadArtifactMD5ByFilename(@PathVariable("fileName") final String fileName, + public ResponseEntity downloadArtifactMD5ByFilename(final String fileName, final HttpServletResponse response) { final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/RootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java similarity index 91% rename from hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/RootController.java rename to hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 4f485984b..3a9e07d79 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/RootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -52,20 +52,19 @@ 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; /** - * The {@link RootController} of the hawkBit server DDI API that is queried by + * The {@link DdiRootController} of the hawkBit server DDI API that is queried by * the hawkBit controller in order to pull {@link Action}s that have to be * fulfilled and report status updates concerning the {@link Action} processing. * * Transactional (read-write) as all queries at least update the last poll time. */ @RestController -public class RootController implements DdiRootControllerRestApi { +public class DdiRootController implements DdiRootControllerRestApi { - private static final Logger LOG = LoggerFactory.getLogger(RootController.class); + private static final Logger LOG = LoggerFactory.getLogger(DdiRootController.class); private static final String GIVEN_ACTION_IS_NOT_ASSIGNED_TO_GIVEN_TARGET = "given action ({}) is not assigned to given target ({})."; @Autowired @@ -91,7 +90,7 @@ public class RootController implements DdiRootControllerRestApi { @Override public ResponseEntity> getSoftwareModulesArtifacts( - @PathVariable final String targetid, @PathVariable final Long softwareModuleId) { + final String targetid, final Long softwareModuleId) { LOG.debug("getSoftwareModulesArtifacts({})", targetid); final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId); @@ -107,7 +106,7 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity getControllerBase(@PathVariable final String targetid, + public ResponseEntity getControllerBase(final String targetid, final HttpServletRequest request) { LOG.debug("getControllerBase({})", targetid); @@ -128,9 +127,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity downloadArtifact(@PathVariable final String targetid, - @PathVariable final Long softwareModuleId, @PathVariable final String fileName, - final HttpServletResponse response, final HttpServletRequest request) { + public ResponseEntity downloadArtifact(final String targetid, final Long softwareModuleId, + final String fileName, final HttpServletResponse response, final HttpServletRequest request) { ResponseEntity result; final Target target = controllerManagement.updateLastTargetQuery(targetid, @@ -181,9 +179,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity downloadArtifactMd5(@PathVariable final String targetid, - @PathVariable final Long softwareModuleId, @PathVariable final String fileName, - final HttpServletResponse response, final HttpServletRequest request) { + public ResponseEntity downloadArtifactMd5(final String targetid, final Long softwareModuleId, + final String fileName, final HttpServletResponse response, final HttpServletRequest request) { controllerManagement.updateLastTargetQuery(targetid, IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader())); @@ -206,10 +203,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity getControllerBasedeploymentAction( - @PathVariable @NotEmpty final String targetid, @PathVariable @NotEmpty final Long actionId, - @RequestParam(value = "c", required = false, defaultValue = "-1") final int resource, - final HttpServletRequest request) { + public ResponseEntity getControllerBasedeploymentAction(final String targetid, + final Long actionId, final int resource, final HttpServletRequest request) { LOG.debug("getControllerBasedeploymentAction({},{})", targetid, resource); final Target target = controllerManagement.updateLastTargetQuery(targetid, @@ -242,9 +237,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity postBasedeploymentActionFeedback(@Valid @RequestBody final DdiActionFeedback feedback, - @PathVariable final String targetid, @PathVariable @NotEmpty final Long actionId, - final HttpServletRequest request) { + public ResponseEntity postBasedeploymentActionFeedback(final DdiActionFeedback feedback, + final String targetid, final Long actionId, final HttpServletRequest request) { LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", targetid, actionId, feedback); final Target target = controllerManagement.updateLastTargetQuery(targetid, @@ -277,8 +271,8 @@ public class RootController implements DdiRootControllerRestApi { } - private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid, final Long actionid, - final Action action) { + private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid, + final Long actionid, final Action action) { final ActionStatus actionStatus = new ActionStatus(); actionStatus.setAction(action); @@ -339,8 +333,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity putConfigData(@Valid @RequestBody final DdiConfigData configData, - @PathVariable final String targetid, final HttpServletRequest request) { + public ResponseEntity putConfigData(final DdiConfigData configData, final String targetid, + final HttpServletRequest request) { controllerManagement.updateLastTargetQuery(targetid, IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader())); @@ -350,8 +344,8 @@ public class RootController implements DdiRootControllerRestApi { } @Override - public ResponseEntity getControllerCancelAction(@PathVariable @NotEmpty final String targetid, - @PathVariable @NotEmpty final Long actionId, final HttpServletRequest request) { + public ResponseEntity getControllerCancelAction(final String targetid, final Long actionId, + final HttpServletRequest request) { LOG.debug("getControllerCancelAction({})", targetid); final Target target = controllerManagement.updateLastTargetQuery(targetid, diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index c52506e11..db9535591 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -29,9 +29,14 @@ hawkbit-rest-core ${project.version} + + commons-io + commons-io + 2.4 + - + org.eclipse.hawkbit hawkbit-rest-core ${project.version} diff --git a/hawkbit-system-api/src/main/java/org/eclipse/hawkbit/system/rest/api/SystemRestApi.java b/hawkbit-system-api/src/main/java/org/eclipse/hawkbit/system/rest/api/SystemRestApi.java index aa764d82a..1f2c497e2 100644 --- a/hawkbit-system-api/src/main/java/org/eclipse/hawkbit/system/rest/api/SystemRestApi.java +++ b/hawkbit-system-api/src/main/java/org/eclipse/hawkbit/system/rest/api/SystemRestApi.java @@ -50,7 +50,7 @@ public interface SystemRestApi { */ @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - ResponseEntity deleteConfigurationValue(@PathVariable final String keyName); + ResponseEntity deleteConfigurationValue(@PathVariable("keyName") final String keyName); /** * Handles the GET request of deleting a tenant specific configuration value @@ -64,7 +64,7 @@ public interface SystemRestApi { */ @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - ResponseEntity getConfigurationValue(@PathVariable final String keyName); + ResponseEntity getConfigurationValue(@PathVariable("keyName") final String keyName); /** * Handles the GET request of deleting a tenant specific configuration value @@ -80,7 +80,8 @@ public interface SystemRestApi { */ @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) - ResponseEntity updateConfigurationValue(@PathVariable final String keyName, + ResponseEntity updateConfigurationValue( + @PathVariable("keyName") final String keyName, @RequestBody final SystemTenantConfigurationValueRequest configurationValueRest); } \ No newline at end of file diff --git a/hawkbit-system-resource/src/test/java/org/eclipse/hawkbit/system/rest/resource/SystemResourceTest.java b/hawkbit-system-resource/src/test/java/org/eclipse/hawkbit/system/rest/resource/SystemResourceTest.java index abb61ef67..8458153ea 100644 --- a/hawkbit-system-resource/src/test/java/org/eclipse/hawkbit/system/rest/resource/SystemResourceTest.java +++ b/hawkbit-system-resource/src/test/java/org/eclipse/hawkbit/system/rest/resource/SystemResourceTest.java @@ -65,7 +65,7 @@ public class SystemResourceTest extends AbstractIntegrationTest { tenantConfigurationManagement.addOrUpdateConfiguration(key, notGlobalValue); - mvc.perform(get(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{configId}/", key.getKeyName())) + mvc.perform(get(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}/", key.getKeyName())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("value", equalTo(notGlobalValue))).andExpect(jsonPath("global", equalTo(false))) .andExpect(jsonPath("createdAt", notNullValue())).andExpect(jsonPath("createdBy", notNullValue())); @@ -78,7 +78,7 @@ public class SystemResourceTest extends AbstractIntegrationTest { final TenantConfigurationKey key = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME; final String testValue = "12:12:12"; - mvc.perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{configId}/", key.getKeyName()) + mvc.perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", key.getKeyName()) .content(String.format(BASE_JSON_REQUEST_STRING, testValue)).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -99,7 +99,7 @@ public class SystemResourceTest extends AbstractIntegrationTest { assertThat(tenantConfigurationManagement.getConfigurationValue(key, String.class).getValue()) .isEqualTo(notGlobalValue); - mvc.perform(delete(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{configId}/", key.getKeyName())) + mvc.perform(delete(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}/", key.getKeyName())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNoContent()); assertThat(tenantConfigurationManagement.getConfigurationValue(key, String.class).isGlobal()).isEqualTo(true); @@ -115,7 +115,7 @@ public class SystemResourceTest extends AbstractIntegrationTest { final String testValue = "12:12:12"; final MvcResult mvcResult = mvc - .perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{configId}", notExistingKey) + .perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", notExistingKey) .content(String.format(BASE_JSON_REQUEST_STRING, testValue)) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); @@ -134,7 +134,7 @@ public class SystemResourceTest extends AbstractIntegrationTest { final String testValue = "invalidFormattedDuration"; final MvcResult mvcResult = mvc - .perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{configId}", key.getKeyName()) + .perform(put(SystemRestConstant.SYSTEM_V1_REQUEST_MAPPING + "/configs/{keyName}", key.getKeyName()) .content(String.format(BASE_JSON_REQUEST_STRING, testValue)) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();