use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method determineDeputyValidity.
private boolean determineDeputyValidity(PrismObject<UserType> potentialDeputy, List<ObjectReferenceType> assignees, @Nullable AbstractWorkItemType workItem, QName privilegeLimitationItemName, Task task, OperationResult result) {
AssignmentEvaluator.Builder<UserType> builder = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(potentialDeputy, null, potentialDeputy, potentialDeputy.getDefinition())).channel(null).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).loginMode(true).lensContext(new LensContextPlaceholder<>(potentialDeputy));
AssignmentEvaluator<UserType> assignmentEvaluator = builder.build();
for (AssignmentType assignmentType : potentialDeputy.asObjectable().getAssignment()) {
if (!DeputyUtils.isDelegationAssignment(assignmentType, relationRegistry)) {
continue;
}
try {
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType));
// TODO some special mode for verification of the validity - we don't need complete calculation here!
EvaluatedAssignment<UserType> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, potentialDeputy.asObjectable(), potentialDeputy.toString(), AssignmentOrigin.createInObject(), task, result);
if (!assignment.isValid()) {
continue;
}
for (EvaluatedAssignmentTarget target : assignment.getRoles().getNonNegativeValues()) {
// MID-6403
if (target.getTarget().getOid() != null && DeputyUtils.isDelegationPath(target.getAssignmentPath(), relationRegistry) && ObjectTypeUtil.containsOid(assignees, target.getTarget().getOid())) {
List<OtherPrivilegesLimitationType> limitations = DeputyUtils.extractLimitations(target.getAssignmentPath());
if (workItem != null && DeputyUtils.limitationsAllow(limitations, privilegeLimitationItemName, workItem) || workItem == null && SchemaDeputyUtil.limitationsAllow(limitations, privilegeLimitationItemName)) {
return true;
}
}
}
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't verify 'deputy' relation between {} and {} for work item {}; assignment: {}", e, potentialDeputy, assignees, workItem, assignmentType);
}
}
return false;
}
use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.
the class LensUtil method getIterationTokenVariableValue.
public static Object getIterationTokenVariableValue(LensProjectionContext accCtx) {
String iterationTokenOld = null;
PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent();
if (shadowCurrent != null) {
iterationTokenOld = shadowCurrent.asObjectable().getIterationToken();
}
if (iterationTokenOld == null) {
return accCtx.getIterationToken();
}
PrismPropertyDefinition<String> propDef = PrismContext.get().definitionFactory().createPropertyDefinition(ExpressionConstants.VAR_ITERATION_TOKEN_QNAME, DOMUtil.XSD_STRING);
PrismProperty<String> propOld = propDef.instantiate();
propOld.setRealValue(iterationTokenOld);
PropertyDelta<String> propDelta = propDef.createEmptyDelta(ExpressionConstants.VAR_ITERATION_TOKEN_QNAME);
propDelta.setRealValuesToReplace(accCtx.getIterationToken());
PrismProperty<String> propNew = propDef.instantiate();
propNew.setRealValue(accCtx.getIterationToken());
ItemDeltaItem<PrismPropertyValue<String>, PrismPropertyDefinition<String>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew, propDef);
return idi;
}
use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.
the class TimeConstraintsEvaluation method parseTimeSource.
private XMLGregorianCalendar parseTimeSource(VariableBindingDefinitionType source, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ItemPath path = m.parser.getSourcePath(source);
Object sourceObject = ExpressionUtil.resolvePathGetValue(path, m.variables, false, m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext, "reference time definition in " + m.getMappingContextDescription(), m.getTask(), result);
LOGGER.trace("parseTimeSource: path = {}, source object = {}", path, sourceObject);
if (sourceObject == null) {
return null;
}
PrismProperty<XMLGregorianCalendar> timeProperty;
if (sourceObject instanceof ItemDeltaItem<?, ?>) {
// noinspection unchecked
timeProperty = (PrismProperty<XMLGregorianCalendar>) ((ItemDeltaItem<?, ?>) sourceObject).getItemNew();
} else if (sourceObject instanceof Item<?, ?>) {
// noinspection unchecked
timeProperty = (PrismProperty<XMLGregorianCalendar>) sourceObject;
} else {
throw new IllegalStateException("Unknown resolve result " + sourceObject);
}
return timeProperty != null ? timeProperty.getRealValue() : null;
}
use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.
the class ExpressionUtil method computeTargetValues.
public static <V extends PrismValue> Collection<V> computeTargetValues(VariableBindingDefinitionType target, TypedValue defaultTargetContext, VariablesMap variables, ObjectResolver objectResolver, String contextDesc, PrismContext prismContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
if (target == null) {
// Is this correct? What about default targets?
return null;
}
ItemPathType itemPathType = target.getPath();
if (itemPathType == null) {
// Is this correct? What about default targets?
return null;
}
ItemPath path = itemPathType.getItemPath();
Object object = resolvePathGetValue(path, variables, false, defaultTargetContext, objectResolver, prismContext, contextDesc, task, result);
if (object == null) {
return new ArrayList<>();
} else if (object instanceof Item) {
return ((Item) object).getValues();
} else if (object instanceof PrismValue) {
return (List<V>) Collections.singletonList((PrismValue) object);
} else if (object instanceof ItemDeltaItem) {
ItemDeltaItem<V, ?> idi = (ItemDeltaItem<V, ?>) object;
PrismValueDeltaSetTriple<V> triple = idi.toDeltaSetTriple(prismContext);
return triple != null ? triple.getNonNegativeValues() : new ArrayList<>();
} else {
throw new IllegalStateException("Unsupported target value(s): " + object.getClass() + " (" + object + ")");
}
}
use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.
the class PathExpressionEvaluation method getInitialResolveContextFromVariable.
private ResolutionContext getInitialResolveContextFromVariable() throws ExpressionEvaluationException {
String variableName = ItemPath.toVariableName(pathToResolve.first()).getLocalPart();
pathToResolve = pathToResolve.rest();
TypedValue variableValueAndDefinition = evaluator.findInSourcesAndVariables(context, variableName);
if (variableValueAndDefinition == null) {
throw new ExpressionEvaluationException("No variable with name " + variableName + " in " + context.getContextDescription());
}
Object variableValue = variableValueAndDefinition.getValue();
if (variableValue == null) {
return null;
} else if (variableValue instanceof Item || variableValue instanceof ItemDeltaItem<?, ?>) {
return IdiResolutionContext.fromAnyObject(variableValue);
} else if (variableValue instanceof PrismValue) {
return new ValueResolutionContext((PrismValue) variableValue, context.getContextDescription());
} else if (variableValueAndDefinition.getTypeClass().isAssignableFrom(variableValue.getClass())) {
return ValueResolutionContext.fromRealValue(variableValue, context.getContextDescription(), evaluator.getPrismContext());
} else {
throw new ExpressionEvaluationException("Unexpected variable value " + variableValue + " (" + variableValue.getClass() + ")");
}
}
Aggregations