use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class AuditTest method test110AuditSecond.
@Test
public void test110AuditSecond() throws QueryException {
OperationResult result = createOperationResult();
when();
AuditEventRecord record = new AuditEventRecord();
record.addPropertyValue("prop", "val");
logger.info("Adding audit record {}", record);
auditService.audit(record, new NullTaskImpl(), result);
then();
System.out.println("Record written:\n" + record.debugDump());
System.out.println("Repo ID: " + record.getRepoId());
MAuditEventRecord loaded = getAuditEventRecord(2, 1);
System.out.println("Record loaded:\n" + loaded);
assertThat(loaded.properties).describedAs("# of properties").hasSize(1);
assertThat(loaded.properties.get("prop")).withFailMessage("Wrong prop values").containsExactlyInAnyOrder("val");
// not initialized if nothing is there, so it's null (meaning empty)
assertThat(loaded.refValues).describedAs("# of references").isNullOrEmpty();
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class AuditTest method getAuditEventRecord.
private MAuditEventRecord getAuditEventRecord(int expectedCount, int index) throws QueryException {
// "create" does not actually create a new audit service, but returns the existing one
SqlRepoContext sqlRepoContext = auditServiceFactory.createAuditService().getSqlRepoContext();
SqlQueryContext<AuditEventRecordType, QAuditEventRecord, MAuditEventRecord> context = AuditSqlQueryContext.from(AuditEventRecordType.class, sqlRepoContext);
QAuditEventRecord aer = context.root();
context.sqlQuery().orderBy(aer.id.asc());
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startReadOnlyTransaction()) {
PageOf<MAuditEventRecord> result = context.executeQuery(jdbcSession).map(t -> t.get(aer));
assertThat(result).hasSize(expectedCount);
return result.get(index);
}
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class QAuditEventRecordMapping method toRowObject.
public MAuditEventRecord toRowObject(AuditEventRecordType record) {
MAuditEventRecord bean = new MAuditEventRecord();
// this better be null if we want to insert
bean.id = record.getRepoId();
bean.eventIdentifier = record.getEventIdentifier();
bean.timestamp = MiscUtil.asInstant(record.getTimestamp());
bean.channel = record.getChannel();
bean.eventStage = MiscUtil.enumOrdinal(RAuditEventStage.from(AuditEventStage.fromSchemaValue(record.getEventStage())));
bean.eventType = MiscUtil.enumOrdinal(RAuditEventType.from(AuditEventType.fromSchemaValue(record.getEventType())));
bean.hostIdentifier = record.getHostIdentifier();
ObjectReferenceType attorney = record.getAttorneyRef();
if (attorney != null) {
bean.attorneyName = attorney.getDescription();
bean.attorneyOid = attorney.getOid();
}
ObjectReferenceType initiator = record.getInitiatorRef();
if (initiator != null) {
bean.initiatorName = initiator.getDescription();
bean.initiatorOid = initiator.getOid();
bean.initiatorType = targetTypeToRepoOrdinal(initiator);
}
bean.message = trim(record.getMessage(), MESSAGE);
bean.nodeIdentifier = record.getNodeIdentifier();
bean.outcome = MiscUtil.enumOrdinal(ROperationResultStatus.from(OperationResultStatus.parseStatusType(record.getOutcome())));
bean.parameter = record.getParameter();
bean.remoteHostAddress = record.getRemoteHostAddress();
bean.requestIdentifier = record.getRequestIdentifier();
bean.result = record.getResult();
bean.sessionIdentifier = record.getSessionIdentifier();
ObjectReferenceType target = record.getTargetRef();
if (target != null) {
bean.targetName = target.getDescription();
bean.targetOid = target.getOid();
bean.targetType = targetTypeToRepoOrdinal(target);
}
ObjectReferenceType targetOwner = record.getTargetOwnerRef();
if (targetOwner != null) {
bean.targetOwnerName = targetOwner.getDescription();
bean.targetOwnerOid = targetOwner.getOid();
bean.targetOwnerType = targetTypeToRepoOrdinal(targetOwner);
}
bean.taskIdentifier = record.getTaskIdentifier();
bean.taskOid = record.getTaskOID();
return bean;
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class SqlAuditServiceImpl method auditAttempt.
private void auditAttempt(AuditEventRecordType record) {
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
try {
MAuditEventRecord auditRow = insertAuditEventRecord(jdbcSession, record);
insertAuditDeltas(jdbcSession, auditRow, record.getDelta());
insertChangedItemPaths(jdbcSession, auditRow);
insertProperties(jdbcSession, auditRow.id, record.getProperty());
insertReferences(jdbcSession, auditRow.id, record.getReference());
insertResourceOids(jdbcSession, auditRow.id, record.getResourceOid());
jdbcSession.commit();
} catch (RuntimeException ex) {
baseHelper.handleGeneralRuntimeException(ex, jdbcSession, null);
}
}
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertAuditEventRecord.
/**
* Inserts audit event record aggregate root without any subentities.
*
* @return ID of created audit event record
*/
private MAuditEventRecord insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecordType record) {
QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
QAuditEventRecord aer = aerMapping.defaultAlias();
MAuditEventRecord row = aerMapping.toRowObject(record);
SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
for (AuditEventRecordCustomColumnPropertyType property : record.getCustomColumnProperty()) {
String propertyName = property.getName();
if (!customColumns.containsKey(propertyName)) {
throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + propertyName);
}
// Like insert.set, but that one is too parameter-type-safe for our generic usage here.
insert.columns(aer.getPath(propertyName)).values(property.getValue());
}
Long returnedId = insert.executeWithKey(aer.id);
// If returned ID is null, it was provided. If not, it fails, something went bad.
row.id = returnedId != null ? returnedId : record.getRepoId();
return row;
}
Aggregations