Search in sources :

Example 1 with ExternalConfiguration

use of alfio.manager.system.ExternalConfiguration in project alf.io by alfio-event.

the class V22_1_14_8__MigrateMailchimp method migrate.

@Override
public void migrate(Context context) throws Exception {
    var jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
    Integer enabledCount = jdbcTemplate.queryForObject("select count(*) from plugin_configuration where plugin_id = 'alfio.mailchimp' and conf_name = 'enabled' and conf_value = 'true'", Integer.class);
    if (enabledCount == null || enabledCount == 0) {
        return;
    }
    DataSource dataSource = Objects.requireNonNull(jdbcTemplate.getDataSource());
    ExtensionRepository extensionRepository = QueryFactory.from(ExtensionRepository.class, "PGSQL", dataSource);
    ExtensionLogRepository extensionLogRepository = QueryFactory.from(ExtensionLogRepository.class, "PGSQL", dataSource);
    PluginRepository pluginRepository = QueryFactory.from(PluginRepository.class, "PGSQL", dataSource);
    ExtensionService extensionService = new ExtensionService(new ScriptingExecutionService(HttpClient.newHttpClient(), null, Executors::newSingleThreadExecutor), extensionRepository, extensionLogRepository, new DataSourceTransactionManager(dataSource), new ExternalConfiguration(), new NamedParameterJdbcTemplate(jdbcTemplate));
    extensionService.createOrUpdate(null, null, new Extension("-", "mailchimp", getMailChimpScript(), true));
    int extensionId = extensionRepository.getExtensionIdFor("-", "mailchimp");
    int apiKeyId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "apiKey", "EVENT");
    int listIdId = pluginRepository.getConfigurationMetadataIdFor(extensionId, "listId", "EVENT");
    List<ConfValue> confValues = pluginRepository.findAllMailChimpConfigurationValues();
    for (ConfValue cv : confValues) {
        if (cv.value != null) {
            optionally(() -> jdbcTemplate.queryForObject("select org_id from event where id = " + cv.eventId, Integer.class)).ifPresent(orgId -> extensionRepository.insertSettingValue("apiKey".equals(cv.name) ? apiKeyId : listIdId, "-" + orgId + "-" + cv.eventId, cv.value));
        }
    }
}
Also used : ExtensionService(alfio.extension.ExtensionService) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource) Extension(alfio.extension.Extension) ExtensionRepository(alfio.repository.ExtensionRepository) ExtensionLogRepository(alfio.repository.ExtensionLogRepository) ExternalConfiguration(alfio.manager.system.ExternalConfiguration) ScriptingExecutionService(alfio.extension.ScriptingExecutionService) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Example 2 with ExternalConfiguration

use of alfio.manager.system.ExternalConfiguration in project alf.io by alfio-event.

the class BaseTestConfiguration method externalConfiguration.

@Bean
@Profile(Initializer.PROFILE_INTEGRATION_TEST)
public ExternalConfiguration externalConfiguration() {
    ExternalConfiguration externalConfiguration = new ExternalConfiguration();
    externalConfiguration.setSettings(Map.of(ConfigurationKeys.BASE_URL.name(), "http://localhost:8080"));
    return externalConfiguration;
}
Also used : ExternalConfiguration(alfio.manager.system.ExternalConfiguration) Profile(org.springframework.context.annotation.Profile) Bean(org.springframework.context.annotation.Bean)

Aggregations

ExternalConfiguration (alfio.manager.system.ExternalConfiguration)2 Extension (alfio.extension.Extension)1 ExtensionService (alfio.extension.ExtensionService)1 ScriptingExecutionService (alfio.extension.ScriptingExecutionService)1 ExtensionLogRepository (alfio.repository.ExtensionLogRepository)1 ExtensionRepository (alfio.repository.ExtensionRepository)1 DataSource (javax.sql.DataSource)1 Bean (org.springframework.context.annotation.Bean)1 Profile (org.springframework.context.annotation.Profile)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)1