Skip to content

Commit 00bbdda

Browse files
author
Philip Z
committed
fix: integrate mutation policy with current runtime boundaries
Refs #196
1 parent 5c5bc61 commit 00bbdda

8 files changed

Lines changed: 41 additions & 15 deletions

File tree

‎teaql-runtime/src/main/java/io/teaql/runtime/LogPrivacy.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public static RawAuditEvent audit(RawAuditEvent source, boolean allow) {
202202
if (source.entityId() != null) intentValues.add(source.entityId());
203203
return new RawAuditEvent(source.kind(), source.entityType(), source.entityId(), changes,
204204
trace(source.traceChain(), intentValues), scrub(source.actor(), intentValues), source.category(),
205-
scrub(source.reason(), intentValues), source.resultingVersion(), source.occurredAt());
205+
scrub(source.reason(), intentValues), source.resultingVersion(), source.occurredAt(),
206+
source.governance());
206207
}
207208
}

‎teaql-runtime/src/main/java/io/teaql/runtime/RawAuditEvent.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,19 @@ public record RawAuditEvent(
2222
traceChain = List.copyOf(traceChain == null ? List.of() : traceChain);
2323
occurredAt = occurredAt == null ? Instant.now() : occurredAt;
2424
}
25+
26+
public RawAuditEvent(
27+
MutationAuditKind kind,
28+
String entityType,
29+
Object entityId,
30+
List<AuditFieldChange> changes,
31+
List<TraceNode> traceChain,
32+
String actor,
33+
String category,
34+
String reason,
35+
Long resultingVersion,
36+
Instant occurredAt) {
37+
this(kind, entityType, entityId, changes, traceChain, actor, category, reason,
38+
resultingVersion, occurredAt, null);
39+
}
2540
}

‎teaql-runtime/src/main/java/io/teaql/runtime/TeaQLRuntime.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,24 +246,24 @@ public <T extends Entity> Stream<T> executeForStream(
246246
throw new TeaQLRuntimeException(
247247
"[PURPOSE REQUIRED] Missing .purpose() on streaming query execution.");
248248
}
249-
if (requestPolicy != null) {
250-
requestPolicy.enforceSelect(context, request);
249+
if (queryPolicy != null) {
250+
queryPolicy.enforceSelect(context, request);
251251
}
252252
return executeForStreamResolved(context, request);
253253
}
254254

255255
/**
256256
* Executes a framework-owned nested stream under an already-authorized root query. The
257-
* nested request still passes through RequestPolicy before reaching the provider.
257+
* nested request still passes through QueryPolicy before reaching the provider.
258258
*/
259259
public <T extends Entity> Stream<T> internalExecuteForStream(
260260
UserContext context, SearchRequest<T> request) {
261261
if (context.getTraceChain() == null || context.getTraceChain().isEmpty()) {
262262
throw new TeaQLRuntimeException(
263263
"[INTERNAL QUERY CONTEXT REQUIRED] Nested streaming query has no authorized root trace.");
264264
}
265-
if (requestPolicy != null) {
266-
requestPolicy.enforceSelect(context, request);
265+
if (queryPolicy != null) {
266+
queryPolicy.enforceSelect(context, request);
267267
}
268268
return executeForStreamResolved(context, request);
269269
}

‎teaql-runtime/src/main/java/io/teaql/runtime/mutation/MutationPlanner.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.teaql.core.meta.EntityDescriptor;
55
import io.teaql.core.meta.EntityMetaFactory;
66
import io.teaql.core.meta.PropertyDescriptor;
7-
import io.teaql.runtime.DefaultMutationRequest;
7+
import io.teaql.runtime.EntityPersistenceMutation;
88

99
import java.util.*;
1010

@@ -152,8 +152,8 @@ void executeLedgerPlan(UserContext ctx, EntityMutationLedger root, MutationExecu
152152
deleteEntity.markForDeletion();
153153
if (root.getComment() != null) deleteEntity.setComment(root.getComment());
154154

155-
DefaultMutationRequest mutationRequest = new DefaultMutationRequest(
156-
deleteEntity, DefaultMutationRequest.Action.DELETE);
155+
EntityPersistenceMutation mutationRequest = new EntityPersistenceMutation(
156+
deleteEntity, EntityPersistenceMutation.Action.DELETE);
157157
mutationExecutor.mutate(ctx, mutationRequest);
158158
}
159159

@@ -175,17 +175,17 @@ void executeLedgerPlan(UserContext ctx, EntityMutationLedger root, MutationExecu
175175

176176
// 3. Execute Inserts
177177
executeBatchMutations(ctx, insertBatches, changeSet, realEntities, root, mutationExecutor,
178-
DefaultMutationRequest.Action.SAVE, false);
178+
EntityPersistenceMutation.Action.SAVE, false);
179179

180180
// 4. Execute Updates
181181
executeBatchMutations(ctx, updateBatches, changeSet, realEntities, root, mutationExecutor,
182-
DefaultMutationRequest.Action.SAVE, true);
182+
EntityPersistenceMutation.Action.SAVE, true);
183183
}
184184

