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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations