From 1f1511dd54306bb02279ba0c789137924a18dff5 Mon Sep 17 00:00:00 2001 From: pyshankov Date: Wed, 17 Aug 2016 17:35:35 +0300 Subject: [PATCH] KAA-1337: Add REST API to retrieve a configuration of a specific user by its external id. --- .../service/UserConfigurationServiceImpl.java | 15 ++++++------- .../UserConfigurationServiceImplTest.java | 21 +++++++++++++++---- .../admin/controller/UserController.java | 13 ++++-------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java index 51078f45fc..1074a777a1 100644 --- a/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java +++ b/server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImpl.java @@ -127,13 +127,14 @@ public void removeByUserIdAndAppTokenAndSchemaVersion(String userId, String appT @Override public EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( String externalUid, - String appToken, - Integer schemaVersion, - String tenantId) { - EndpointUser endpointUser = endpointUserDao.findByExternalIdAndTenantId(externalUid,tenantId); - EndpointUserConfiguration endpointUserConfiguration = - endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion(endpointUser.getId(),appToken,schemaVersion); - return getDto(endpointUserConfiguration); + String appToken, + Integer schemaVersion, + String tenantId) { + return getDto( + endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion( + endpointUserDao.findByExternalIdAndTenantId(externalUid, tenantId).getId(), + appToken, + schemaVersion)); } diff --git a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImplTest.java b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImplTest.java index 931f783d1d..a4063ebcb5 100644 --- a/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImplTest.java +++ b/server/common/dao/src/test/java/org/kaaproject/kaa/server/common/dao/service/UserConfigurationServiceImplTest.java @@ -83,22 +83,35 @@ public void removeByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { } @Test - public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionTest() throws IOException{ + public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionTest() throws IOException{ ApplicationDto appDto = generateApplicationDto(); EndpointUserDto userDto = generateEndpointUserDto(appDto.getTenantId()); EndpointUserConfigurationDto userConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); - EndpointUserConfigurationDto endpointUserConfigurationDto = userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( userDto.getExternalId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion(), - appDto.getTenantId() - ); + appDto.getTenantId()); Assert.assertNotNull(endpointUserConfigurationDto); } + @Test + public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionNullTest() throws IOException{ + ApplicationDto appDto = generateApplicationDto(); + EndpointUserDto userDto = generateEndpointUserDto(appDto.getTenantId()); + EndpointUserConfigurationDto userConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); + userConfigurationService.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion()); + EndpointUserConfigurationDto endpointUserConfigurationDto = + userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( + userDto.getExternalId(), + appDto.getApplicationToken(), + userConfigurationDto.getSchemaVersion(), + appDto.getTenantId()); + Assert.assertNull(endpointUserConfigurationDto); + } + @Test public void saveUserConfigurationTest() throws IOException { EndpointUserConfigurationDto configurationDto = generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/UserController.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/UserController.java index 9119e88540..8ad7993dca 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/UserController.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/UserController.java @@ -291,13 +291,14 @@ public List findAllTenantAdminsByTenantId( } @ApiOperation(value = "Get endpoint user configuration by external user id", - notes="Get endpoint user configuration by external user id. Only user with TENANT_DEVELOPER and TENANT_USER roles is allowed to perform this operation.") + notes="Get endpoint user configuration by external user id." + + " Only user with TENANT_DEVELOPER and TENANT_USER roles is allowed to perform this operation.") @ApiResponses(value = { - @ApiResponse(code = 400, message = "The specified url is not valid"), + @ApiResponse(code = 400, message = "The specified url is not valid"), @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), @ApiResponse(code = 403, message = "The authenticated user does not have neither TENANT_DEVELOPER nor TENANT_USER role"), @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) - @RequestMapping(value = "configuration/{appToken}/{userId}/{schemaVersion}", method = RequestMethod.GET) + @RequestMapping(value = "configuration/{userId}/{appToken}/{schemaVersion}", method = RequestMethod.GET) @ResponseBody public EndpointUserConfigurationDto findUserConfigurationByUserId( @PathVariable String userId, @@ -306,10 +307,4 @@ public EndpointUserConfigurationDto findUserConfigurationByUserId( return configurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(userId,appToken,schemaVersion); } - - - - - - }