185185
private void executeBatchMutations(UserContext ctx, Map<String, List<EntityKey>> batches,
186186
EntityChangeSet changeSet, Map<EntityKey, BaseEntity> realEntities,
187187
EntityMutationLedger root, MutationExecutor mutationExecutor,
188-
DefaultMutationRequest.Action action, boolean markAsUpdated) {
188+
EntityPersistenceMutation.Action action, boolean markAsUpdated) {
189189
for (Map.Entry<String, List<EntityKey>> entry : batches.entrySet()) {
190190
String entityName = entry.getKey();
191191
List<EntityKey> keys = entry.getValue();
@@ -213,7 +213,7 @@ private void executeBatchMutations(UserContext ctx, Map<String, List<EntityKey>>
213213
}
214214
if (root.getComment() != null) entity.setComment(root.getComment());
215215

216-
DefaultMutationRequest mutationRequest = new DefaultMutationRequest(entity, action);
216+
EntityPersistenceMutation mutationRequest = new EntityPersistenceMutation(entity, action);
217217
mutationExecutor.mutate(ctx, mutationRequest);
218218
entity.clearUpdatedProperties();
219219
}

‎teaql-runtime/src/test/java/io/teaql/runtime/TeaQLRuntimeTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public void streamingExecutionAppliesRequestPolicyBeforeProvider() {
603603
TeaQLRuntime runtime = TeaQLRuntime.builder()
604604
.metadata(new DummyMetaFactory())
605605
.dataService("dummy", executor)
606-
.requestPolicy(new RequestPolicy() {
606+
.queryPolicy(new QueryPolicy() {
607607
@Override public void enforceSelect(
608608
UserContext context, SearchRequest<?> query) {
609609
policyCalls.incrementAndGet();
@@ -636,7 +636,7 @@ public void internalStreamingRequiresAuthorizedRootAndAppliesRequestPolicy() {
636636
TeaQLRuntime runtime = TeaQLRuntime.builder()
637637
.metadata(new DummyMetaFactory())
638638
.dataService("dummy", executor)
639-
.requestPolicy(new RequestPolicy() {
639+
.queryPolicy(new QueryPolicy() {
640640
@Override public void enforceSelect(
641641
UserContext context, SearchRequest<?> query) {
642642
policyCalls.incrementAndGet();

‎teaql-tfp-endpoint/src/test/java/io/teaql/tfp/TfpConformanceServer.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private static Map<String, String> headers(HttpExchange exchange) {
8787
private static UserContext createContext() {
8888
EntityDescriptor descriptor = new EntityDescriptor();
8989
descriptor.setType("CustomerOrder"); descriptor.setTargetType(CustomerOrder.class);
90+
descriptor.withEntitySupplier(CustomerOrder::new);
9091
descriptor.addSimpleProperty("status", String.class);
9192
descriptor.addSimpleProperty("orderNumber", String.class);
9293
descriptor.addSimpleProperty("tenantId", Long.class);

‎teaql-tfp-endpoint/src/test/java/io/teaql/tfp/TfpEndpointPolicyTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public void isolatesTopLevelFacetAndMutationMetadataByInvokingContext() throws E
216216
EntityDescriptor probe = new EntityDescriptor();
217217
probe.setType("Probe");
218218
probe.setTargetType(AlternateProbe.class);
219+
probe.withEntitySupplier(AlternateProbe::new);
219220
probe.addSimpleProperty("id", Long.class);
220221
probe.addSimpleProperty("status", String.class);
221222
alternate.register(probe);
@@ -347,6 +348,13 @@ public static final class AlternateProbe extends BaseEntity {
347348
public String typeName() { return "Probe"; }
348349
public String getStatus() { return status; }
349350
public void setStatus(String value) { status = value; }
351+
@Override public void __internalSet(String property, Object value) {
352+
if ("status".equals(property)) status = (String) value;
353+
else super.__internalSet(property, value);
354+
}
355+
@Override public Object __internalGet(String property) {
356+
return "status".equals(property) ? status : super.__internalGet(property);
357+
}
350358
}
351359
public static final class AlternateProbeStatus extends BaseEntity {
352360
public String typeName() { return "ProbeStatus"; }

‎teaql-tfp-endpoint/src/test/java/io/teaql/tfp/TfpEndpointTelemetryTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void registerMetadata() {
4141
EntityDescriptor descriptor = new EntityDescriptor();
4242
descriptor.setType("Probe");
4343
descriptor.setTargetType(Probe.class);
44+
descriptor.withEntitySupplier(Probe::new);
4445
metadata.register(descriptor);
4546
EntityMetaFactory.registerGlobal(null);
4647
context = new DefaultUserContext(TeaQLRuntime.builder()

0 commit comments

Comments
 (0)