Search in sources :

Example 1 with Configuration

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));
    }
}
Also used : java.util(java.util) PaymentProxy(alfio.model.transaction.PaymentProxy) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Pair(org.apache.commons.lang3.tuple.Pair) Collector(java.util.stream.Collector) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Predicate(java.util.function.Predicate) User(alfio.model.user.User) EventRepository(alfio.repository.EventRepository) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ConfigurationModification(alfio.model.modification.ConfigurationModification) UserManager(alfio.manager.user.UserManager) Configuration(alfio.model.system.Configuration) Log4j2(lombok.extern.log4j.Log4j2) ConfigurationPathLevel(alfio.model.system.ConfigurationPathLevel) Event(alfio.model.Event) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) Transactional(org.springframework.transaction.annotation.Transactional) User(alfio.model.user.User)

Example 2 with Configuration

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());
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) LocalTime(java.time.LocalTime) Before(org.junit.Before) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Organization(alfio.model.user.Organization) User(alfio.model.user.User) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) OptionalWrapper(alfio.util.OptionalWrapper) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) TicketCategory(alfio.model.TicketCategory) Role(alfio.model.user.Role) Initializer(alfio.config.Initializer) ConfigurationModification(alfio.model.modification.ConfigurationModification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Configuration(alfio.model.system.Configuration) ConfigurationPathLevel(alfio.model.system.ConfigurationPathLevel) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) ConfigurationModification(alfio.model.modification.ConfigurationModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(alfio.model.system.Configuration) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) Test(org.junit.Test)

Example 3 with Configuration

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());
        }
    });
}
Also used : User(alfio.model.user.User) Configuration(alfio.model.system.Configuration) Event(alfio.model.Event)

Example 4 with Configuration

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());
}
Also used : ConfigurationModification(alfio.model.modification.ConfigurationModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(alfio.model.system.Configuration) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) Test(org.junit.Test)

Example 5 with Configuration

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());
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) LocalTime(java.time.LocalTime) Before(org.junit.Before) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Organization(alfio.model.user.Organization) User(alfio.model.user.User) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) OptionalWrapper(alfio.util.OptionalWrapper) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) TicketCategory(alfio.model.TicketCategory) Role(alfio.model.user.Role) Initializer(alfio.config.Initializer) ConfigurationModification(alfio.model.modification.ConfigurationModification) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) Configuration(alfio.model.system.Configuration) ConfigurationPathLevel(alfio.model.system.ConfigurationPathLevel) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) ConfigurationModification(alfio.model.modification.ConfigurationModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(alfio.model.system.Configuration) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) Test(org.junit.Test)

Aggregations

Configuration (alfio.model.system.Configuration)5 Event (alfio.model.Event)4 ConfigurationModification (alfio.model.modification.ConfigurationModification)4 User (alfio.model.user.User)4 TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 UserManager (alfio.manager.user.UserManager)3 ConfigurationKeys (alfio.model.system.ConfigurationKeys)3 ConfigurationPathLevel (alfio.model.system.ConfigurationPathLevel)3 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Initializer (alfio.config.Initializer)2 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 TicketCategory (alfio.model.TicketCategory)2 DateTimeModification (alfio.model.modification.DateTimeModification)2 EventModification (alfio.model.modification.EventModification)2 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)2