Search in sources :

Example 1 with AuditEventRecordCustomColumnPropertyType

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);
}
Also used : AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) Predicate(com.querydsl.core.types.Predicate)

Example 2 with AuditEventRecordCustomColumnPropertyType

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);
}
Also used : AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) Predicate(com.querydsl.core.types.Predicate)

Example 3 with AuditEventRecordCustomColumnPropertyType

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;
}
Also used : AuditEventRecordReferenceType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) SystemException(com.evolveum.midpoint.util.exception.SystemException) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) DeltaConversionOptions(com.evolveum.midpoint.schema.DeltaConversionOptions) AuditEventRecordPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordPropertyType)

Example 4 with AuditEventRecordCustomColumnPropertyType

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;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) ZonedDateTime(java.time.ZonedDateTime) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 5 with AuditEventRecordCustomColumnPropertyType

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;
}
Also used : AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) ColumnMetadata(com.querydsl.sql.ColumnMetadata) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

AuditEventRecordCustomColumnPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType)5 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)2 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)2 Predicate (com.querydsl.core.types.Predicate)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 DeltaConversionOptions (com.evolveum.midpoint.schema.DeltaConversionOptions)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 AuditEventRecordPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordPropertyType)1 AuditEventRecordReferenceType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType)1 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)1 ColumnMetadata (com.querydsl.sql.ColumnMetadata)1 SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1