Add name of @PathVariable

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-04-21 11:29:56 +02:00
parent 3fa9105428
commit bb0fb5da8d
6 changed files with 47 additions and 49 deletions

View File

@@ -117,12 +117,12 @@ public final class DataConversionHelper {
// have changed from 'soft' to 'forced' type and we need to // have changed from 'soft' to 'forced' type and we need to
// change the payload of the // change the payload of the
// response because of eTags. // 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(), .getControllerBasedeploymentAction(target.getControllerId(), action.getId(), actions.hashCode(),
null)).withRel(DdiRestConstants.DEPLOYMENT_BASE_ACTION)); null)).withRel(DdiRestConstants.DEPLOYMENT_BASE_ACTION));
addedUpdate = true; addedUpdate = true;
} else if (action.isCancelingOrCanceled() && !addedCancel) { } 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)) .getControllerCancelAction(target.getControllerId(), action.getId(), null))
.withRel(DdiRestConstants.CANCEL_ACTION)); .withRel(DdiRestConstants.CANCEL_ACTION));
addedCancel = true; addedCancel = true;
@@ -130,7 +130,7 @@ public final class DataConversionHelper {
} }
if (target.getTargetInfo().isRequestControllerAttributes()) { 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)); target.getControllerId(), null)).withRel(DdiRestConstants.CONFIG_DATA_ACTION));
} }
return result; return result;

View File

