Search in sources :

Example 1 with Extension

use of alfio.extension.Extension in project alf.io by alfio-event.

the class MailchimpMigration method migrate.

@Override
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    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 == 0) {
        return;
    }
    // extract sql dialect from the directory location: from "classpath:alfio/db/HSQLDB" to hsqldb
    String dialect = flywayConfiguration.getLocations()[0].split("\\/db\\/")[1].toLowerCase(Locale.ROOT);
    QueryFactory queryFactory = new QueryFactory(dialect, jdbcTemplate);
    EventRepository eventRepository = queryFactory.from(EventRepository.class);
    ExtensionRepository extensionRepository = queryFactory.from(ExtensionRepository.class);
    ExtensionLogRepository extensionLogRepository = queryFactory.from(ExtensionLogRepository.class);
    PluginRepository pluginRepository = queryFactory.from(PluginRepository.class);
    ExtensionService extensionService = new ExtensionService(new ScriptingExecutionService(), extensionRepository, extensionLogRepository, new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
    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) QueryFactory(ch.digitalfondue.npjt.QueryFactory) Extension(alfio.extension.Extension) ExtensionRepository(alfio.repository.ExtensionRepository) ExtensionLogRepository(alfio.repository.ExtensionLogRepository) EventRepository(alfio.repository.EventRepository) ScriptingExecutionService(alfio.extension.ScriptingExecutionService) DataSourceTransactionManager(org.springframework.jdbc.datasource.DataSourceTransactionManager)

Aggregations

Extension (alfio.extension.Extension)1 ExtensionService (alfio.extension.ExtensionService)1 ScriptingExecutionService (alfio.extension.ScriptingExecutionService)1 EventRepository (alfio.repository.EventRepository)1 ExtensionLogRepository (alfio.repository.ExtensionLogRepository)1 ExtensionRepository (alfio.repository.ExtensionRepository)1 QueryFactory (ch.digitalfondue.npjt.QueryFactory)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1