Search in sources :

Example 1 with AssignmentPathImpl

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;
}
Also used : LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) AssignmentPathSegmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathSegmentImpl) EvaluatedPolicyRuleImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl) EvaluatedCollectionStatsTrigger(com.evolveum.midpoint.model.api.context.EvaluatedCollectionStatsTrigger) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) AssignmentPathImpl(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathImpl) CollectionStats(com.evolveum.midpoint.model.api.CollectionStats) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CollectionStats (com.evolveum.midpoint.model.api.CollectionStats)1 EvaluatedCollectionStatsTrigger (com.evolveum.midpoint.model.api.context.EvaluatedCollectionStatsTrigger)1 EvaluatedPolicyRuleImpl (com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl)1 AssignmentPathImpl (com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathImpl)1 AssignmentPathSegmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.AssignmentPathSegmentImpl)1 LocalizableMessageBuilder (com.evolveum.midpoint.util.LocalizableMessageBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1