Skip to content

Commit

Permalink
Add ability to compute specific item modification count
Browse files Browse the repository at this point in the history
1. Counts modifications based on the specified item path.
  • Loading branch information
tchrapovic committed Jan 25, 2024
1 parent 56adecc commit 0165827
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/simulation/results/metrics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,36 @@ We can restrict the selection (or domain) of the original metric to cover only s
----
<1> The `after` item represents the object state after the operation.
(Note that if the `department` attribute itself is modified to a value other than "Security services", this change is not seen by this simple filter.)

Let's explore how to configure the system to determine whether any changes have occurred to
a specific attribute such as `employeeNumber`.

.Listing 7. Computation of attribute modifications for specific item path
[source,xml]
----
<metric>
<identifier>attribute-modifications-employee-number</identifier>
<computation>
<domain>
<expression>
<script>
<code>processedObject.isShadow()</code>
</script>
</expression>
</domain>
<valueExpression>
<script>
<code>
import com.evolveum.midpoint.prism.path.ItemPath;
def itemPath = ItemPath.create('attributes','employeeNumber');<!--1-->
return processedObject.getItemModificationsCount(itemPath);<!--2-->
</code>
</script>
</valueExpression>
</computation>
</metric>
----
<1> Define the item path for 'employeeNumber'. The item path must exactly match the configuration.
<2> Compute the count of modifications for the specified item path.
To include sub-item modifications, use `getItemModificationsCount(itemPath, true)`.
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,48 @@ private boolean isAttributeModification(@NotNull ItemDelta<?, ?> modification) {
return ShadowType.F_ATTRIBUTES.equivalent(modification.getParentPath());
}

/**
* Counts modifications based on the specified path, excluding changes in ADD/DELETE deltas.
* <p>
* The item path must exactly match the configuration.
* </p>
* Sub-item modifications are not counted.
*
* @param itemPath the path to count modifications for
* @return the number of attribute modifications.
*/
@SuppressWarnings("unused") // used in scripts
public int getItemModificationsCount(@NotNull ItemPath itemPath) {
return getItemModificationsCount(itemPath, false);
}

/**
* Counts modifications based on the specified path, excluding changes in ADD/DELETE deltas.
* <p>
* The item path must exactly match the configuration.
* </p>
* If {@code allowSubPaths} is true, sub-item modifications are also counted.
*
* @param itemPath the path to count modifications for
* @param allowSubPaths if true, sub-item modifications are allowed
* @return the number of attribute modifications
*/
@SuppressWarnings("unused") // used in scripts
public int getItemModificationsCount(@NotNull ItemPath itemPath, boolean allowSubPaths) {
if (delta == null || !delta.isModify()) {
return 0;
}

return (int) delta.getModifications().stream()
.filter(itemDelta -> {
ItemPath deltaPath = itemDelta.getPath();
return allowSubPaths
? deltaPath.isSuperPathOrEquivalent(itemPath)
: deltaPath.equivalent(itemPath);
})
.count();
}

/**
* Returns the number of VALUES of associations added or deleted.
*
Expand Down

0 comments on commit 0165827

Please sign in to comment.