Search in sources :

Example 1 with CollectionStats

use of com.evolveum.midpoint.model.api.CollectionStats in project midpoint by Evolveum.

the class DashboardServiceImpl method generateNumberMessageForCollection.

private String generateNumberMessageForCollection(DashboardWidgetType widget, DashboardWidget data, Task task, OperationResult result) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, ObjectNotFoundException {
    CollectionRefSpecificationType collectionSpec = getCollectionRefSpecificationType(widget, task, result);
    if (collectionSpec != null) {
        CompiledObjectCollectionView compiledCollection = modelInteractionService.compileObjectCollectionView(collectionSpec, null, task, task.getResult());
        CollectionStats collStats = modelInteractionService.determineCollectionStats(compiledCollection, task, result);
        // getObjectCount(valueCollection, true, task, result);
        Integer value = collStats.getObjectCount();
        Integer domainValue = collStats.getDomainCount();
        IntegerStatType statType = generateIntegerStat(value, domainValue);
        Collection<EvaluatedPolicyRule> evalPolicyRules = new ArrayList<>();
        if (collectionSpec.getCollectionRef() != null && QNameUtil.match(ObjectCollectionType.COMPLEX_TYPE, collectionSpec.getCollectionRef().getType())) {
            ObjectCollectionType valueCollection = getObjectCollectionType(widget, task, result);
            evalPolicyRules = modelInteractionService.evaluateCollectionPolicyRules(valueCollection.asPrismObject(), compiledCollection, null, task, task.getResult());
        }
        Collection<String> policySituations = new ArrayList<>();
        for (EvaluatedPolicyRule evalPolicyRule : evalPolicyRules) {
            if (!evalPolicyRule.getAllTriggers().isEmpty()) {
                policySituations.add(evalPolicyRule.getPolicySituation());
            }
        }
        return generateNumberMessage(widget, createVariables(null, statType, policySituations, null), data);
    } else {
        LOGGER.error("CollectionRefSpecificationType is null in widget " + widget.getIdentifier());
    }
    return null;
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) CompiledObjectCollectionView(com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView) CollectionStats(com.evolveum.midpoint.model.api.CollectionStats)

Example 2 with CollectionStats

use of com.evolveum.midpoint.model.api.CollectionStats in project midpoint by Evolveum.

the class CollectionProcessor method determineCollectionStats.

public <O extends ObjectType> CollectionStats determineCollectionStats(CompiledObjectCollectionView collectionView, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
    CollectionStats stats = new CollectionStats();
    Class<O> targetClass = collectionView.getTargetClass(prismContext);
    stats.setObjectCount(countObjects(targetClass, evaluateExpressionsInFilter(collectionView.getFilter(), result, task), collectionView.getOptions(), task, result));
    stats.setDomainCount(countObjects(targetClass, evaluateExpressionsInFilter(collectionView.getDomainFilter(), result, task), collectionView.getDomainOptions(), task, result));
    return stats;
}
Also used : CollectionStats(com.evolveum.midpoint.model.api.CollectionStats)

Example 3 with CollectionStats

use of com.evolveum.midpoint.model.api.CollectionStats 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)

Example 4 with CollectionStats

use of com.evolveum.midpoint.model.api.CollectionStats in project midpoint by Evolveum.

the class TestCollections method test110CollectionStatsAllEnabled.

@Test
public void test110CollectionStatsAllEnabled() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // WHEN
    when();
    CollectionStats stats = modelInteractionService.determineCollectionStats(collectionViewActiveUsers, task, result);
    // THEN
    then();
    displayValue("Collection stats", stats);
    assertSuccess(result);
    assertNotNull("Null stats", stats);
    assertEquals("Wrong object count", (Integer) getNumberOfUsers(), stats.getObjectCount());
    assertEquals("Wrong domain count", (Integer) getNumberOfUsers(), stats.getDomainCount());
    assertPercentage(stats, 100);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CollectionStats(com.evolveum.midpoint.model.api.CollectionStats) Test(org.testng.annotations.Test)

Example 5 with CollectionStats

use of com.evolveum.midpoint.model.api.CollectionStats in project midpoint by Evolveum.

the class TestCollections method test120CollectionStatsOneDisabled.

@Test
public void test120CollectionStatsOneDisabled() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    modifyUserReplace(USER_GUYBRUSH_OID, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, task, result, ActivationStatusType.DISABLED);
    numberOfDisabledUsers++;
    // WHEN
    when();
    CollectionStats stats = modelInteractionService.determineCollectionStats(collectionViewActiveUsers, task, result);
    // THEN
    then();
    displayValue("Collection stats", stats);
    assertSuccess(result);
    assertNotNull("Null stats", stats);
    assertEquals("Wrong object count", (Integer) (getNumberOfUsers() - numberOfDisabledUsers), stats.getObjectCount());
    assertEquals("Wrong domain count", (Integer) getNumberOfUsers(), stats.getDomainCount());
    assertPercentage(stats, (getNumberOfUsers() - numberOfDisabledUsers) * 100f / getNumberOfUsers());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CollectionStats(com.evolveum.midpoint.model.api.CollectionStats) Test(org.testng.annotations.Test)

Aggregations

CollectionStats (com.evolveum.midpoint.model.api.CollectionStats)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 Test (org.testng.annotations.Test)2 CompiledObjectCollectionView (com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView)1 EvaluatedCollectionStatsTrigger (com.evolveum.midpoint.model.api.context.EvaluatedCollectionStatsTrigger)1 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)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