use of com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method process.
@Override
public Predicate process(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter) throws QueryException {
// This is a tricky situation, if multi-value, each value can have different path (derived
// from AuditEventRecordCustomColumnPropertyType.getName()), so we can't use this directly.
ValueFilterValues<AuditEventRecordCustomColumnPropertyType, ?> values = ValueFilterValues.from(filter);
if (values.isEmpty()) {
throw new QueryException("Custom column null value is not supported," + " column can't be determined from filter: " + filter);
}
if (values.isMultiValue()) {
Predicate predicate = null;
for (AuditEventRecordCustomColumnPropertyType propertyType : values.allValuesRaw()) {
Predicate right = createPredicate(filter, propertyType);
predicate = predicate != null ? ExpressionUtils.or(predicate, right) : right;
}
return predicate;
}
AuditEventRecordCustomColumnPropertyType value = values.singleValueRaw();
assert value != null;
return createPredicate(filter, value);
}
use of com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType in project midpoint by Evolveum.
the class AuditCustomColumnItemFilterProcessor method process.
@Override
public Predicate process(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter) throws QueryException {
// This is a tricky situation, if multi-value, each value can have different path (derived
// from AuditEventRecordCustomColumnPropertyType.getName()), so we can't use this directly.
ValueFilterValues<AuditEventRecordCustomColumnPropertyType, ?> values = ValueFilterValues.from(filter);
if (values.isEmpty()) {
throw new QueryException("Custom column null value is not supported," + " column can't be determined from filter: " + filter);
}
if (values.isMultiValue()) {
Predicate predicate = null;
for (AuditEventRecordCustomColumnPropertyType propertyType : values.allValuesRaw()) {
Predicate right = createPredicate(filter, propertyType);
predicate = predicate != null ? ExpressionUtils.or(predicate, right) : right;
}
return predicate;
}
AuditEventRecordCustomColumnPropertyType value = values.singleValueRaw();
assert value != null;
return createPredicate(filter, value);
}
use of com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType in project midpoint by Evolveum.
the class AuditEventRecord method createAuditEventRecordType.
// TODO: currently unused (2021), but if audit(AERType) will be reused as part of audit(AER) it can still be useful
public AuditEventRecordType createAuditEventRecordType(boolean tolerateInconsistencies) {
AuditEventRecordType auditRecord = new AuditEventRecordType();
auditRecord.setRepoId(repoId);
auditRecord.setChannel(channel);
auditRecord.setEventIdentifier(eventIdentifier);
auditRecord.setEventStage(AuditEventStage.toSchemaValue(eventStage));
auditRecord.setEventType(AuditEventType.toSchemaValue(eventType));
auditRecord.setHostIdentifier(hostIdentifier);
auditRecord.setRemoteHostAddress(remoteHostAddress);
auditRecord.setNodeIdentifier(nodeIdentifier);
auditRecord.setInitiatorRef(ObjectTypeUtil.createObjectRef(initiatorRef, true));
auditRecord.setAttorneyRef(ObjectTypeUtil.createObjectRef(attorneyRef, true));
auditRecord.setMessage(message);
auditRecord.setOutcome(OperationResultStatus.createStatusType(outcome));
auditRecord.setParameter(parameter);
auditRecord.setResult(result);
auditRecord.setSessionIdentifier(sessionIdentifier);
auditRecord.setTargetOwnerRef(ObjectTypeUtil.createObjectRef(targetOwnerRef, true));
auditRecord.setTargetRef(ObjectTypeUtil.createObjectRef(targetRef, true));
auditRecord.setRequestIdentifier(requestIdentifier);
auditRecord.setTaskIdentifier(taskIdentifier);
auditRecord.setTaskOID(taskOid);
auditRecord.getResourceOid().addAll(resourceOids);
auditRecord.setTimestamp(MiscUtil.asXMLGregorianCalendar(timestamp));
for (ObjectDeltaOperation<?> delta : deltas) {
ObjectDeltaOperationType odo = new ObjectDeltaOperationType();
try {
DeltaConversionOptions options = DeltaConversionOptions.createSerializeReferenceNames();
// This can be tricky because it can create human-readable but machine-unprocessable
// data, see MID-6262. But in current context the results of this method are to be
// used only in GUI and reports, so we are safe here.
options.setEscapeInvalidCharacters(true);
DeltaConvertor.toObjectDeltaOperationType(delta, odo, options);
auditRecord.getDelta().add(odo);
} catch (Exception e) {
if (tolerateInconsistencies) {
if (delta.getExecutionResult() != null) {
// TODO does this even work? [med]
delta.getExecutionResult().setMessage("Could not show audit record, bad data in delta: " + delta.getObjectDelta());
} else {
OperationResult result = new OperationResult("Create audit event record type");
result.setMessage("Could not show audit record, bad data in delta: " + delta.getObjectDelta());
odo.setExecutionResult(result.createOperationResultType());
}
} else {
throw new SystemException(e.getMessage(), e);
}
}
}
for (Map.Entry<String, Set<String>> propertyEntry : properties.entrySet()) {
AuditEventRecordPropertyType propertyType = new AuditEventRecordPropertyType();
propertyType.setName(propertyEntry.getKey());
propertyType.getValue().addAll(propertyEntry.getValue());
auditRecord.getProperty().add(propertyType);
}
for (Map.Entry<String, Set<AuditReferenceValue>> referenceEntry : references.entrySet()) {
AuditEventRecordReferenceType referenceType = new AuditEventRecordReferenceType();
referenceType.setName(referenceEntry.getKey());
referenceEntry.getValue().forEach(v -> referenceType.getValue().add(v.toXml()));
auditRecord.getReference().add(referenceType);
}
for (Map.Entry<String, String> customColumnEntry : customColumnProperty.entrySet()) {
AuditEventRecordCustomColumnPropertyType customColumn = new AuditEventRecordCustomColumnPropertyType();
customColumn.setName(customColumnEntry.getKey());
customColumn.setValue(customColumnEntry.getValue());
auditRecord.getCustomColumnProperty().add(customColumn);
}
// TODO MID-5531 convert custom properties too? What about other than string types?
return auditRecord;
}
use of com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType in project midpoint by Evolveum.
the class DefaultColumnUtils method processSpecialColumn.
public static String processSpecialColumn(ItemPath itemPath, Containerable object, LocalizationService localization) {
if (itemPath == null) {
return null;
}
if (object instanceof TaskType) {
TaskType task = (TaskType) object;
if (itemPath.equivalent(TaskType.F_COMPLETION_TIMESTAMP)) {
XMLGregorianCalendar timestamp = task.getCompletionTimestamp();
if (timestamp != null && task.getExecutionState() == TaskExecutionStateType.CLOSED) {
// Do we want default locale or default locale for FORMAT category?
// For latter no .withLocale() would be needed.
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM).withLocale(Locale.getDefault());
ZonedDateTime time = timestamp.toGregorianCalendar().toZonedDateTime();
String dateTime = formatter.format(time);
String key = "pageTasks.task.closedAt";
return localization.translate(key, null, Locale.getDefault(), key) + " " + dateTime;
}
return "";
} else if (itemPath.equivalent(TaskType.F_SCHEDULE)) {
List<Object> localizationObject = new ArrayList<>();
String key = TaskTypeUtil.createScheduledToRunAgain(task, localizationObject);
Object[] params = localizationObject.isEmpty() ? null : localizationObject.toArray();
return localization.translate(key, params, Locale.getDefault(), key);
} else if (itemPath.equivalent(TaskType.F_PROGRESS)) {
// TODO revise this; re-add "stalled since" information
if (ActivityStateUtil.isProgressAvailableLocally(task)) {
ActivityProgressInformation progress = ActivityProgressInformation.fromRootTask(task, FULL_STATE_PREFERRED);
// TODO create toLocalizedString method
return progress.toHumanReadableString(false);
} else {
return "";
}
} else if (itemPath.equivalent(TASK_ERRORS)) {
if (ActivityStateUtil.isProgressAvailableLocally(task)) {
ActivityProgressInformation progress = ActivityProgressInformation.fromRootTask(task, FULL_STATE_PREFERRED);
return String.valueOf(progress.getErrorsRecursive());
} else {
return "0";
}
}
} else if (object instanceof AuditEventRecordType) {
for (AuditEventRecordCustomColumnPropertyType customColumn : ((AuditEventRecordType) object).getCustomColumnProperty()) {
if (customColumn.getName().equals(itemPath.toString())) {
return customColumn.getValue();
}
}
}
return null;
}
use of com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType in project midpoint by Evolveum.
the class AuditInsertion method insertAuditEventRecord.
private MAuditEventRecord insertAuditEventRecord(MAuditEventRecord row) {
QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
QAuditEventRecord aer = aerMapping.defaultAlias();
SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
// Custom columns, this better be replaced by some extension container later
Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
for (AuditEventRecordCustomColumnPropertyType property : record.getCustomColumnProperty()) {
if (!customColumns.containsKey(property.getName())) {
throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + property.getName());
}
// Like insert.set, but that one is too parameter-type-safe for our generic usage here.
insert.columns(aer.getPath(property.getName())).values(property.getValue());
}
Long returnedId = insert.executeWithKey(aer.id);
// If returned ID is null, it was likely provided, so we use that one.
row.id = returnedId != null ? returnedId : record.getRepoId();
return row;
}
Aggregations