-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add draft item-level simulation report
This commit provides a simple (unfinished) simulation report on the level of individual modified items. Other changes: 1. Added <?> to ItemDefinition is various places (see 64aa3962b70b4364bd6ad1f5fdf7ce8be4687ff4 in prism). 2. Added support for multivalued report parameters.
- Loading branch information
Showing
42 changed files
with
660 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
infra/schema/src/main/java/com/evolveum/midpoint/schema/util/delta/ItemDeltaFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2010-2023 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.schema.util.delta; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.prism.delta.ItemDelta; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.prism.path.PathSet; | ||
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; | ||
|
||
/** | ||
* Filters item deltas according to specified criteria. | ||
* | ||
* Currently in `schema` module (not in `prism` one), because I am not sure if it will be midPoint-specific or not. | ||
*/ | ||
public class ItemDeltaFilter { | ||
|
||
@NotNull private final PathSet pathsToInclude = new PathSet(); | ||
@NotNull private final PathSet pathsToExclude = new PathSet(); | ||
private boolean includeOperationalItems = false; | ||
|
||
public static ItemDeltaFilter create(Object pathsToInclude, Object pathsToExclude, Boolean includeOperationalItems) { | ||
ItemDeltaFilter filter = new ItemDeltaFilter(); | ||
filter.pathsToInclude.addAll(toPaths(pathsToInclude)); | ||
filter.pathsToExclude.addAll(toPaths(pathsToExclude)); | ||
if (includeOperationalItems != null) { | ||
filter.includeOperationalItems = includeOperationalItems; | ||
} | ||
return filter; | ||
} | ||
|
||
private static Collection<? extends ItemPath> toPaths(Object object) { | ||
if (object == null) { | ||
return List.of(); | ||
} else if (object instanceof Collection) { | ||
return ((Collection<?>) object).stream() | ||
.map(o -> toPath(o)) | ||
.collect(Collectors.toList()); | ||
} else { | ||
return List.of(toPath(object)); | ||
} | ||
} | ||
|
||
private static ItemPath toPath(Object object) { | ||
if (object instanceof ItemPath) { | ||
return (ItemPath) object; | ||
} else if (object instanceof ItemPathType) { | ||
return ((ItemPathType) object).getItemPath(); | ||
} else if (object instanceof String) { | ||
return ItemPath.fromString((String) object); | ||
} else { | ||
throw new IllegalArgumentException("Not a path: " + object); | ||
} | ||
} | ||
|
||
/** | ||
* TODO describe the algorithm | ||
*/ | ||
public boolean matches(ItemDelta<?, ?> itemDelta) { | ||
ItemPath path = itemDelta.getPath().namedSegmentsOnly(); | ||
Boolean match = getExactMatch(path); | ||
if (match != null) { | ||
return match; // Ignoring "operational" flag for exact match | ||
} | ||
if (itemDelta.isOperational() && !includeOperationalItems) { | ||
return false; | ||
} | ||
ItemPath reduced = path.allExceptLast(); | ||
for (;;) { | ||
Boolean matchReduced = getExactMatch(reduced); | ||
if (matchReduced != null) { | ||
return matchReduced; | ||
} | ||
if (reduced.isEmpty()) { | ||
// If we specified anything to include, the the default is assumed to be "NOT INCLUDED". | ||
return pathsToInclude.isEmpty(); | ||
} | ||
reduced = reduced.allExceptLast(); | ||
} | ||
} | ||
|
||
private Boolean getExactMatch(ItemPath path) { | ||
if (pathsToInclude.contains(path)) { | ||
return true; | ||
} else if (pathsToExclude.contains(path)) { | ||
return false; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.