use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertAuditDeltas.
private Collection<MAuditDelta> insertAuditDeltas(JdbcSession jdbcSession, long recordId, Collection<ObjectDeltaOperation<?>> deltas) {
// we want to keep only unique deltas, checksum is also part of PK
Map<String, MAuditDelta> deltasByChecksum = new HashMap<>();
for (ObjectDeltaOperation<?> deltaOperation : deltas) {
if (deltaOperation == null) {
continue;
}
MAuditDelta mAuditDelta = convertDelta(deltaOperation, recordId);
deltasByChecksum.put(mAuditDelta.checksum, mAuditDelta);
}
if (!deltasByChecksum.isEmpty()) {
SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
for (MAuditDelta value : deltasByChecksum.values()) {
// NULLs are important to keep the value count consistent during the batch
insertBatch.populate(value, DefaultMapper.WITH_NULL_BINDINGS).addBatch();
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
return deltasByChecksum.values();
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta in project midpoint by Evolveum.
the class SqlAuditServiceImpl method convertDelta.
private MAuditDelta convertDelta(ObjectDeltaOperation<?> deltaOperation, long recordId) {
MAuditDelta mAuditDelta = new MAuditDelta();
mAuditDelta.recordId = recordId;
try {
ObjectDelta<? extends ObjectType> delta = deltaOperation.getObjectDelta();
if (delta != null) {
DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
options.setEscapeInvalidCharacters(isEscapingInvalidCharacters(auditConfiguration));
String serializedDelta = DeltaConvertor.serializeDelta(delta, options, PrismContext.LANG_XML);
// serializedDelta is transient, needed for changed items later
mAuditDelta.serializedDelta = serializedDelta;
mAuditDelta.delta = RUtil.getBytesFromSerializedForm(serializedDelta, sqlConfiguration().isUseZipAudit());
mAuditDelta.deltaOid = delta.getOid();
mAuditDelta.deltaType = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(delta.getChangeType(), RChangeType.class));
}
OperationResult executionResult = deltaOperation.getExecutionResult();
if (executionResult != null) {
OperationResultType jaxb = executionResult.createOperationResultType();
if (jaxb != null) {
mAuditDelta.status = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(jaxb.getStatus(), ROperationResultStatus.class));
// Note that escaping invalid characters and using toString for unsupported types is safe in the
// context of operation result serialization.
String full = schemaService.createStringSerializer(PrismContext.LANG_XML).options(SerializationOptions.createEscapeInvalidCharacters().serializeUnsupportedTypesAsString(true)).serializeRealValue(jaxb, SchemaConstantsGenerated.C_OPERATION_RESULT);
mAuditDelta.fullResult = RUtil.getBytesFromSerializedForm(full, sqlConfiguration().isUseZipAudit());
}
}
mAuditDelta.resourceOid = deltaOperation.getResourceOid();
if (deltaOperation.getObjectName() != null) {
mAuditDelta.objectNameOrig = deltaOperation.getObjectName().getOrig();
mAuditDelta.objectNameNorm = deltaOperation.getObjectName().getNorm();
}
if (deltaOperation.getResourceName() != null) {
mAuditDelta.resourceNameOrig = deltaOperation.getResourceName().getOrig();
mAuditDelta.resourceNameNorm = deltaOperation.getResourceName().getNorm();
}
mAuditDelta.checksum = RUtil.computeChecksum(mAuditDelta.delta, mAuditDelta.fullResult);
} catch (Exception ex) {
throw new SystemException("Problem during audit delta conversion", ex);
}
return mAuditDelta;
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta in project midpoint by Evolveum.
the class SqlAuditServiceImpl method convertDelta.
private MAuditDelta convertDelta(ObjectDeltaOperationType deltaOperation, MAuditEventRecord auditRow) {
MAuditDelta mAuditDelta = new MAuditDelta();
mAuditDelta.recordId = auditRow.id;
try {
ObjectDeltaType delta = deltaOperation.getObjectDelta();
if (delta != null) {
DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
options.setEscapeInvalidCharacters(isEscapingInvalidCharacters(auditConfiguration));
String serializedDelta = DeltaConvertor.serializeDelta(delta, options, PrismContext.LANG_XML);
// serializedDelta is transient, needed for changed items later
mAuditDelta.serializedDelta = serializedDelta;
mAuditDelta.delta = RUtil.getBytesFromSerializedForm(serializedDelta, sqlConfiguration().isUseZipAudit());
mAuditDelta.deltaOid = delta.getOid();
mAuditDelta.deltaType = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(ChangeType.toChangeType(delta.getChangeType()), RChangeType.class));
for (ItemDeltaType itemDelta : delta.getItemDelta()) {
ItemPath path = itemDelta.getPath().getItemPath();
CanonicalItemPath canonical = schemaService.createCanonicalItemPath(path, delta.getObjectType());
for (int i = 0; i < canonical.size(); i++) {
auditRow.addChangedItem(canonical.allUpToIncluding(i).asString());
}
}
}
OperationResultType executionResult = deltaOperation.getExecutionResult();
if (executionResult != null) {
mAuditDelta.status = MiscUtil.enumOrdinal(RUtil.getRepoEnumValue(executionResult.getStatus(), ROperationResultStatus.class));
// Note that escaping invalid characters and using toString for unsupported types is safe in the
// context of operation result serialization.
String full = schemaService.createStringSerializer(PrismContext.LANG_XML).options(SerializationOptions.createEscapeInvalidCharacters().serializeUnsupportedTypesAsString(true)).serializeRealValue(executionResult, SchemaConstantsGenerated.C_OPERATION_RESULT);
mAuditDelta.fullResult = RUtil.getBytesFromSerializedForm(full, sqlConfiguration().isUseZipAudit());
}
mAuditDelta.resourceOid = deltaOperation.getResourceOid();
if (deltaOperation.getObjectName() != null) {
mAuditDelta.objectNameOrig = deltaOperation.getObjectName().getOrig();
mAuditDelta.objectNameNorm = deltaOperation.getObjectName().getNorm();
}
if (deltaOperation.getResourceName() != null) {
mAuditDelta.resourceNameOrig = deltaOperation.getResourceName().getOrig();
mAuditDelta.resourceNameNorm = deltaOperation.getResourceName().getNorm();
}
mAuditDelta.checksum = RUtil.computeChecksum(mAuditDelta.delta, mAuditDelta.fullResult);
} catch (Exception ex) {
throw new SystemException("Problem during audit delta conversion", ex);
}
return mAuditDelta;
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertChangedItemPaths.
private void insertChangedItemPaths(JdbcSession jdbcSession, long recordId, Collection<MAuditDelta> deltas) {
Set<String> changedItemPaths = new HashSet<>();
for (MAuditDelta delta : deltas) {
try {
ObjectDeltaType deltaBean = schemaService.parserFor(delta.serializedDelta).parseRealValue(ObjectDeltaType.class);
for (ItemDeltaType itemDelta : deltaBean.getItemDelta()) {
ItemPath path = itemDelta.getPath().getItemPath();
CanonicalItemPath canonical = schemaService.createCanonicalItemPath(path, deltaBean.getObjectType());
for (int i = 0; i < canonical.size(); i++) {
changedItemPaths.add(canonical.allUpToIncluding(i).asString());
}
}
} catch (SchemaException | SystemException e) {
// See MID-6446 - we want to throw in tests, old ones should be fixed by now
if (InternalsConfig.isConsistencyChecks()) {
throw new SystemException("Problem during audit delta parse", e);
}
LOGGER.warn("Serialized audit delta for recordId={} cannot be parsed." + " No changed items were created. This may cause problem later, but is not" + " critical for storing the audit record.", recordId, e);
}
}
if (!changedItemPaths.isEmpty()) {
QAuditItem qAuditItem = QAuditItemMapping.get().defaultAlias();
SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditItem);
for (String changedItemPath : changedItemPaths) {
insertBatch.set(qAuditItem.recordId, recordId).set(qAuditItem.changedItemPath, changedItemPath).addBatch();
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
}
use of com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertAuditDeltas.
private void insertAuditDeltas(JdbcSession jdbcSession, MAuditEventRecord auditRow, List<ObjectDeltaOperationType> deltas) {
// we want to keep only unique deltas, checksum is also part of PK
Map<String, MAuditDelta> deltasByChecksum = new HashMap<>();
for (ObjectDeltaOperationType delta : deltas) {
if (delta == null) {
continue;
}
MAuditDelta mAuditDelta = convertDelta(delta, auditRow);
deltasByChecksum.put(mAuditDelta.checksum, mAuditDelta);
}
if (!deltasByChecksum.isEmpty()) {
SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
for (MAuditDelta value : deltasByChecksum.values()) {
// NULLs are important to keep the value count consistent during the batch
insertBatch.populate(value, DefaultMapper.WITH_NULL_BINDINGS).addBatch();
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
}
Aggregations