@@ -32,21 +32,20 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; 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; import org.springframework.web.bind.annotation.RestController;
/** /**
* The {@link ArtifactStoreController} of the HawkBit server controller API that * The {@link DdiArtifactStoreController} of the HawkBit server controller API
* is queried by the HawkBit target in order to download artifacts independent * that is queried by the HawkBit target in order to download artifacts
* of their own individual resource. This is offered in addition to the * independent of their own individual resource. This is offered in addition to
* {@link RootController#downloadArtifact(String, Long, Long, javax.servlet.http.HttpServletResponse)} * 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. * for legacy controllers that can not be fed with a download URI at runtime.
*/ */
@RestController @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 @Autowired
private ArtifactManagement artifactManagement; private ArtifactManagement artifactManagement;
@@ -61,9 +60,8 @@ public class ArtifactStoreController implements DdiArtifactStoreControllerRestAp
private HawkbitSecurityProperties securityProperties; private HawkbitSecurityProperties securityProperties;
@Override @Override
public ResponseEntity<Void> downloadArtifactByFilename(@PathVariable("fileName") final String fileName, public ResponseEntity<Void> downloadArtifactByFilename(final String fileName, final HttpServletResponse response,
final HttpServletResponse response, final HttpServletRequest request, final HttpServletRequest request, final String targetid) {
@AuthenticationPrincipal final String targetid) {
ResponseEntity<Void> result; ResponseEntity<Void> result;
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
@@ -100,7 +98,7 @@ public class ArtifactStoreController implements DdiArtifactStoreControllerRestAp
} }
@Override @Override
public ResponseEntity<Void> downloadArtifactMD5ByFilename(@PathVariable("fileName") final String fileName, public ResponseEntity<Void> downloadArtifactMD5ByFilename(final String fileName,
final HttpServletResponse response) { final HttpServletResponse response) {
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);

View File

@@ -52,20 +52,19 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; 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 * the hawkBit controller in order to pull {@link Action}s that have to be
* fulfilled and report status updates concerning the {@link Action} processing. * fulfilled and report status updates concerning the {@link Action} processing.
* *
* Transactional (read-write) as all queries at least update the last poll time. * Transactional (read-write) as all queries at least update the last poll time.
*/ */
@RestController @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 ({})."; private static final String GIVEN_ACTION_IS_NOT_ASSIGNED_TO_GIVEN_TARGET = "given action ({}) is not assigned to given target ({}).";
@Autowired @Autowired
@@ -91,7 +90,7 @@ public class RootController implements DdiRootControllerRestApi {
@Override @Override
public ResponseEntity<List<org.eclipse.hawkbit.ddi.json.model.DdiArtifact>> getSoftwareModulesArtifacts( public ResponseEntity<List<org.eclipse.hawkbit.ddi.json.model.DdiArtifact>> getSoftwareModulesArtifacts(
@PathVariable final String targetid, @PathVariable final Long softwareModuleId) { final String targetid, final Long softwareModuleId) {
LOG.debug("getSoftwareModulesArtifacts({})", targetid); LOG.debug("getSoftwareModulesArtifacts({})", targetid);
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId); final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId);
@@ -107,7 +106,7 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<DdiControllerBase> getControllerBase(@PathVariable final String targetid, public ResponseEntity<DdiControllerBase> getControllerBase(final String targetid,
final HttpServletRequest request) { final HttpServletRequest request) {
LOG.debug("getControllerBase({})", targetid); LOG.debug("getControllerBase({})", targetid);
@@ -128,9 +127,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<Void> downloadArtifact(@PathVariable final String targetid, public ResponseEntity<Void> downloadArtifact(final String targetid, final Long softwareModuleId,
@PathVariable final Long softwareModuleId, @PathVariable final String fileName, final String fileName, final HttpServletResponse response, final HttpServletRequest request) {
final HttpServletResponse response, final HttpServletRequest request) {
ResponseEntity<Void> result; ResponseEntity<Void> result;
final Target target = controllerManagement.updateLastTargetQuery(targetid, final Target target = controllerManagement.updateLastTargetQuery(targetid,
@@ -181,9 +179,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<Void> downloadArtifactMd5(@PathVariable final String targetid, public ResponseEntity<Void> downloadArtifactMd5(final String targetid, final Long softwareModuleId,
@PathVariable final Long softwareModuleId, @PathVariable final String fileName, final String fileName, final HttpServletResponse response, final HttpServletRequest request) {
final HttpServletResponse response, final HttpServletRequest request) {
controllerManagement.updateLastTargetQuery(targetid, controllerManagement.updateLastTargetQuery(targetid,
IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader())); IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader()));
@@ -206,10 +203,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<DdiDeploymentBase> getControllerBasedeploymentAction( public ResponseEntity<DdiDeploymentBase> getControllerBasedeploymentAction(final String targetid,
@PathVariable @NotEmpty final String targetid, @PathVariable @NotEmpty final Long actionId, final Long actionId, final int resource, final HttpServletRequest request) {
@RequestParam(value = "c", required = false, defaultValue = "-1") final int resource,
final HttpServletRequest request) {
LOG.debug("getControllerBasedeploymentAction({},{})", targetid, resource); LOG.debug("getControllerBasedeploymentAction({},{})", targetid, resource);
final Target target = controllerManagement.updateLastTargetQuery(targetid, final Target target = controllerManagement.updateLastTargetQuery(targetid,
@@ -242,9 +237,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<Void> postBasedeploymentActionFeedback(@Valid @RequestBody final DdiActionFeedback feedback, public ResponseEntity<Void> postBasedeploymentActionFeedback(final DdiActionFeedback feedback,
@PathVariable final String targetid, @PathVariable @NotEmpty final Long actionId, final String targetid, final Long actionId, final HttpServletRequest request) {
final HttpServletRequest request) {
LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", targetid, actionId, feedback); LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", targetid, actionId, feedback);
final Target target = controllerManagement.updateLastTargetQuery(targetid, 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, private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid,
final Action action) { final Long actionid, final Action action) {
final ActionStatus actionStatus = new ActionStatus(); final ActionStatus actionStatus = new ActionStatus();
actionStatus.setAction(action); actionStatus.setAction(action);
@@ -339,8 +333,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<Void> putConfigData(@Valid @RequestBody final DdiConfigData configData, public ResponseEntity<Void> putConfigData(final DdiConfigData configData, final String targetid,
@PathVariable final String targetid, final HttpServletRequest request) { final HttpServletRequest request) {
controllerManagement.updateLastTargetQuery(targetid, controllerManagement.updateLastTargetQuery(targetid,
IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader())); IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader()));
@@ -350,8 +344,8 @@ public class RootController implements DdiRootControllerRestApi {
} }
@Override @Override
public ResponseEntity<DdiCancel> getControllerCancelAction(@PathVariable @NotEmpty final String targetid, public ResponseEntity<DdiCancel> getControllerCancelAction(final String targetid, final Long actionId,
@PathVariable @NotEmpty final Long actionId, final HttpServletRequest request) { final HttpServletRequest request) {
LOG.debug("getControllerCancelAction({})", targetid); LOG.debug("getControllerCancelAction({})", targetid);
final Target target = controllerManagement.updateLastTargetQuery(targetid, final Target target = controllerManagement.updateLastTargetQuery(targetid,

View File

@@ -29,9 +29,14 @@
<artifactId>hawkbit-rest-core</artifactId> <artifactId>hawkbit-rest-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>org.eclipse.hawkbit</groupId> <groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest-core</artifactId> <artifactId>hawkbit-rest-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>

View File

@@ -50,7 +50,7 @@ public interface SystemRestApi {
*/ */
@RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json", @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> deleteConfigurationValue(@PathVariable final String keyName); ResponseEntity<Void> deleteConfigurationValue(@PathVariable("keyName") final String keyName);
/** /**
* Handles the GET request of deleting a tenant specific configuration value * 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", @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<SystemTenantConfigurationValue> getConfigurationValue(@PathVariable final String keyName); ResponseEntity<SystemTenantConfigurationValue> getConfigurationValue(@PathVariable("keyName") final String keyName);
/** /**
* Handles the GET request of deleting a tenant specific configuration value * 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", @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<SystemTenantConfigurationValue> updateConfigurationValue(@PathVariable final String keyName, ResponseEntity<SystemTenantConfigurationValue> updateConfigurationValue(
@PathVariable("keyName") final String keyName,
@RequestBody final SystemTenantConfigurationValueRequest configurationValueRest); @RequestBody final SystemTenantConfigurationValueRequest configurationValueRest);
} }

View File

@@ -65,7 +65,7 @@ public class SystemResourceTest extends AbstractIntegrationTest {
tenantConfigurationManagement.addOrUpdateConfiguration(key, notGlobalValue); 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()) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("value", equalTo(notGlobalValue))).andExpect(jsonPath("global", equalTo(false))) .andExpect(jsonPath("value", equalTo(notGlobalValue))).andExpect(jsonPath("global", equalTo(false)))
.andExpect(jsonPath("createdAt", notNullValue())).andExpect(jsonPath("createdBy", notNullValue())); .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 TenantConfigurationKey key = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME;
final String testValue = "12:12:12"; 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)) .content(String.format(BASE_JSON_REQUEST_STRING, testValue)).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
@@ -99,7 +99,7 @@ public class SystemResourceTest extends AbstractIntegrationTest {
assertThat(tenantConfigurationManagement.getConfigurationValue(key, String.class).getValue()) assertThat(tenantConfigurationManagement.getConfigurationValue(key, String.class).getValue())
.isEqualTo(notGlobalValue); .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()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isNoContent());
assertThat(tenantConfigurationManagement.getConfigurationValue(key, String.class).isGlobal()).isEqualTo(true); 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 String testValue = "12:12:12";
final MvcResult mvcResult = mvc 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)) .content(String.format(BASE_JSON_REQUEST_STRING, testValue))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
@@ -134,7 +134,7 @@ public class SystemResourceTest extends AbstractIntegrationTest {
final String testValue = "invalidFormattedDuration"; final String testValue = "invalidFormattedDuration";
final MvcResult mvcResult = mvc 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)) .content(String.format(BASE_JSON_REQUEST_STRING, testValue))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn(); .andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();