use of com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathImpl 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