use of com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathSegmentImpl in project midpoint by Evolveum.
the class LensUtil method computeAssignmentPathVariables.
public static AssignmentPathVariables computeAssignmentPathVariables(AssignmentPathImpl assignmentPath) throws SchemaException {
if (assignmentPath == null || assignmentPath.isEmpty()) {
return null;
}
AssignmentPathVariables vars = new AssignmentPathVariables();
vars.setAssignmentPath(assignmentPath.clone());
Iterator<AssignmentPathSegmentImpl> iterator = assignmentPath.getSegments().iterator();
while (iterator.hasNext()) {
AssignmentPathSegmentImpl segment = iterator.next();
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> segmentAssignmentIdi = segment.getAssignmentIdi();
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> magicAssignmentIdi;
// Magic assignment
if (vars.getMagicAssignment() == null) {
magicAssignmentIdi = segmentAssignmentIdi.clone();
vars.setMagicAssignment(magicAssignmentIdi);
} else {
// Collect extension values from the assignment extension
magicAssignmentIdi = vars.getMagicAssignment();
mergeExtension(magicAssignmentIdi, segmentAssignmentIdi);
}
// Collect extension values from the source object extension
ObjectType segmentSource = segment.getSource();
if (segmentSource != null) {
mergeExtension(magicAssignmentIdi, segmentSource.asPrismObject());
}
// immediate assignment (use assignment from previous iteration)
vars.setImmediateAssignment(vars.getThisAssignment());
// this assignment
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> thisAssignment = segmentAssignmentIdi.clone();
vars.setThisAssignment(thisAssignment);
if (iterator.hasNext() && segmentSource instanceof AbstractRoleType) {
vars.setImmediateRole((PrismObject<? extends AbstractRoleType>) segmentSource.asPrismObject());
}
}
AssignmentPathSegmentImpl focusAssignmentSegment = assignmentPath.first();
vars.setFocusAssignment(focusAssignmentSegment.getAssignmentIdi().clone());
// a bit of hack -- TODO reconsider in 3.7
// objects are already cloned
convertToLegacy(vars.getMagicAssignment());
convertToLegacy(vars.getThisAssignment());
convertToLegacy(vars.getFocusAssignment());
convertToLegacy(vars.getImmediateAssignment());
return vars;
}
use of com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathSegmentImpl in project midpoint by Evolveum.
the class CollectionProcessor method evaluatePolicyRule.
/**
* Very simple implementation, needs to be extended later.
*/
@NotNull
private EvaluatedPolicyRule evaluatePolicyRule(PrismObject<ObjectCollectionType> collection, CompiledObjectCollectionView collectionView, @NotNull AssignmentType assignmentType, @NotNull PolicyRuleType policyRuleType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
AssignmentPathImpl assignmentPath = new AssignmentPathImpl();
AssignmentPathSegmentImpl assignmentPathSegment = new AssignmentPathSegmentImpl.Builder().source(collection.asObjectable()).sourceDescription("object collection " + collection).assignment(assignmentType).isAssignment(true).evaluationOrder(EvaluationOrderImpl.zero(relationRegistry)).evaluationOrderForTarget(EvaluationOrderImpl.zero(relationRegistry)).direct(// to be reconsidered - but assignment path is empty, so we consider this to be directly assigned
true).pathToSourceValid(true).pathToSourceConditionState(ConditionState.allTrue()).build();
assignmentPath.add(assignmentPathSegment);
// Generated proforma - actually not much needed for now.
String ruleId = PolicyRuleTypeUtil.createId(collection.getOid(), assignmentType.getId());
EvaluatedPolicyRuleImpl evaluatedPolicyRule = new EvaluatedPolicyRuleImpl(policyRuleType.clone(), ruleId, assignmentPath, null);
PolicyConstraintsType policyConstraints = policyRuleType.getPolicyConstraints();
if (policyConstraints == null) {
return evaluatedPolicyRule;
}
PolicyThresholdType policyThreshold = policyRuleType.getPolicyThreshold();
for (CollectionStatsPolicyConstraintType collectionStatsPolicy : policyConstraints.getCollectionStats()) {
CollectionStats stats = determineCollectionStats(collectionView, task, result);
if (isThresholdTriggered(stats, collection, policyThreshold)) {
EvaluatedPolicyRuleTrigger<?> trigger = new EvaluatedCollectionStatsTrigger(PolicyConstraintKindType.COLLECTION_STATS, collectionStatsPolicy, new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX + CONSTRAINT_KEY).arg(ObjectTypeUtil.createDisplayInformation(collection, false)).args().build(), new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY).arg(ObjectTypeUtil.createDisplayInformation(collection, false)).args().build());
evaluatedPolicyRule.addTrigger(trigger);
}
}
return evaluatedPolicyRule;
}
Aggregations