Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
* 'master' of github.com:Evolveum/midpoint:
  Add structural archetype OID metric dimension
  Replace artificial IDs with native ones for POs
  Block provisioning changes for simulation tasks
  • Loading branch information
katkav committed Feb 2, 2023
2 parents d5cfad9 + 8c4cf88 commit 2ac9d3a
Show file tree
Hide file tree
Showing 27 changed files with 412 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@
public class PartitionScope {

private final QName objectType;
private final String structuralArchetypeOid;
private final String resourceOid;
private final ShadowKindType kind;
private final String intent;
private final Set<QName> allDimensions;

public PartitionScope(QName objectType, String resourceOid, ShadowKindType kind, String intent, Set<QName> allDimensions) {
public PartitionScope(
QName objectType,
String structuralArchetypeOid,
String resourceOid,
ShadowKindType kind,
String intent,
Set<QName> allDimensions) {
this.objectType = objectType;
this.structuralArchetypeOid = structuralArchetypeOid;
this.resourceOid = resourceOid;
this.kind = kind;
this.intent = intent;
Expand All @@ -45,10 +53,12 @@ public PartitionScope(QName objectType, String resourceOid, ShadowKindType kind,

public static PartitionScope fromBean(SimulationMetricPartitionScopeType scope, Set<QName> availableDimensions) {
if (scope == null) {
return new PartitionScope(null, null, null, null, availableDimensions);
return new PartitionScope(
null, null, null, null, null, availableDimensions);
} else {
return new PartitionScope(
ifAvailable(scope.getTypeName(), availableDimensions, F_TYPE_NAME),
ifAvailable(scope.getStructuralArchetypeOid(), availableDimensions, F_STRUCTURAL_ARCHETYPE_OID),
ifAvailable(scope.getResourceOid(), availableDimensions, F_RESOURCE_OID),
ifAvailable(scope.getKind(), availableDimensions, F_KIND),
ifAvailable(scope.getIntent(), availableDimensions, F_INTENT),
Expand Down Expand Up @@ -76,6 +86,7 @@ public boolean equals(Object o) {
}
PartitionScope that = (PartitionScope) o;
return Objects.equals(objectType, that.objectType)
&& Objects.equals(structuralArchetypeOid, that.structuralArchetypeOid)
&& Objects.equals(resourceOid, that.resourceOid)
&& kind == that.kind
&& Objects.equals(intent, that.intent)
Expand All @@ -84,19 +95,23 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(objectType, resourceOid, kind, intent);
return Objects.hash(objectType, structuralArchetypeOid, resourceOid, kind, intent);
}

public SimulationMetricPartitionScopeType toBean() {
SimulationMetricPartitionScopeType bean = new SimulationMetricPartitionScopeType()
.typeName(objectType)
.structuralArchetypeOid(structuralArchetypeOid)
.resourceOid(resourceOid)
.kind(kind)
.intent(intent);
List<QName> nullDimensions = bean.getNullDimensions();
if (objectType == null && allDimensions.contains(F_TYPE_NAME)) {
nullDimensions.add(F_TYPE_NAME);
}
if (structuralArchetypeOid == null && allDimensions.contains(F_STRUCTURAL_ARCHETYPE_OID)) {
nullDimensions.add(F_STRUCTURAL_ARCHETYPE_OID);
}
if (resourceOid == null && allDimensions.contains(F_RESOURCE_OID)) {
nullDimensions.add(F_RESOURCE_OID);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

public class ObjectReferenceTypeUtil {

public static String getTargetNameOrOid(ObjectReferenceType ref) {
if (ref == null) {
return null;
}
PolyStringType targetName = ref.getTargetName();
if (targetName != null) {
String orig = targetName.getOrig();
if (orig != null) {
return orig;
}
}
return ref.getOid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static Set<QName> getDimensions(@Nullable SimulationMetricPartitionScopeT
if (scope.getTypeName() != null) {
dimensions.add(SimulationMetricPartitionScopeType.F_TYPE_NAME);
}
if (scope.getStructuralArchetypeOid() != null) {
dimensions.add(SimulationMetricPartitionScopeType.F_STRUCTURAL_ARCHETYPE_OID);
}
if (scope.getResourceOid() != null) {
dimensions.add(SimulationMetricPartitionScopeType.F_RESOURCE_OID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class SimulationMetricPartitionTypeUtil {

public static final Set<QName> ALL_DIMENSIONS = Set.of(
SimulationMetricPartitionScopeType.F_TYPE_NAME,
SimulationMetricPartitionScopeType.F_STRUCTURAL_ARCHETYPE_OID,
SimulationMetricPartitionScopeType.F_RESOURCE_OID,
SimulationMetricPartitionScopeType.F_KIND,
SimulationMetricPartitionScopeType.F_INTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="structuralArchetypeOid" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Value of the "structural archetype OID" dimension. Applies only to focus objects.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="resourceOid" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -926,17 +933,6 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="identifier" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Identifier of this "processed object" record.

EXPERIMENTAL
TODO Should it be generated by the repository? Probably so.
TODO Should it be named "identifier" or "recordId" or ... ?
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="transactionId" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -964,6 +960,17 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="structuralArchetypeRef" type="tns:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Structural archetype of the object processed. Applies only to focal objects (assignment holders).
</xsd:documentation>
<xsd:appinfo>
<a:displayName>SimulationResultProcessedObjectType.structuralArchetypeRef</a:displayName>
<a:objectReferenceTargetType>tns:ArchetypeType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="resourceObjectCoordinates" type="tns:ShadowDiscriminatorType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -1033,7 +1040,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="focusRecordId" type="xsd:string" minOccurs="0">
<xsd:element name="focusRecordId" type="xsd:long" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
For projection-related records, this field denotes the focus record ID to which this projection belongs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import java.util.*;

import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.MiscUtil;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -145,6 +148,13 @@ public void setArchetypes(List<ArchetypeType> archetypes) {
this.archetypes = archetypes;
}

/** Precondition: context is "complete" i.e. {@link #archetypes} are filled in. */
public ObjectReferenceType getStructuralArchetypeRef() throws SchemaException {
return ObjectTypeUtil.createObjectRef(
ArchetypeTypeUtil.getStructuralArchetype(
MiscUtil.stateNonNull(archetypes, () -> "Information about archetypes is not present")));
}

public ObjectTemplateType getFocusTemplate() {
return focusTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

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

import static com.evolveum.midpoint.schema.util.ObjectReferenceTypeUtil.getTargetNameOrOid;
import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.asObjectable;
import static com.evolveum.midpoint.schema.util.SimulationMetricPartitionTypeUtil.ALL_DIMENSIONS;
import static com.evolveum.midpoint.util.MiscUtil.argCheck;
import static com.evolveum.midpoint.util.MiscUtil.emptyIfNull;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -65,10 +63,11 @@
@SuppressWarnings("CommentedOutCode")
public class ProcessedObjectImpl<O extends ObjectType> implements ProcessedObject<O> {

private String recordId; // TODO consider removal
private Long recordId;
@NotNull private final String transactionId;
private final String oid; // TODO may be null?
@NotNull private final Class<O> type;
@Nullable private final ObjectReferenceType structuralArchetypeRef;
@NotNull private final QName typeName;
private final ShadowDiscriminatorType shadowDiscriminator;
private final PolyStringType name;
Expand All @@ -83,7 +82,7 @@ public class ProcessedObjectImpl<O extends ObjectType> implements ProcessedObjec

private Integer projectionRecords;

private String focusRecordId;
private Long focusRecordId;

@Nullable private final O before;
@Nullable private final O after;
Expand All @@ -97,12 +96,13 @@ private ProcessedObjectImpl(
@NotNull String transactionId,
String oid,
@NotNull Class<O> type,
@Nullable ObjectReferenceType structuralArchetypeRef,
ShadowDiscriminatorType shadowDiscriminator,
PolyStringType name,
@NotNull ObjectProcessingStateType state,
@NotNull ParsedMetricValues parsedMetricValues,
Boolean focus,
@Nullable String focusRecordId,
@Nullable Long focusRecordId,
@Nullable O before,
@Nullable O after,
@Nullable ObjectDelta<O> delta,
Expand All @@ -111,6 +111,7 @@ private ProcessedObjectImpl(
this.oid = oid;
this.type = type;
this.typeName = ObjectTypes.getObjectType(type).getTypeQName();
this.structuralArchetypeRef = structuralArchetypeRef;
this.shadowDiscriminator = shadowDiscriminator;
this.name = name;
this.state = state;
Expand All @@ -133,6 +134,7 @@ public static <O extends ObjectType> ProcessedObjectImpl<O> parse(@NotNull Simul
bean.getTransactionId(),
bean.getOid(),
(Class<O>) type,
bean.getStructuralArchetypeRef(),
bean.getResourceObjectCoordinates(),
bean.getName(),
MiscUtil.argNonNull(bean.getState(), () -> "No processing state in " + bean),
Expand All @@ -143,7 +145,7 @@ public static <O extends ObjectType> ProcessedObjectImpl<O> parse(@NotNull Simul
(O) bean.getAfter(),
DeltaConvertor.createObjectDeltaNullable(bean.getDelta()),
InternalState.PARSED);
obj.setRecordId(bean.getIdentifier());
obj.setRecordId(bean.getId());
obj.setFocusRecordId(bean.getFocusRecordId());
obj.setProjectionRecords(bean.getProjectionRecords());
return obj;
Expand Down Expand Up @@ -199,6 +201,8 @@ private void addComputedMetricValues(@NotNull List<SimulationProcessedObjectMetr
simulationTransaction.getTransactionId(),
elementContext.getOid(),
type,
elementContext instanceof LensFocusContext<?> ?
((LensFocusContext<?>) elementContext).getStructuralArchetypeRef() : null,
determineShadowDiscriminator(anyState),
anyState.getName(),
delta != null ?
Expand Down Expand Up @@ -239,11 +243,11 @@ private static <O extends ObjectType> ShadowDiscriminatorType determineShadowDis
.objectClassName(shadow.getObjectClass());
}

String getRecordId() {
Long getRecordId() {
return recordId;
}

void setRecordId(String recordId) {
private void setRecordId(Long recordId) {
this.recordId = recordId;
invalidateCachedBean();
}
Expand All @@ -262,6 +266,10 @@ public String getOid() {
return typeName;
}

private @Nullable String getStructuralArchetypeOid() {
return Referencable.getOid(structuralArchetypeRef);
}

public String getResourceOid() {
return shadowDiscriminator != null ?
Referencable.getOid(shadowDiscriminator.getResourceRef()) : null;
Expand Down Expand Up @@ -313,7 +321,7 @@ private void invalidateCachedBean() {
this.cachedBean = null;
}

void setFocusRecordId(String focusRecordId) {
void setFocusRecordId(Long focusRecordId) {
this.focusRecordId = focusRecordId;
invalidateCachedBean();
}
Expand Down Expand Up @@ -342,11 +350,11 @@ public SimulationResultProcessedObjectType toBean() {
}
try {
SimulationResultProcessedObjectType bean = new SimulationResultProcessedObjectType()
.identifier(recordId)
.transactionId(transactionId)
.oid(oid)
.type(
PrismContext.get().getSchemaRegistry().determineTypeForClass(type))
.structuralArchetypeRef(structuralArchetypeRef)
.resourceObjectCoordinates(shadowDiscriminator != null ? shadowDiscriminator.clone() : null)
.name(name)
.state(state)
Expand Down Expand Up @@ -393,6 +401,9 @@ private ObjectType prepareObjectForStorage(@Nullable O original) {
public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createTitleStringBuilder(getClass(), indent);
sb.append(" of ").append(type.getSimpleName());
if (structuralArchetypeRef != null) {
sb.append("/").append(getTargetNameOrOid(structuralArchetypeRef));
}
sb.append(" ").append(oid);
sb.append(" (").append(name).append("): ");
sb.append(state);
Expand Down Expand Up @@ -575,7 +586,13 @@ public void resolveEventMarks(OperationResult result) {
}

PartitionScope partitionScope() {
return new PartitionScope(getTypeName(), getResourceOid(), getKind(), getIntent(), ALL_DIMENSIONS);
return new PartitionScope(getTypeName(), getStructuralArchetypeOid(), getResourceOid(), getKind(), getIntent(), ALL_DIMENSIONS);
}

void propagateRecordId() {
recordId = Objects.requireNonNull(
cachedBean != null ? cachedBean.getId() : null,
() -> "No cached bean or no ID in it: " + cachedBean);
}

static class ParsedMetricValues implements DebugDumpable {
Expand Down

0 comments on commit 2ac9d3a

Please sign in to comment.