use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.
the class RAuditEventRecord method toRepo.
public static RAuditEventRecord toRepo(AuditEventRecord record, PrismContext prismContext) throws DtoTranslationException {
Validate.notNull(record, "Audit event record must not be null.");
Validate.notNull(prismContext, "Prism context must not be null.");
RAuditEventRecord repo = new RAuditEventRecord();
if (record.getRepoId() != null) {
repo.setId(record.getRepoId());
}
repo.setChannel(record.getChannel());
if (record.getTimestamp() != null) {
repo.setTimestamp(new Timestamp(record.getTimestamp()));
}
repo.setEventStage(RAuditEventStage.toRepo(record.getEventStage()));
repo.setEventType(RAuditEventType.toRepo(record.getEventType()));
repo.setSessionIdentifier(record.getSessionIdentifier());
repo.setEventIdentifier(record.getEventIdentifier());
repo.setHostIdentifier(record.getHostIdentifier());
repo.setRemoteHostAddress(record.getRemoteHostAddress());
repo.setNodeIdentifier(record.getNodeIdentifier());
repo.setParameter(record.getParameter());
repo.setMessage(RUtil.trimString(record.getMessage(), AuditService.MAX_MESSAGE_SIZE));
if (record.getOutcome() != null) {
repo.setOutcome(RUtil.getRepoEnumValue(record.getOutcome().createStatusType(), ROperationResultStatus.class));
}
repo.setTaskIdentifier(record.getTaskIdentifier());
repo.setTaskOID(record.getTaskOID());
repo.setResult(record.getResult());
try {
if (record.getTarget() != null) {
PrismReferenceValue target = record.getTarget();
repo.setTargetName(getOrigName(target));
repo.setTargetOid(target.getOid());
repo.setTargetType(ClassMapper.getHQLTypeForQName(target.getTargetType()));
}
if (record.getTargetOwner() != null) {
PrismObject targetOwner = record.getTargetOwner();
repo.setTargetOwnerName(getOrigName(targetOwner));
repo.setTargetOwnerOid(targetOwner.getOid());
}
if (record.getInitiator() != null) {
PrismObject<UserType> initiator = record.getInitiator();
repo.setInitiatorName(getOrigName(initiator));
repo.setInitiatorOid(initiator.getOid());
}
for (ObjectDeltaOperation<?> delta : record.getDeltas()) {
if (delta == null) {
continue;
}
ObjectDelta<?> objectDelta = delta.getObjectDelta();
for (ItemDelta<?, ?> itemDelta : objectDelta.getModifications()) {
ItemPath path = itemDelta.getPath();
if (path != null) {
// TODO what if empty?
CanonicalItemPath canonical = CanonicalItemPath.create(path, objectDelta.getObjectTypeClass(), prismContext);
for (int i = 0; i < canonical.size(); i++) {
RAuditItem changedItem = RAuditItem.toRepo(repo, canonical.allUpToIncluding(i).asString());
repo.getChangedItems().add(changedItem);
}
}
}
RObjectDeltaOperation rDelta = RObjectDeltaOperation.toRepo(repo, delta, prismContext);
rDelta.setTransient(true);
rDelta.setRecord(repo);
repo.getDeltas().add(rDelta);
}
for (Map.Entry<String, Set<String>> propertyEntry : record.getProperties().entrySet()) {
for (String propertyValue : propertyEntry.getValue()) {
repo.getPropertyValues().add(RAuditPropertyValue.toRepo(repo, propertyEntry.getKey(), RUtil.trimString(propertyValue, AuditService.MAX_PROPERTY_SIZE)));
}
}
for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : record.getReferences().entrySet()) {
for (AuditReferenceValue referenceValue : referenceEntry.getValue()) {
repo.getReferenceValues().add(RAuditReferenceValue.toRepo(repo, referenceEntry.getKey(), referenceValue));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return repo;
}
use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.
the class WfTestUtil method checkWfProcessAuditRecords.
public static void checkWfProcessAuditRecords(Map<String, WorkflowResult> expectedResults, DummyAuditService dummyAuditService) {
List<AuditEventRecord> records = dummyAuditService.getRecordsOfType(AuditEventType.WORKFLOW_PROCESS_INSTANCE);
assertEquals("Unexpected number of workflow process instance audit records", expectedResults.size() * 2, records.size());
for (AuditEventRecord record : records) {
if (record.getEventStage() != AuditEventStage.EXECUTION) {
continue;
}
Set<AuditReferenceValue> targetRef = record.getReferenceValues(AuditingConstants.AUDIT_TARGET);
assertEquals("Wrong # of targetRef values in " + record.debugDump(), 1, targetRef.size());
String oid = targetRef.iterator().next().getOid();
assertTrue("Unexpected role to approve: " + oid, expectedResults.containsKey(oid));
assertEquals("Unexpected result for " + oid + ": " + record.getResult(), expectedResults.get(oid), WorkflowResult.fromNiceWfAnswer(record.getResult()));
if (expectedResults.get(oid) == WorkflowResult.APPROVED) {
assertEquals("Wrong # of deltas in " + record.debugDump(), 1, record.getDeltas().size());
}
}
}
use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.
the class SqaleAuditService method insertReferences.
private void insertReferences(JdbcSession jdbcSession, MAuditEventRecord auditRow, Map<String, Set<AuditReferenceValue>> references) {
if (references.isEmpty()) {
return;
}
QAuditRefValue qr = QAuditRefValueMapping.get().defaultAlias();
SQLInsertClause insertBatch = jdbcSession.newInsert(qr);
for (String refName : references.keySet()) {
for (AuditReferenceValue refValue : references.get(refName)) {
// id will be generated, but we're not interested in those here
PolyString targetName = refValue.getTargetName();
insertBatch.set(qr.recordId, auditRow.id).set(qr.timestamp, auditRow.timestamp).set(qr.name, refName).set(qr.targetOid, SqaleUtils.oidToUUid(refValue.getOid())).set(qr.targetType, refValue.getType() != null ? MObjectType.fromTypeQName(refValue.getType()) : null).set(qr.targetNameOrig, PolyString.getOrig(targetName)).set(qr.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
}
}
if (insertBatch.getBatchCount() == 0) {
// strange, no values anywhere?
return;
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertAuditReferenceValue.
protected void assertAuditReferenceValue(AuditEventRecord event, String refName, String oid, QName type, String name) {
Set<AuditReferenceValue> values = event.getReferenceValues(refName);
assertEquals("Wrong # of reference values of '" + refName + "'", 1, values.size());
AuditReferenceValue value = values.iterator().next();
assertEquals("Wrong OID", oid, value.getOid());
assertEquals("Wrong type", type, value.getType());
assertEquals("Wrong name", name, PolyString.getOrig(value.getTargetName()));
}
use of com.evolveum.midpoint.audit.api.AuditReferenceValue in project midpoint by Evolveum.
the class SqlAuditServiceImpl method insertReferences.
private void insertReferences(JdbcSession jdbcSession, long recordId, Map<String, Set<AuditReferenceValue>> references) {
if (references.isEmpty()) {
return;
}
QAuditRefValue qAuditRefValue = QAuditRefValueMapping.get().defaultAlias();
SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditRefValue);
for (String refName : references.keySet()) {
for (AuditReferenceValue refValue : references.get(refName)) {
// id will be generated, but we're not interested in those here
PolyString targetName = refValue.getTargetName();
insertBatch.set(qAuditRefValue.recordId, recordId).set(qAuditRefValue.name, refName).set(qAuditRefValue.oid, refValue.getOid()).set(qAuditRefValue.type, RUtil.qnameToString(refValue.getType())).set(qAuditRefValue.targetNameOrig, PolyString.getOrig(targetName)).set(qAuditRefValue.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
}
}
if (insertBatch.getBatchCount() == 0) {
// strange, no values anywhere?
return;
}
insertBatch.setBatchToBulk(true);
insertBatch.execute();
}
Aggregations