@Override public EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( String externalUId, String appToken, Integer schemaVersion, String tenantId) { return userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( externalUId, appToken, schemaVersion, tenantId); }
private EndpointUserConfigurationDto findLatestUserConfiguration(final String userId, DeltaCacheKey deltaKey) { EndpointUserConfigurationDto userConfiguration = null; if (userId != null) { userConfiguration = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( userId, deltaKey.getAppConfigVersionKey().getApplicationToken(), deltaKey.getAppConfigVersionKey().getVersion()); if (userConfiguration != null) { LOG.debug("[{}] User specific configuration found", userId); } else { LOG.debug("[{}] No user configuration found ", userId); } } return userConfiguration; }
@Test public void removeByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto schema = generateConfSchemaDto(null, appDto.getId(), 1).get(0); generateEndpointUserConfigurationDto(userDto, appDto, schema, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); userConfigurationService.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); EndpointUserConfigurationDto removed = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertNull(removed); List<EndpointUserConfigurationDto> foundList = userConfigurationService.findUserConfigurationByUserId(userDto.getId()); Assert.assertEquals(2, foundList.size()); }
@Test public void userConfigNullTest() { EndpointUserConfigurationDto dto = null; EndpointUserConfigurationDto result = userConfigurationService.saveUserConfiguration(dto); Assert.assertNull(result); }
@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 findUserConfigurationByUserIdTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); EndpointUserConfigurationDto firstUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto secondUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); List<EndpointUserConfigurationDto> expectedList = new ArrayList<>(); expectedList.add(firstUserConfigurationDto); expectedList.add(secondUserConfigurationDto); generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); List<EndpointUserConfigurationDto> foundList = userConfigurationService.findUserConfigurationByUserId(userDto.getId()); Assert.assertEquals(expectedList.size(), foundList.size()); }
@Test(expected = IncorrectParameterException.class) public void saveUserConfigBlankTest() { EndpointUserConfigurationDto configurationDto = generateEndpointUserConfigurationDto(null, null, null, ""); userConfigurationService.saveUserConfiguration(configurationDto); }
@Test(expected = IncorrectParameterException.class) public void appDtoNullTest() throws IOException { EndpointUserConfigurationDto configurationDto = generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON), true); EndpointUserConfigurationDto result = userConfigurationService.saveUserConfiguration(configurationDto); Assert.assertEquals(configurationDto, result); } }
@Override public byte[] fetchUcfHash(String appToken, EndpointProfileDto profile) { if (profile.getEndpointUserId() == null || profile.getEndpointUserId().isEmpty()) { return null; } EndpointUserConfigurationDto ucfDto = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( profile.getEndpointUserId(), appToken, profile.getConfigurationVersion()); if (ucfDto != null) { return EndpointObjectHash.fromString(ucfDto.getBody()).getData(); } return null; }
@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 userConfigNotNullTest() throws IOException { EndpointUserConfigurationDto configurationDto = generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto result = userConfigurationService.saveUserConfiguration(configurationDto); Assert.assertEquals(configurationDto, result); }
@Test public void findUserConfigurationByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto schema = generateConfSchemaDto(null, appDto.getId(), 1).get(0); EndpointUserConfigurationDto firstUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, schema, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto found = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertEquals(firstUserConfigurationDto, found); }
protected EndpointUserConfigurationDto generateEndpointUserConfigurationDto(EndpointUserDto endpointUser, ApplicationDto applicationDto, ConfigurationSchemaDto configurationSchema, String body, boolean isNullAppDto) { EndpointUserConfigurationDto configurationDto = new EndpointUserConfigurationDto(); configurationDto.setBody(body); if (endpointUser == null) { endpointUser = generateEndpointUserDto(null); } if (!isNullAppDto) { if (applicationDto == null) { applicationDto = generateApplicationDto(); } configurationDto.setAppToken(applicationDto.getApplicationToken()); } else { return userConfigurationService.saveUserConfiguration(configurationDto); } configurationDto.setUserId(endpointUser.getId()); if (configurationSchema == null) { configurationSchema = generateConfSchemaDto(null, applicationDto.getId(), 1).get(0); } configurationDto.setSchemaVersion(configurationSchema.getVersion()); return userConfigurationService.saveUserConfiguration(configurationDto); }
@Override public void editUserConfiguration(EndpointUserConfigurationDto configuration) throws ControlServiceException { ApplicationDto appDto = applicationService.findAppByApplicationToken( configuration.getAppToken()); EndpointUserDto userDto = endpointService.findEndpointUserByExternalIdAndTenantId( configuration.getUserId(), appDto.getTenantId()); if (userDto == null) { throw new NotFoundException("Specified user not found!"); } configuration.setUserId(userDto.getId()); configuration = userConfigurationService.saveUserConfiguration(configuration); EndpointObjectHash hash = EndpointObjectHash.fromString(configuration.getBody()); checkNeighbors(); OperationsNodeInfo server = resolve(configuration.getUserId()); if (server != null) { UserConfigurationUpdate msg = new UserConfigurationUpdate(appDto.getTenantId(), configuration.getUserId(), configuration.getAppToken(), configuration.getSchemaVersion(), hash.getDataBuf()); if (LOG.isTraceEnabled()) { LOG.trace("Sending message {} to [{}]", msg, Neighbors.getServerId( server.getConnectionInfo())); } neighbors.sendMessage(server.getConnectionInfo(), OperationsServiceMsg.fromUpdate(msg)); } else { LOG.warn("Can't find server for user [{}]", configuration.getUserId()); } }