@Override public List<EndpointUserConfigurationDto> findUserConfigurationByUserId(String userId) { return convertDtoList(endpointUserConfigurationDao.findByUserId(userId)); }
@Override public EndpointUserConfigurationDto findUserConfigurationByUserIdAndAppTokenAndSchemaVersion( String userId, String appToken, Integer schemaVersion) { return getDto(endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion( userId, appToken, schemaVersion)); }
@Override public void removeByUserIdAndAppTokenAndSchemaVersion(String userId, String appToken, Integer schemaVersion) { endpointUserConfigurationDao.removeByUserIdAndAppTokenAndSchemaVersion(userId, appToken, schemaVersion); }
@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()); }
@Override public EndpointUserConfigurationDto saveUserConfiguration(EndpointUserConfigurationDto userConfig) { EndpointUserConfigurationDto userConfigurationDto = null; if (userConfig != null) { String userConfigBody = userConfig.getBody(); if (isNotBlank(userConfigBody)) { String appToken = userConfig.getAppToken(); ApplicationDto applicationDto = applicationService.findAppByApplicationToken(appToken); if (applicationDto != null) { int schemaVersion = userConfig.getSchemaVersion(); userConfig.setBody(configurationService.normalizeAccordingToOverrideConfigurationSchema(applicationDto.getId(), schemaVersion, userConfigBody)); userConfigurationDto = getDto(endpointUserConfigurationDao.save(userConfig)); } else { LOG.warn("Can't find application with token {} for endpoint user configuration.", appToken); throw new IncorrectParameterException("Can't find application for specified token."); } } else { LOG.warn("Invalid endpoint user configuration. Configuration body is empty"); throw new IncorrectParameterException("Configuration body is empty."); } } return userConfigurationDto; }
@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 @Ignore("invalid") public void findByUserIdTest() 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<MongoEndpointUserConfiguration> expectedList = new ArrayList<>(); expectedList.add(new MongoEndpointUserConfiguration(firstUserConfigurationDto)); expectedList.add(new MongoEndpointUserConfiguration(secondUserConfigurationDto)); generateEndpointUserConfigurationDto(null, null, null); List<MongoEndpointUserConfiguration> foundList = endpointUserConfigurationDao.findByUserId(userDto.getId()); Assert.assertEquals(expectedList.size(), foundList.size()); Assert.assertEquals(expectedList, foundList); } }
@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()); }