@Override public EndpointUserConfigurationDto findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( String userId, String appToken, Integer schemaVersion) { return getDto(endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion( userId, appToken, schemaVersion)); }
@Override public EndpointUserConfigurationDto findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( String externalUid, String appToken, Integer schemaVersion, String tenantId) { if (isNotBlank(externalUid)) { EndpointUser endpointUser = endpointUserDao.findByExternalIdAndTenantId( externalUid, tenantId); if (endpointUser != null) { return getDto(endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion( endpointUser.getId(), appToken, schemaVersion)); } else { LOG.warn("Could not find endpoint user by externalUid:", externalUid); throw new IncorrectParameterException("Could not find endpoint user by externalUid"); } } else { LOG.warn("external user id could not be null!"); throw new IncorrectParameterException("externalUid could not be null!"); } }
@Test public void findByUserIdAndAppTokenAndSchemaVersionTest() 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)); MongoEndpointUserConfiguration found = endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertEquals(firstUserConfigurationDto, found.toDto()); }
@Test public void removeByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto configurationSchemaDto = generateConfSchemaDto(null, appDto.getId(), 1).get(0); generateEndpointUserConfigurationDto(userDto, appDto, configurationSchemaDto, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); endpointUserConfigurationDao.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), configurationSchemaDto.getVersion()); MongoEndpointUserConfiguration removed = endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), configurationSchemaDto.getVersion()); Assert.assertNull(removed); List<MongoEndpointUserConfiguration> foundList = endpointUserConfigurationDao.findByUserId(userDto.getId()); Assert.assertEquals(2, foundList.size()); }