Search in sources :

Example 1 with ConfigurationModification

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());
}
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 2 with ConfigurationModification

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());
}
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 3 with ConfigurationModification

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());
}
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

TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 ConfigurationModification (alfio.model.modification.ConfigurationModification)3 Configuration (alfio.model.system.Configuration)3 Test (org.junit.Test)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 Initializer (alfio.config.Initializer)2 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 UserManager (alfio.manager.user.UserManager)2 Event (alfio.model.Event)2 TicketCategory (alfio.model.TicketCategory)2 DateTimeModification (alfio.model.modification.DateTimeModification)2 EventModification (alfio.model.modification.EventModification)2 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)2 LocationDescriptor (alfio.model.modification.support.LocationDescriptor)2 ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 ConfigurationPathLevel (alfio.model.system.ConfigurationPathLevel)2 Organization (alfio.model.user.Organization)2 Role (alfio.model.user.Role)2