Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Feb 27, 2023
2 parents c0caabf + 17f02f7 commit 94a5912
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.exception.SystemException;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -1114,6 +1116,35 @@ public static String getOid(ObjectType object) {
return object != null ? object.getOid() : null;
}

/**
* Converts {@link PrismContainerValue} to {@link PrismObjectValue} based {@link ObjectType} as a workaround for MID-8522.
*
* TEMPORARY CODE
*/
public static ObjectType fix(ObjectType objectable) {
if (objectable == null) {
return null;
}
PrismContainerValue<?> pcv = objectable.asPrismContainerValue();
if (pcv instanceof PrismObjectValue) {
return objectable;
}

PrismObjectValue<?> pov;
try {
pov = PrismContext.get().getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(objectable.getClass())
.instantiate()
.createNewValue();
for (Item<?, ?> item : pcv.getItems()) {
pov.add(item.clone());
}
} catch (SchemaException e) {
throw SystemException.unexpected(e, "when fixing " + objectable);
}
return (ObjectType) pov.asObjectable();
}

@FunctionalInterface
private interface ExtensionItemRemover {
// Removes item (known from the context) from the extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.util.annotation.Experimental;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.delta.ItemDelta;
Expand All @@ -22,7 +24,11 @@
* 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.
*
* LIMITED FUNCTIONALITY. We are not able to see inside deltas. So, for example, when looking for
* `activation/administrativeStatus` property, and the whole `activation` container is added, the delta is not shown.
*/
@Experimental
public class ItemDeltaFilter {

@NotNull private final PathSet pathsToInclude = new PathSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.delta.ItemDeltaFilter;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import com.google.common.collect.ImmutableMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.io.Serializable;
import java.util.Collection;
Expand All @@ -30,77 +34,155 @@

/**
* Parsed analogy of {@link SimulationResultProcessedObjectType}.
*
* Used during creation of {@link SimulationResultType} objects, reporting on them, and during testing.
*/
@Experimental
public interface ProcessedObject<O extends ObjectType> extends DebugDumpable, Serializable {

// TODO document all this!!!!!!!!!

Map<ChangeType, ObjectProcessingStateType> DELTA_TO_PROCESSING_STATE =
new ImmutableMap.Builder<ChangeType, ObjectProcessingStateType>()
.put(ChangeType.ADD, ObjectProcessingStateType.ADDED)
.put(ChangeType.DELETE, ObjectProcessingStateType.DELETED)
.put(ChangeType.MODIFY, ObjectProcessingStateType.MODIFIED)
.build();

/**
* OID of the object whole processing is described by this record. Usually not null but we shouldn't rely on it.
*
* @see SimulationResultProcessedObjectType#getOid()
*/
String getOid();

/**
* Type of the object being processed.
*
* @see SimulationResultProcessedObjectType#getType()
*/
@NotNull Class<O> getType();

/**
* Name of the object being processed. May not be known; typically for shadows to-be-created.
*
* @see SimulationResultProcessedObjectType#getName()
*/
@Nullable PolyStringType getName();

/**
* State of the object.
*
* @see #DELTA_TO_PROCESSING_STATE
* @see SimulationResultProcessedObjectType#getState()
*/
@NotNull ObjectProcessingStateType getState();

/**
* TODO
*/
@NotNull Collection<String> getMatchingEventMarks();
@Nullable Map<String, MarkType> getEventMarksMap();

default boolean isAddition() {
return getState() == ObjectProcessingStateType.ADDED;
}
/**
* Returns the state of the object before the operation.
*
* @see SimulationResultProcessedObjectType#getBefore()
*/
O getBefore();

default boolean isModification() {
return getState() == ObjectProcessingStateType.MODIFIED;
}
/**
* Returns the (expected) state of the object after the operation.
*
* @see SimulationResultProcessedObjectType#getAfter()
*/
O getAfter();

default boolean isDeletion() {
return getState() == ObjectProcessingStateType.DELETED;
}
/**
* Returns the operation that is to be executed.
*
* @see SimulationResultProcessedObjectType#getDelta()
*/
@Nullable ObjectDelta<O> getDelta();

default boolean isNoChange() {
return getState() == ObjectProcessingStateType.UNMODIFIED;
default O getAfterOrBefore() {
return MiscUtil.getFirstNonNull(getAfter(), getBefore());
}

void setEventMarksMap(Map<String, MarkType> eventMarksMap);
O getBefore();
O getAfter();
@Nullable ObjectDelta<O> getDelta();
O getAfterOrBefore();

boolean matches(@NotNull SimulationObjectPredicateType predicate, @NotNull Task task, @NotNull OperationResult result)
throws CommonException;
/** For diagnostic purposes. */
@VisibleForTesting
void resolveEventMarks(OperationResult result);

@VisibleForTesting
boolean hasEventMark(@NotNull String eventMarkOid);

@VisibleForTesting
boolean hasNoEventMarks();
@Nullable String getResourceOid();

default @NotNull Collection<ProcessedObjectItemDelta<?,?>> getItemDeltas() {
return getItemDeltas(null, null, true);
}
/** For processed objects that are shadows: returns the related resource OID. */
@VisibleForTesting
@Nullable String getResourceOid();

/**
* Returns the collection of (augmented) item deltas related to this "processed object".
*
* Limited! We are not able to see inside deltas. So, for example, when looking for `activation/administrativeStatus`
* property, and the whole `activation` container is added, the delta is not shown.
*
* See the implementation and {@link ItemDeltaFilter} for details. Experimental.
*
* @param pathsToInclude paths of items that we want to see in the list of deltas
* @param pathsToExclude paths of items that we do not want to see in the list of deltas
* @param includeOperationalItems should the operational items be included in the list of deltas?
*/
@NotNull Collection<ProcessedObjectItemDelta<?,?>> getItemDeltas(
@Nullable Object pathsToInclude, @Nullable Object pathsToExclude, @Nullable Boolean includeOperationalItems);
void applyDefinitions(Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectNotFoundException;

/**
* Applies the definitions (currently, resource schema related to specific shadow) to the object(s) before/after,
* and the delta.
*/
void applyDefinitions(@NotNull Task task, @NotNull OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException,
ObjectNotFoundException;

/**
* {@link ItemDelta} augmented with functionality needed to display it in a complex way, for example,
* with the information on real change(s) to the object.
*
* Highly experimental, and currently not very sound. For example, the {@link #getRealValuesAfter()} or
* {@link #getRealValuesModified()} may return values modified not by this delta. (Like when having `assignment`
* ADD/DELETE delta accompanied with a couple of `assignment/[1]/activation/...` deltas.)
*/
@SuppressWarnings("unused") // used by the reports
@Experimental
interface ProcessedObjectItemDelta<V extends PrismValue, D extends ItemDefinition<?>> extends ItemDelta<V, D> {
/** Real values of the corresponding item before execution of this delta. */
@NotNull Collection<?> getRealValuesBefore();
/** Prism values of the corresponding item before execution of this delta. */
@NotNull Set<? extends PrismValue> getPrismValuesBefore();
/** Real values of the corresponding item after execution of this delta; beware - may contain results of related deltas */
@NotNull Collection<?> getRealValuesAfter();
/** Prism values of the corresponding item after execution of this delta; beware - may contain results of related deltas */
@NotNull Set<? extends PrismValue> getPrismValuesAfter();
/** Real values added by this delta. (Phantom ones are filtered out.) */
@NotNull Collection<?> getRealValuesAdded();
/** Real values deleted by this delta. (Phantom ones are filtered out.) */
@NotNull Collection<?> getRealValuesDeleted();
/** Real values modified by this delta - their identity is known by PCV ID. */
@NotNull Set<?> getRealValuesModified();
/** Real values unchanged by this delta. */
@NotNull Collection<?> getRealValuesUnchanged();
/** All values (added, deleted, modified) with the corresponding state. Modified values returned only for REPLACE deltas. */
@NotNull Collection<ValueWithState> getValuesWithStates();
/** The state of the assignment pointed to by the delta of `assignment/[nn]/...` kind. */
@Nullable AssignmentType getRelatedAssignment();
}

/** Value touched by a delta, along with their processing {@link State}. */
@Experimental
class ValueWithState implements Serializable {

/** We hope this object is serializable, as it originated in a delta (which is serializable). */
@NotNull private final Object value;

@NotNull private final State state;

public ValueWithState(@NotNull Object value, @NotNull State state) {
Expand All @@ -125,11 +207,4 @@ public enum State {
UNCHANGED, ADDED, DELETED, MODIFIED
}
}

interface Factory {
<O extends ObjectType> ProcessedObject<O> create(
@Nullable O stateBefore,
@Nullable ObjectDelta<O> simulatedDelta,
@NotNull Collection<String> eventMarks) throws SchemaException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

package com.evolveum.midpoint.model.impl.simulation;

import com.evolveum.midpoint.model.api.simulation.ProcessedObject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.model.common.ModelCommonBeans;
import com.evolveum.midpoint.model.impl.lens.LensElementContext;
import com.evolveum.midpoint.prism.ItemDefinition;
Expand All @@ -26,13 +32,6 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Computes metrics for (individual) processed object.
*
Expand All @@ -46,14 +45,14 @@ class ObjectMetricsComputation<O extends ObjectType> {

@NotNull private final ModelCommonBeans beans = ModelCommonBeans.get();

@NotNull private final ProcessedObject<O> processedObject;
@NotNull private final ProcessedObjectImpl<O> processedObject;
@NotNull private final LensElementContext<O> elementContext;
@NotNull private final SimulationResultImpl simulationResult;
@NotNull private final Collection<SimulationMetricDefinitionType> metricDefinitions;
@NotNull private final Task task;

private ObjectMetricsComputation(
@NotNull ProcessedObject<O> processedObject,
@NotNull ProcessedObjectImpl<O> processedObject,
@NotNull LensElementContext<O> elementContext,
@NotNull SimulationResultImpl simulationResult,
@NotNull Collection<SimulationMetricDefinitionType> metricDefinitions,
Expand All @@ -66,7 +65,7 @@ private ObjectMetricsComputation(
}

static <O extends ObjectType> List<SimulationProcessedObjectMetricValueType> computeAll(
ProcessedObject<O> processedObject,
ProcessedObjectImpl<O> processedObject,
LensElementContext<O> elementContext,
SimulationResultImpl simulationResult,
Collection<SimulationMetricDefinitionType> metricDefinitions,
Expand Down

0 comments on commit 94a5912

Please sign in to comment.