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