Search in sources :

Example 1 with BaseHierarchicalConfiguration

use of org.apache.commons.configuration2.BaseHierarchicalConfiguration in project midpoint by Evolveum.

the class AuditFactory method init.

@PostConstruct
public void init() {
    Configuration config = midpointConfiguration.getConfiguration(MidpointConfiguration.AUDIT_CONFIGURATION);
    List<HierarchicalConfiguration<ImmutableNode>> auditServices = ((BaseHierarchicalConfiguration) config).configurationsAt(CONF_AUDIT_SERVICE);
    for (Configuration serviceConfig : auditServices) {
        String factoryClass = getFactoryClassName(serviceConfig);
        try {
            // noinspection unchecked
            Class<AuditServiceFactory> clazz = (Class<AuditServiceFactory>) Class.forName(factoryClass);
            AuditServiceFactory factory = getFactory(clazz);
            factory.init(serviceConfig);
            serviceFactories.add(factory);
        } catch (Exception ex) {
            LoggingUtils.logException(LOGGER, "AuditServiceFactory implementation class {} failed to initialize.", ex, factoryClass);
            throw new SystemException("AuditServiceFactory implementation class " + factoryClass + " failed to initialize: " + ex.getMessage(), ex);
        }
    }
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SystemException(com.evolveum.midpoint.util.exception.SystemException) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) AuditServiceFactory(com.evolveum.midpoint.audit.api.AuditServiceFactory) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SystemException(com.evolveum.midpoint.util.exception.SystemException) PostConstruct(javax.annotation.PostConstruct)

Example 2 with BaseHierarchicalConfiguration

use of org.apache.commons.configuration2.BaseHierarchicalConfiguration in project midpoint by Evolveum.

the class SqaleAuditServiceFactory method initCustomColumns.

private void initCustomColumns(@NotNull Configuration configuration, SqaleRepoContext sqlRepoContext) {
    List<HierarchicalConfiguration<ImmutableNode>> subConfigColumns = ((BaseHierarchicalConfiguration) configuration).configurationsAt(CONF_AUDIT_SERVICE_COLUMNS);
    // here we use config from context, it can be main repository configuration
    SqaleRepositoryConfiguration repoConfig = (SqaleRepositoryConfiguration) sqlRepoContext.getJdbcRepositoryConfiguration();
    boolean createMissing = repoConfig.isCreateMissingCustomColumns() || // but we'll consider the flag also on audit configuration, just in case
    configuration.getBoolean(PROPERTY_CREATE_MISSING_CUSTOM_COLUMNS, false);
    SqlTableMetadata tableMetadata = null;
    if (createMissing) {
        try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
            tableMetadata = SqlTableMetadata.create(jdbcSession.connection(), QAuditEventRecord.TABLE_NAME);
        }
    }
    for (Configuration subConfigColumn : subConfigColumns) {
        String columnName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_COLUMN_NAME);
        String propertyName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_EVENT_RECORD_PROPERTY_NAME);
        // No type definition for now, it's all String or String implicit conversion.
        ColumnMetadata columnMetadata = ColumnMetadata.named(columnName).ofType(Types.VARCHAR);
        QAuditEventRecordMapping.get().addExtensionColumn(propertyName, columnMetadata);
        if (tableMetadata != null && tableMetadata.get(columnName) == null) {
            try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
                jdbcSession.addColumn(QAuditEventRecord.TABLE_NAME, columnMetadata);
                jdbcSession.commit();
            }
        }
    }
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) ColumnMetadata(com.querydsl.sql.ColumnMetadata) SqaleRepositoryConfiguration(com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration) JdbcRepositoryConfiguration(com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SqaleRepositoryConfiguration(com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) SqlTableMetadata(com.evolveum.midpoint.repo.sqlbase.SqlTableMetadata)

Example 3 with BaseHierarchicalConfiguration

use of org.apache.commons.configuration2.BaseHierarchicalConfiguration in project midpoint by Evolveum.

the class SqlAuditServiceFactory method initCustomColumns.

private void initCustomColumns(@NotNull Configuration configuration, SqlRepoContext sqlRepoContext) {
    List<HierarchicalConfiguration<ImmutableNode>> subConfigColumns = ((BaseHierarchicalConfiguration) configuration).configurationsAt(CONF_AUDIT_SERVICE_COLUMNS);
    // here we use config from context, it can be main repository configuration
    SqlRepositoryConfiguration repoConfig = (SqlRepositoryConfiguration) sqlRepoContext.getJdbcRepositoryConfiguration();
    SqlTableMetadata tableMetadata = null;
    if (repoConfig.isCreateMissingCustomColumns()) {
        try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
            tableMetadata = SqlTableMetadata.create(jdbcSession.connection(), QAuditEventRecord.TABLE_NAME);
        }
    }
    for (Configuration subConfigColumn : subConfigColumns) {
        String columnName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_COLUMN_NAME);
        String propertyName = getStringFromConfig(subConfigColumn, CONF_AUDIT_SERVICE_EVENT_RECORD_PROPERTY_NAME);
        // No type definition for now, it's all String or String implicit conversion.
        ColumnMetadata columnMetadata = ColumnMetadata.named(columnName).ofType(Types.NVARCHAR).withSize(255);
        QAuditEventRecordMapping.get().addExtensionColumn(propertyName, columnMetadata);
        if (tableMetadata != null && tableMetadata.get(columnName) == null) {
            // Fails on SQL Server with snapshot transaction, so different isolation is used.
            try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction(Connection.TRANSACTION_READ_COMMITTED)) {
                jdbcSession.addColumn(QAuditEventRecord.TABLE_NAME, ColumnMetadata.named(columnName).ofType(Types.VARCHAR).withSize(255));
                jdbcSession.commit();
            }
        }
    }
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) BaseHierarchicalConfiguration(org.apache.commons.configuration2.BaseHierarchicalConfiguration)

Aggregations

BaseHierarchicalConfiguration (org.apache.commons.configuration2.BaseHierarchicalConfiguration)3 Configuration (org.apache.commons.configuration2.Configuration)3 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)3 ColumnMetadata (com.querydsl.sql.ColumnMetadata)2 AuditServiceFactory (com.evolveum.midpoint.audit.api.AuditServiceFactory)1 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)1 SqaleRepositoryConfiguration (com.evolveum.midpoint.repo.sqale.SqaleRepositoryConfiguration)1 JdbcRepositoryConfiguration (com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration)1 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)1 SqlTableMetadata (com.evolveum.midpoint.repo.sqlbase.SqlTableMetadata)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 PostConstruct (javax.annotation.PostConstruct)1