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
// 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;

View File

@@ -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<Void> downloadArtifactByFilename(@PathVariable("fileName") final String fileName,
final HttpServletResponse response, final HttpServletRequest request,
@AuthenticationPrincipal final String targetid) {
public ResponseEntity<Void> downloadArtifactByFilename(final String fileName, final HttpServletResponse response,
final HttpServletRequest request, final String targetid) {
ResponseEntity<Void> result;
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
@@ -100,7 +98,7 @@ public class ArtifactStoreController implements DdiArtifactStoreControllerRestAp
}
@Override
public ResponseEntity<Void> downloadArtifactMD5ByFilename(@PathVariable("fileName") final String fileName,
public ResponseEntity<Void> downloadArtifactMD5ByFilename(final String fileName,
final HttpServletResponse response) {
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.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<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);
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(softwareModuleId);
@@ -107,7 +106,7 @@ public class RootController implements DdiRootControllerRestApi {
}
@Override
public ResponseEntity<DdiControllerBase> getControllerBase(@PathVariable final String targetid,
public ResponseEntity<DdiControllerBase> getControllerBase(final String targetid,
final HttpServletRequest request) {
LOG.debug("getControllerBase({})", targetid);
@@ -128,9 +127,8 @@ public class RootController implements DdiRootControllerRestApi {
}
@Override
public ResponseEntity<Void> downloadArtifact(@PathVariable final String targetid,
@PathVariable final Long softwareModuleId, @PathVariable final String fileName,
final HttpServletResponse response, final HttpServletRequest request) {
public ResponseEntity<Void> downloadArtifact(final String targetid, final Long softwareModuleId,
final String fileName, final HttpServletResponse response, final HttpServletRequest request) {
ResponseEntity<Void> result;
final Target target = controllerManagement.updateLastTargetQuery(targetid,
@@ -181,9 +179,8 @@ public class RootController implements DdiRootControllerRestApi {
}
@Override
public ResponseEntity<Void> downloadArtifactMd5(@PathVariable final String targetid,
@PathVariable final Long softwareModuleId, @PathVariable final String fileName,
final HttpServletResponse response, final HttpServletRequest request) {
public ResponseEntity<Void> 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<DdiDeploymentBase> 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<DdiDeploymentBase> 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<Void> postBasedeploymentActionFeedback(@Valid @RequestBody final DdiActionFeedback feedback,
@PathVariable final String targetid, @PathVariable @NotEmpty final Long actionId,
final HttpServletRequest request) {
public ResponseEntity<Void> 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<Void> putConfigData(@Valid @RequestBody final DdiConfigData configData,
@PathVariable final String targetid, final HttpServletRequest request) {
public ResponseEntity<Void> 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<DdiCancel> getControllerCancelAction(@PathVariable @NotEmpty final String targetid,
@PathVariable @NotEmpty final Long actionId, final HttpServletRequest request) {
public ResponseEntity<DdiCancel> getControllerCancelAction(final String targetid, final Long actionId,
final HttpServletRequest request) {
LOG.debug("getControllerCancelAction({})", targetid);
final Target target = controllerManagement.updateLastTargetQuery(targetid,

View File

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

View File

@@ -50,7 +50,7 @@ public interface SystemRestApi {
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { "application/hal+json",
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
@@ -64,7 +64,7 @@ public interface SystemRestApi {
*/
@RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { "application/hal+json",
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
@@ -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<SystemTenantConfigurationValue> updateConfigurationValue(@PathVariable final String keyName,
ResponseEntity<SystemTenantConfigurationValue> updateConfigurationValue(
@PathVariable("keyName") final String keyName,
@RequestBody final SystemTenantConfigurationValueRequest configurationValueRest);
}

View File

@@ -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();