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