use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class ObjectFilterAsserter method assertEq.
public ObjectFilterAsserter<RA> assertEq(ItemPath expectedItemPath, Object expectedValue) {
assertClass(EqualFilter.class);
ItemPath actualItemPath = ((EqualFilter) filter).getPath();
AssertJUnit.assertTrue("Wrong path in eq clause, expected " + expectedItemPath + ", but was " + actualItemPath + "; in " + desc(), expectedItemPath.equivalent(actualItemPath));
PrismValue actualPVal = ((EqualFilter) filter).getSingleValue();
Object actualValue = actualPVal.getRealValue();
AssertJUnit.assertTrue("Wrong value in eq clause, expected " + expectedValue + ", but was " + actualValue + "; in " + desc(), expectedValue.equals(actualValue));
return this;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class AuditHelper method evaluateRecordingExpression.
public <F extends ObjectType> AuditEventRecord evaluateRecordingExpression(ExpressionType expression, AuditEventRecord auditRecord, PrismObject<? extends ObjectType> primaryObject, ModelContext<F> context, Task task, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OP_EVALUATE_RECORDING_SCRIPT);
try {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(context, null, task, result));
try {
PrismValue returnValue = ExpressionUtil.evaluateExpression(variables, null, expression, context != null ? context.getPrivilegedExpressionProfile() : null, expressionFactory, OP_EVALUATE_RECORDING_SCRIPT, task, result);
return returnValue != null ? (AuditEventRecord) returnValue.getRealValue() : null;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit recording expression", t);
// Copied from evaluateAuditRecordProperty: 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();
}
// modified by some part of the script too - this we have to suffer.
return auditRecord;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class TransformationBuiltinMapping method markNotTransient.
/**
* The value can contain transient values e.g. because during its computation the transformation metadata was
* marked as transient. But there can be situations when transformation metadata for the current value are
* non-transient. Then we could want to store them completely, i.e. with transformation metadata of source values.
* So we must mark them as not transient.
*/
private void markNotTransient(PrismValue rootValue) {
rootValue.accept(visitable -> {
if (visitable instanceof PrismValue) {
PrismValue value = (PrismValue) visitable;
value.setTransient(false);
value.getValueMetadataAsContainer().valuesStream().forEach(this::markNotTransient);
}
});
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class CaseExpressionEvaluationHelper method evaluateExpression.
@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, VariablesMap variables, String contextDescription, Class<T> clazz, QName typeName, boolean multiValued, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
MutableItemDefinition<?> resultDef;
ItemName resultName = new ItemName(SchemaConstants.NS_C, "result");
if (QNameUtil.match(typeName, ObjectReferenceType.COMPLEX_TYPE)) {
resultDef = prismContext.definitionFactory().createReferenceDefinition(resultName, typeName);
} else {
resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, typeName);
}
if (multiValued) {
resultDef.setMaxOccurs(-1);
}
Expression<?, ?> expression = expressionFactory.makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), contextDescription, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task);
context.setAdditionalConvertor(additionalConvertor);
PrismValueDeltaSetTriple<?> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateAnyExpressionInContext(expression, context, task, result);
List<T> list = new ArrayList<>();
for (PrismValue pv : exprResultTriple.getZeroSet()) {
T realValue;
if (pv instanceof PrismReferenceValue) {
// pv.getRealValue sometimes returns synthesized Referencable, not ObjectReferenceType
// If we would stay with that we would need to make many changes throughout workflow module.
// So it is safer to stay with ObjectReferenceType.
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue((PrismReferenceValue) pv);
realValue = (T) ort;
} else {
realValue = pv.getRealValue();
}
list.add(realValue);
}
return list;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class CredentialPolicyEvaluator method hasValueDelta.
private boolean hasValueDelta(ObjectDelta<F> focusDelta, ItemPath credentialsPath) {
if (focusDelta == null) {
return false;
}
for (PartiallyResolvedDelta<PrismValue, ItemDefinition> partialDelta : focusDelta.findPartial(credentialsPath)) {
LOGGER.trace("Residual delta:\n{}", partialDelta.debugDumpLazily());
ItemPath residualPath = partialDelta.getResidualPath();
if (ItemPath.isEmpty(residualPath)) {
continue;
}
LOGGER.trace("PATH: {}", residualPath);
ItemName name = residualPath.firstName();
LOGGER.trace("NAME: {}", name);
if (isValueElement(name)) {
return true;
}
}
return false;
}
Aggregations