use of alfio.model.modification.ConfigurationModification in project alf.io by alfio-event.
the class ConfigurationManagerIntegrationTest method testSaveOnlyExistingConfiguration.
@Test
public void testSaveOnlyExistingConfiguration() {
configurationRepository.insertOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue(), "MY-ACCOUNT_NUMBER", "empty");
Configuration existing = configurationRepository.findByKeyAtOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue()).orElseThrow(IllegalStateException::new);
Map<ConfigurationKeys.SettingCategory, List<Configuration>> all = configurationManager.loadOrganizationConfig(event.getOrganizationId(), USERNAME);
List<Configuration> flatten = all.entrySet().stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList());
List<ConfigurationModification> modified = flatten.stream().filter(c -> !c.getKey().equals(ConfigurationKeys.BANK_ACCOUNT_NR.getValue())).map(ConfigurationModification::fromConfiguration).collect(Collectors.toList());
modified.add(new ConfigurationModification(existing.getId(), existing.getKey(), "NEW-NUMBER"));
configurationManager.saveAllOrganizationConfiguration(event.getOrganizationId(), modified, USERNAME);
List<Configuration> organizationConfiguration = configurationRepository.findOrganizationConfiguration(event.getOrganizationId());
assertEquals(1, organizationConfiguration.size());
Optional<Configuration> result = configurationRepository.findByKeyAtOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue());
assertTrue(result.isPresent());
Configuration configuration = result.get();
assertEquals(ConfigurationKeys.BANK_ACCOUNT_NR, configuration.getConfigurationKey());
assertEquals("NEW-NUMBER", configuration.getValue());
}
use of alfio.model.modification.ConfigurationModification in project alf.io by alfio-event.
the class ConfigurationManagerIntegrationTest method testSaveBooleanOptions.
@Test
public void testSaveBooleanOptions() {
String ftcKey = ALLOW_FREE_TICKETS_CANCELLATION.getValue();
configurationRepository.insert(ftcKey, "false", "this should be updated to true");
ConfigurationModification ftc = new ConfigurationModification(configurationRepository.findByKey(ftcKey).getId(), ftcKey, "true");
String prKey = ENABLE_PRE_REGISTRATION.getValue();
configurationRepository.insert(prKey, "true", "this should be updated to false");
ConfigurationModification pr = new ConfigurationModification(configurationRepository.findByKey(prKey).getId(), prKey, "false");
ConfigurationModification newTrue = new ConfigurationModification(-1, ENABLE_WAITING_QUEUE.getValue(), "true");
ConfigurationModification newFalse = new ConfigurationModification(-1, ENABLE_WAITING_QUEUE_NOTIFICATION.getValue(), "false");
ConfigurationModification newNull = new ConfigurationModification(-1, GOOGLE_ANALYTICS_ANONYMOUS_MODE.getValue(), null);
configurationManager.saveAllSystemConfiguration(Arrays.asList(ftc, pr, newTrue, newFalse, newNull));
Configuration cFtc = configurationRepository.findByKey(ftcKey);
assertNotNull(ftc);
assertEquals("true", cFtc.getValue());
Configuration cPr = configurationRepository.findByKey(prKey);
assertNotNull(cPr);
assertEquals("false", cPr.getValue());
Configuration nTrue = configurationRepository.findByKey(ENABLE_WAITING_QUEUE.getValue());
assertNotNull(nTrue);
assertEquals("true", nTrue.getValue());
Configuration nFalse = configurationRepository.findByKey(ENABLE_WAITING_QUEUE_NOTIFICATION.getValue());
assertNotNull(nFalse);
assertEquals("false", nFalse.getValue());
Optional<Configuration> opt = OptionalWrapper.optionally(() -> configurationRepository.findByKey(GOOGLE_ANALYTICS_ANONYMOUS_MODE.getValue()));
assertFalse(opt.isPresent());
}
use of alfio.model.modification.ConfigurationModification in project alf.io by alfio-event.
the class ConfigurationManagerIntegrationTest method testSaveOnlyValidConfiguration.
@Test
public void testSaveOnlyValidConfiguration() {
configurationRepository.insertOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue(), "MY-ACCOUNT_NUMBER", "empty");
Configuration existing = configurationRepository.findByKeyAtOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue()).orElseThrow(IllegalStateException::new);
Map<ConfigurationKeys.SettingCategory, List<Configuration>> all = configurationManager.loadOrganizationConfig(event.getOrganizationId(), USERNAME);
List<Configuration> flatten = all.entrySet().stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList());
List<ConfigurationModification> modified = flatten.stream().filter(c -> !c.getKey().equals(ConfigurationKeys.BANK_ACCOUNT_NR.getValue()) && !c.getKey().equals(ConfigurationKeys.PARTIAL_RESERVATION_ID_LENGTH.getValue())).map(ConfigurationModification::fromConfiguration).collect(Collectors.toList());
modified.add(new ConfigurationModification(existing.getId(), existing.getKey(), "NEW-NUMBER"));
modified.add(new ConfigurationModification(-1, ConfigurationKeys.PARTIAL_RESERVATION_ID_LENGTH.getValue(), "9"));
configurationManager.saveAllOrganizationConfiguration(event.getOrganizationId(), modified, USERNAME);
List<Configuration> organizationConfiguration = configurationRepository.findOrganizationConfiguration(event.getOrganizationId());
assertEquals(2, organizationConfiguration.size());
Optional<Configuration> result = configurationRepository.findByKeyAtOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue());
assertTrue(result.isPresent());
Configuration configuration = result.get();
assertEquals(ConfigurationKeys.BANK_ACCOUNT_NR, configuration.getConfigurationKey());
assertEquals("NEW-NUMBER", configuration.getValue());
result = configurationRepository.findByKeyAtOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.PARTIAL_RESERVATION_ID_LENGTH.getValue());
assertTrue(result.isPresent());
configuration = result.get();
assertEquals(ConfigurationKeys.PARTIAL_RESERVATION_ID_LENGTH, configuration.getConfigurationKey());
assertEquals("9", configuration.getValue());
}
Aggregations