Skip to content

Commit

Permalink
Another fix, merge was incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 12, 2023
1 parent 8afbd30 commit 5e18d5c
Showing 1 changed file with 1 addition and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,10 @@
package com.evolveum.midpoint.model.impl.lens;

import java.util.Collection;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.prism.PrismContext;

import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;

import com.evolveum.midpoint.repo.common.expression.ExpressionUtil;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.expression.VariablesMap;

import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.audit.api.AuditEventRecord;
Expand All @@ -41,6 +26,7 @@
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -53,13 +39,7 @@ public class ClockworkAuditHelper {

private static final Trace LOGGER = TraceManager.getTrace(ClockworkAuditHelper.class);

private static final String OP_EVALUATE_AUDIT_RECORD_PROPERTY =
ClockworkAuditHelper.class.getName() + ".evaluateAuditRecordProperty";

@Autowired private PrismContext prismContext;
@Autowired private AuditHelper auditHelper;
@Autowired private ExpressionFactory expressionFactory;
@Autowired @Qualifier("cacheRepositoryService") private RepositoryService repositoryService;

// "overallResult" covers the whole clockwork run
// while "result" is - most of the time - related to the current clockwork click
Expand Down Expand Up @@ -232,64 +212,6 @@ private <F extends ObjectType> void recordResourceOids(
}
}

private <F extends ObjectType> void evaluateAuditRecordProperty(SystemConfigurationAuditEventRecordingPropertyType propertyDef,
AuditEventRecord auditRecord, PrismObject<? extends ObjectType> primaryObject, LensContext<F> context, Task task,
OperationResult parentResult) {
String name = propertyDef.getName();
OperationResult result = parentResult.subresult(OP_EVALUATE_AUDIT_RECORD_PROPERTY)
.addParam("name", name)
.setMinor()
.build();
try {
if (StringUtils.isBlank(name)) {
throw new IllegalArgumentException("Name of SystemConfigurationAuditEventRecordingPropertyType is empty or null in " + propertyDef);
}
if (!targetSelectorMatches(propertyDef.getTargetSelector(), primaryObject)) {
result.recordNotApplicable();
return;
}
ExpressionType expression = propertyDef.getExpression();
if (expression != null) {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
String shortDesc = "value for custom column of audit table";
Collection<String> values = ExpressionUtil.evaluateStringExpression(variables, prismContext, expression,
context.getPrivilegedExpressionProfile(), expressionFactory, shortDesc, task, result);
if (values == null || values.isEmpty()) {
// nothing to do
} else if (values.size() == 1) {
auditRecord.getCustomColumnProperty().put(name, values.iterator().next());
} else {
throw new IllegalArgumentException("Collection of expression result contains more than one value");
}
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit record property expression {}", t, name);
// Intentionally not throwing the exception. The error is marked as partial.
// (It would be better to mark it as fatal and to derive overall result as partial, but we aren't that far yet.)
result.recordPartialError(t);
} finally {
result.recordSuccessIfUnknown();
}
}

private boolean targetSelectorMatches(List<ObjectSelectorType> targetSelectors,
PrismObject<? extends ObjectType> primaryObject) throws CommunicationException, ObjectNotFoundException,
SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
if (targetSelectors.isEmpty()) {
return true;
}
for (ObjectSelectorType targetSelector : targetSelectors) {
if (repositoryService.selectorMatches(
targetSelector, primaryObject, null, LOGGER, "target selector")) {
return true;
}
}
LOGGER.debug("No selector matches for {}", primaryObject);
return false;
}

@NotNull
private AuditEventType determineEventType(ObjectDelta<? extends ObjectType> primaryDelta) {
AuditEventType eventType;
Expand Down

0 comments on commit 5e18d5c

Please sign in to comment.