Skip to content

Commit

Permalink
KAA-1337: Add REST API to retrieve a configuration of a specific user…
Browse files Browse the repository at this point in the history
… by its external id.
  • Loading branch information
Pyshankov committed Aug 17, 2016
1 parent b109d3d commit 661d583
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 15 deletions.
76 changes: 61 additions & 15 deletions doc/Programming-guide/Server-REST-APIs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,13 @@
"/api/admins/{tenantId}" : {
"post" : {
"tags" : [ "User" ],
"summary" : "Select tenant admins by tenant id",
"description" : "",
"summary" : "Get tenant admins based on tenant id",
"description" : "Gets the tenant admins by specified tenantId. Only user with KAA_ADMIN role is allowed to perform this operation.",
"operationId" : "findAllTenantAdminsByTenantId",
"parameters" : [ {
"name" : "",
"name" : "tenantId",
"in" : "path",
"description" : "A unique tenant identifier",
"required" : true,
"type" : "string"
} ],
Expand All @@ -668,7 +669,7 @@
"description" : "The user is not authenticated or invalid credentials were provided"
},
"403" : {
"description" : "The authenticated user does not have the required TENANT_ADMIN role or the Tenant ID of the editing user does not match the Tenant ID of the authenticated user"
"description" : "The authenticated user does not have the required KAA_ADMIN role"
},
"404" : {
"description" : "The user with the specified tenantId does not exist"
Expand Down Expand Up @@ -1099,7 +1100,7 @@
"description" : "The authenticated user does not have the required role (TENANT_DEVELOPER or TENANT_USER) or the Tenant ID of the application does not match the Tenant ID of the authenticated user"
},
"404" : {
"description" : "An endpoint group with the specified endpointGroupId does not exist or the endpoint group does not have the requested configuration record\n"
"description" : "An endpoint group with the specified endpointGroupId does not exist or the endpoint group does not have the requested configuration record"
},
"500" : {
"description" : "An unexpected error occurred on the server side"
Expand Down Expand Up @@ -3144,18 +3145,18 @@
"post" : {
"tags" : [ "Notifications" ],
"summary" : "Send notification",
"description" : "Sends a notification with the notification body from the specified file. Only users with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.",
"description" : "Sends a notification with the notification body from the specified file. Only users with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation. If you want to set notification time to leave, you must set expiredAt field in the parameter notification. If your notification schema contains one field \"message\" with Union type, notification body from the specified file looks like below: ```{ \"message\" : { \"string\" : \"Hello world!\" }}```. And for primitive string type of the field \"message\" notification body from the specified file looks like below: ```{ \"message\" : \"Hello world!\"}```",
"operationId" : "sendNotification",
"parameters" : [ {
"name" : "notification",
"in" : "formData",
"description" : "NotificationDto body. Mandatory fields: applicationId, schemaId, version, topicId, type",
"description" : "NotificationDto body. Mandatory fields: applicationId, schemaId, topicId, type",
"required" : true,
"type" : "ref"
}, {
"name" : "file",
"in" : "formData",
"description" : "Notification schema represented in json format",
"description" : "A file with notification body according to the specified notification schema represented in json format",
"required" : true,
"type" : "file"
} ],
Expand Down Expand Up @@ -3188,12 +3189,12 @@
"post" : {
"tags" : [ "Notifications" ],
"summary" : "Send unicast notification",
"description" : "Sends a unicast notification with the notification body from the specified file to the client identified by endpointKeyHash. Only users with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.",
"description" : "Sends a unicast notification with the notification body from the specified file to the client identified by endpointKeyHash. Only users with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation. If you want to set notification time to leave, you must set expiredAt field in the parameter notification. If your notification schema contains one field \"message\" with Union type, notification body from the specified file looks like below: ```{ \"message\" : { \"string\" : \"Hello world!\" }}```. And for primitive string type of the field \"message\" notification body from the specified file looks like below: ```{ \"message\" : \"Hello world!\"}```",
"operationId" : "sendUnicastNotification",
"parameters" : [ {
"name" : "notification",
"in" : "formData",
"description" : "NotificationDto body. Mandatory fields: applicationId, schemaId, version, topicId, type",
"description" : "NotificationDto body. Mandatory fields: applicationId, schemaId, topicId, type",
"required" : true,
"type" : "ref"
}, {
Expand All @@ -3205,7 +3206,7 @@
}, {
"name" : "file",
"in" : "formData",
"description" : "Notification schema represented in json format",
"description" : "A file with notification body according to the specified notification schema represented in json format",
"required" : true,
"type" : "file"
} ],
Expand Down Expand Up @@ -3680,6 +3681,37 @@
}
}
},
"/api/userConfiguration" : {
"post" : {
"tags" : [ "Configuration" ],
"summary" : "Create/Edit user configuration",
"description" : "Creates or updates a configuration for the specific user under the application. TIf a configuration with the specified user ID does not exist, then it will be created. If a configuration with the specified user ID exists, the configuration will be updated. Only users with the TENANT_DEVELOPER or TENANT_USER role are allowed to perform this operation.",
"operationId" : "editUserConfiguration",
"parameters" : [ {
"in" : "body",
"name" : "endpointUserConfiguration",
"description" : "EndpointUserConfigurationDto body. Mandatory fields: userId, appToken, schemaVersion, body",
"required" : true,
"schema" : {
"$ref" : "#/definitions/EndpointUserConfigurationDto"
}
} ],
"responses" : {
"401" : {
"description" : "The user is not authenticated or invalid credentials were provided"
},
"403" : {
"description" : "The authenticated user does not have the required role (TENANT_DEVELOPER or TENANT_USER) or the Tenant ID of the application does not match the Tenant ID of the authenticated user"
},
"404" : {
"description" : "A user with the specified userId or application with the specified appToken does not exists"
},
"500" : {
"description" : "An unexpected error occurred on the server side"
}
}
}
},
"/api/userNotificationSchemas/{applicationToken}" : {
"get" : {
"tags" : [ "Notifications" ],
Expand Down Expand Up @@ -4654,6 +4686,24 @@
}
}
},
"EndpointUserConfigurationDto" : {
"type" : "object",
"properties" : {
"userId" : {
"type" : "string"
},
"appToken" : {
"type" : "string"
},
"schemaVersion" : {
"type" : "integer",
"format" : "int32"
},
"body" : {
"type" : "string"
}
}
},
"EventClassFamilyDto" : {
"type" : "object",
"properties" : {
Expand Down Expand Up @@ -4854,10 +4904,6 @@
"secNum" : {
"type" : "integer",
"format" : "int32"
},
"version" : {
"type" : "integer",
"format" : "int64"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public interface UserConfigurationService {
* @param schemaVersion the schema version
*/
void removeByUserIdAndAppTokenAndSchemaVersion(String userId, String appToken, Integer schemaVersion);


EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(String externalUId, String appToken, Integer schemaVersion,String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.kaaproject.kaa.server.common.dao.UserConfigurationService;
import org.kaaproject.kaa.server.common.dao.exception.IncorrectParameterException;
import org.kaaproject.kaa.server.common.dao.impl.EndpointUserConfigurationDao;
import org.kaaproject.kaa.server.common.dao.impl.EndpointUserDao;
import org.kaaproject.kaa.server.common.dao.model.EndpointUser;
import org.kaaproject.kaa.server.common.dao.model.EndpointUserConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -58,6 +60,7 @@ public class UserConfigurationServiceImpl implements UserConfigurationService {

private EndpointUserConfigurationDao<EndpointUserConfiguration> endpointUserConfigurationDao;

private EndpointUserDao<EndpointUser> endpointUserDao;

@Override
public EndpointUserConfigurationDto saveUserConfiguration(EndpointUserConfigurationDto userConfig) {
Expand Down Expand Up @@ -121,8 +124,24 @@ public void removeByUserIdAndAppTokenAndSchemaVersion(String userId, String appT
endpointUserConfigurationDao.removeByUserIdAndAppTokenAndSchemaVersion(userId, appToken, schemaVersion);
}

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


public void setEndpointUserConfigurationDao(EndpointUserConfigurationDao<EndpointUserConfiguration> endpointUserConfigurationDao) {
this.endpointUserConfigurationDao = endpointUserConfigurationDao;
}

public void setEndpointUserDao(EndpointUserDao<EndpointUser> endpointUserDao) {
this.endpointUserDao = endpointUserDao;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

<bean id="userConfigurationService" class="org.kaaproject.kaa.server.common.dao.service.UserConfigurationServiceImpl">
<property name="endpointUserConfigurationDao" ref="endpointUserConfigurationDao"/>
<property name="endpointUserDao" ref="endpointUserDao"/>
</bean>

<bean id="serverProfileService" class="org.kaaproject.kaa.server.common.dao.service.ServerProfileServiceImpl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ public void removeByUserIdAndAppTokenAndSchemaVersionTest() throws IOException {
Assert.assertEquals(2, foundList.size());
}

@Test
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()
);
Assert.assertNotNull(endpointUserConfigurationDto);
}

@Test
public void saveUserConfigurationTest() throws IOException {
EndpointUserConfigurationDto configurationDto = generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

<bean id="userConfigurationService" class="org.kaaproject.kaa.server.common.dao.service.UserConfigurationServiceImpl">
<property name="endpointUserConfigurationDao" ref="endpointUserConfigurationDao"/>
<property name="endpointUserDao" ref="endpointUserDao"/>
</bean>

<bean id="serverProfileService" class="org.kaaproject.kaa.server.common.dao.service.ServerProfileServiceImpl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

<bean id="userConfigurationService" class="org.kaaproject.kaa.server.common.dao.service.UserConfigurationServiceImpl">
<property name="endpointUserConfigurationDao" ref="endpointUserConfigurationDao"/>
<property name="endpointUserDao" ref="endpointUserDao"/>
</bean>

<bean id="serverProfileService" class="org.kaaproject.kaa.server.common.dao.service.ServerProfileServiceImpl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.commons.lang3.StringUtils;
import org.kaaproject.kaa.common.dto.EndpointUserConfigurationDto;
import org.kaaproject.kaa.common.dto.KaaAuthorityDto;
import org.kaaproject.kaa.common.dto.admin.AuthResultDto;
import org.kaaproject.kaa.common.dto.admin.ResultCode;
Expand Down Expand Up @@ -289,6 +290,26 @@ public List<UserDto> findAllTenantAdminsByTenantId(
return userService.findAllTenantAdminsByTenantId(tenantId);
}

@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.")
@ApiResponses(value = {
@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)
@ResponseBody
public EndpointUserConfigurationDto findUserConfigurationByUserId(
@PathVariable String userId,
@PathVariable String appToken,
@PathVariable Integer schemaVersion) throws KaaAdminServiceException {
return configurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(userId,appToken,schemaVersion);
}







}
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ public ConfigurationSchemaViewDto createConfigurationSchemaFormCtlSchema(CtlSche
}
}

@Override
public EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(String externalUserId, String appToken, Integer schemaVersion) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
return controlService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(externalUserId,appToken,schemaVersion,getTenantId());
}

private void checkSchemaId(String schemaId) throws IllegalArgumentException {
if (isEmpty(schemaId)) {
throw new IllegalArgumentException("The schemaId parameter is empty.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ public interface ConfigurationService extends RemoteService {

ConfigurationSchemaViewDto createConfigurationSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException;

EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(String externalUId, String appToken, Integer schemaVersion) throws KaaAdminServiceException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -1718,4 +1718,8 @@ CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, int ve
* @throws ControlServiceException - if an exception occures.
*/
List<String> getCredentialsServiceNames() throws ControlServiceException;


EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(String userId, String appToken, Integer schemaVersion,String tenantId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.kaaproject.kaa.server.control.service;

import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.kaaproject.kaa.server.admin.services.util.Utils.getCurrentUser;
import static org.kaaproject.kaa.server.admin.shared.util.Utils.isEmpty;

import java.io.IOException;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.kaaproject.kaa.common.dto.logs.LogSchemaDto;
import org.kaaproject.kaa.common.dto.user.UserVerifierDto;
import org.kaaproject.kaa.common.hash.EndpointObjectHash;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.common.Base64Util;
import org.kaaproject.kaa.server.common.Version;
import org.kaaproject.kaa.server.common.core.algorithms.AvroUtils;
Expand Down Expand Up @@ -2297,4 +2299,13 @@ public void provisionRegistration(
public List<String> getCredentialsServiceNames() throws ControlServiceException {
return this.credentialsServiceRegistry.getCredentialsServiceNames();
}

@Override
public EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(
String externalUId,
String appToken,
Integer schemaVersion,
String tenantId) {
return userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion(externalUId,appToken,schemaVersion,tenantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@

<bean id="userConfigurationService" class="org.kaaproject.kaa.server.common.dao.service.UserConfigurationServiceImpl">
<property name="endpointUserConfigurationDao" ref="endpointUserConfigurationDao"/>
<property name="endpointUserDao" ref="endpointUserDao"/>
</bean>
</beans>

0 comments on commit 661d583

Please sign in to comment.