use of alfio.model.system.Configuration in project alf.io by alfio-event.
the class ConfigurationManager method loadOrganizationConfig.
public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadOrganizationConfig(int organizationId, String username) {
User user = userManager.findUserByUsername(username);
if (!userManager.isOwnerOfOrganization(user, organizationId)) {
return Collections.emptyMap();
}
boolean isAdmin = userManager.isAdmin(user);
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().filter(checkActualConfigurationLevel(isAdmin, ORGANIZATION)).sorted().collect(groupByCategory());
String paymentMethodsBlacklist = getStringConfigValue(Configuration.from(organizationId, ConfigurationKeys.PAYMENT_METHODS_BLACKLIST), "");
Map<SettingCategory, List<Configuration>> result = groupByCategory(isAdmin ? union(SYSTEM, ORGANIZATION) : ORGANIZATION_CONFIGURATION, existing);
List<SettingCategory> toBeRemoved = PaymentProxy.availableProxies().stream().filter(pp -> paymentMethodsBlacklist.contains(pp.getKey())).flatMap(pp -> pp.getSettingCategories().stream()).collect(Collectors.toList());
if (toBeRemoved.isEmpty()) {
return result;
} else {
return result.entrySet().stream().filter(entry -> !toBeRemoved.contains(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
use of alfio.model.system.Configuration 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.system.Configuration in project alf.io by alfio-event.
the class ConfigurationManager method saveCategoryConfiguration.
public void saveCategoryConfiguration(int categoryId, int eventId, List<ConfigurationModification> list, String username) {
User user = userManager.findUserByUsername(username);
Event event = eventRepository.findById(eventId);
Validate.notNull(event, "event does not exist");
Validate.isTrue(userManager.isOwnerOfOrganization(user, event.getOrganizationId()), "Cannot update settings, user is not owner of event");
list.stream().filter(TO_BE_SAVED).forEach(c -> {
Optional<Configuration> existing = configurationRepository.findByKeyAtCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey());
Optional<String> value = evaluateValue(c.getKey(), c.getValue());
if (!value.isPresent()) {
configurationRepository.deleteCategoryLevelByKey(c.getKey(), eventId, categoryId);
} else if (existing.isPresent()) {
configurationRepository.updateCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey(), value.get());
} else {
configurationRepository.insertTicketCategoryLevel(event.getOrganizationId(), eventId, categoryId, c.getKey(), value.get(), ConfigurationKeys.fromString(c.getKey()).getDescription());
}
});
}
use of alfio.model.system.Configuration 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.system.Configuration 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