Skip to content

Commit

Permalink
MID-8979: Prepare storage and setting of Kind/Intent for audit
Browse files Browse the repository at this point in the history
  - Added support for setting kind/intent to ObjectDeltaOperation
  - Added Draft repository code for Kind/Intent
  • Loading branch information
tonydamage committed Aug 22, 2023
1 parent f32ae88 commit 93c7329
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public static ObjectDeltaOperation<?> createObjectDeltaOperation(ObjectDeltaOper
if (odoBean.getResourceName() != null) {
odo.setObjectName(odoBean.getResourceName().toPolyString());
}
odo.setShadowIntent(odoBean.getShadowIntent());
odo.setShadowKind(odoBean.getShadowKind());
return odo;
}

Expand Down Expand Up @@ -313,6 +315,8 @@ public static void toObjectDeltaOperationType(ObjectDeltaOperation<?> odo, Objec
if (odo.getResourceName() != null) {
odoBean.setResourceName(new PolyStringType(odo.getResourceName()));
}
odoBean.setShadowKind(odo.getShadowKind());
odoBean.setShadowIntent(odo.getShadowIntent());
}

private static ChangeTypeType convertChangeType(ChangeType changeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import com.evolveum.midpoint.util.MiscUtil;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -41,6 +43,9 @@ public class ObjectDeltaOperation<O extends ObjectType> implements DebugDumpable
private String resourceOid;
private PolyString resourceName;

private ShadowKindType shadowKind;
private String shadowIntent;

public ObjectDeltaOperation() {
super();
}
Expand Down Expand Up @@ -118,6 +123,8 @@ protected void copyToClone(ObjectDeltaOperation<O> clone) {
clone.objectName = this.objectName;
clone.resourceOid = this.resourceOid;
clone.resourceName = this.resourceName;
clone.shadowIntent = this.shadowIntent;
clone.shadowKind = this.shadowKind;
}

public static void checkConsistence(Collection<? extends ObjectDeltaOperation<?>> deltas) {
Expand Down Expand Up @@ -359,4 +366,20 @@ public boolean wasReallyExecuted() {
public String getOid() {
return objectDelta != null ? objectDelta.getOid() : null;
}

public void setShadowKind(ShadowKindType kind) {
this.shadowKind = kind;
}

public void setShadowIntent(String intent) {
this.shadowIntent = intent;
}

public ShadowKindType getShadowKind() {
return this.shadowKind;
}

public String getShadowIntent() {
return shadowIntent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17866,6 +17866,21 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="shadowKind" type="tns:ShadowKindType">
<xsd:annotation>
<xsd:documentation>
Shadow kind of the shadow, that is related to this operation.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="shadowIntent" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Shadow kind of the shadow, that is related to this operation.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ private ObjectDeltaOperation<? extends ObjectType> prepareObjectDeltaOperation(O
ShadowType shadow = (ShadowType) objectToDetermineDetailsForAudit;
odoToAudit.setResourceOid(ShadowUtil.getResourceOid(shadow));
odoToAudit.setResourceName(ShadowUtil.getResourceName(shadow));
odoToAudit.setShadowKind(ShadowUtil.getKind(shadow));
odoToAudit.setShadowIntent(ShadowUtil.getIntent(shadow));
}
}
return odoToAudit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,19 @@ public static <T extends ObjectType> LensObjectDeltaOperation<T> createObjectDel
if (resource == null && projCtx != null) {
resource = projCtx.getResource();
}

if (resource != null) {
objectDeltaOp.setResourceOid(resource.getOid());
objectDeltaOp.setResourceName(PolyString.toPolyString(resource.getName()));
} else if (objectContext instanceof LensProjectionContext) {
objectDeltaOp.setResourceOid(((LensProjectionContext) objectContext).getResourceOid());
if (object.asObjectable() instanceof ShadowType shadow) {
objectDeltaOp.setShadowKind(shadow.getKind());
objectDeltaOp.setShadowIntent(shadow.getIntent());
}
} else if (objectContext instanceof LensProjectionContext ctx) {

objectDeltaOp.setResourceOid(ctx.getResourceOid());
objectDeltaOp.setShadowKind(ctx.getKind());
objectDeltaOp.setShadowIntent(ctx.getKey().getIntent());
}
return objectDeltaOp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ private <F extends ObjectType> LensObjectDeltaOperation<F> simplifyOperation(Obj
rv.setObjectName(operation.getObjectName());
rv.setResourceName(operation.getResourceName());
rv.setResourceOid(operation.getResourceOid());
rv.setShadowIntent(operation.getShadowIntent());
rv.setShadowKind(operation.getShadowKind());
return rv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ private Collection<MAuditDelta> prepareDeltas(Collection<ObjectDeltaOperation<?>
deltaRow.resourceNameOrig = deltaOperation.getResourceName().getOrig();
deltaRow.resourceNameNorm = deltaOperation.getResourceName().getNorm();
}
deltaRow.shadowKind = deltaOperation.getShadowKind();
deltaRow.shadowIntent = deltaOperation.getShadowIntent();

deltaRow.checksum = computeChecksum(deltaRow.delta, fullResultForCheckSum);
return deltaRow;
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType;

/**
Expand All @@ -32,6 +33,10 @@ public class MAuditDelta {
public UUID resourceOid;
public String resourceNameNorm;
public String resourceNameOrig;

public ShadowKindType shadowKind;
public String shadowIntent;

public OperationResultStatusType status;

// "transient" fields not used by Querydsl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import static com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType.*;

/**
* Mapping between {@link QAuditDelta} and {@link ObjectDeltaOperationType}.
*/
Expand All @@ -48,6 +50,11 @@ public static QAuditDeltaMapping get() {
private QAuditDeltaMapping(@NotNull SqaleRepoContext repositoryContext) {
super(TABLE_NAME, DEFAULT_ALIAS_NAME,
ObjectDeltaOperationType.class, QAuditDelta.class, repositoryContext);
// FIXME: Add mappers
addItemMapping(F_RESOURCE_OID);
addItemMapping(F_SHADOW_INTENT);
addItemMapping(F_SHADOW_KIND);

}

@Override
Expand All @@ -71,6 +78,8 @@ public ObjectDeltaOperationType toSchemaObject(MAuditDelta row) {
odo.setResourceName(new PolyStringType(
new PolyString(row.resourceNameOrig, row.resourceNameNorm)));
}
odo.setShadowKind(row.shadowKind);
odo.setShadowIntent(row.shadowIntent);

return odo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.*;
import java.util.function.Function;

import com.evolveum.midpoint.repo.sqlbase.mapping.TableRelationResolver;

import com.google.common.collect.Table;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.dsl.ArrayPath;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -114,6 +117,9 @@ private QAuditEventRecordMapping(@NotNull SqaleRepoContext repositoryContext) {
ctx -> new AuditPropertiesItemFilterProcessor(ctx, q -> q.properties)));

addItemMapping(F_CUSTOM_COLUMN_PROPERTY, AuditCustomColumnItemFilterProcessor.mapper());

addRelationResolver(F_DELTA,
TableRelationResolver.usingJoin(QAuditDeltaMapping::get, (r,d) -> r.id.eq(d.recordId)));
}

@Override
Expand Down

0 comments on commit 93c7329

Please sign in to comment.