davsclaus commented on code in PR #29744:
URL: https://github.com/apache/camel/pull/29744#discussion_r4556631430
##########
components/camel-openfga/src/main/java/org/apache/camel/component/openfga/OpenFgaProducer.java:
##########
@@ -700,6 +723,49 @@ private static String stringValue(Map<?, ?> map, String
key) {
return value != null ? value.toString().trim() : null;
}
+ /**
+ * Builds the relationship condition a write should carry from the way the
body expressed it: an SDK
+ * {@link ClientRelationshipCondition} as is, or a {@code Map} of {@code
name} and {@code context} - the shape
+ * {@link #readTuples} and {@link #readChanges} project a stored condition
as, so a route can feed one straight
+ * back. A body with no condition keeps writing an unconditioned tuple.
+ */
+ private static ClientRelationshipCondition toCondition(Object raw) {
+ if (raw == null) {
+ return null;
+ }
+ if (raw instanceof ClientRelationshipCondition condition) {
+ return condition;
+ }
+ if (raw instanceof Map<?, ?> map) {
+ String name = stringValue(map, "name");
+ if (ObjectHelper.isEmpty(name)) {
+ throw new IllegalArgumentException(
+ "A relationship tuple condition must name a condition,
but the condition entry had no name");
+ }
+ ClientRelationshipCondition condition = new
ClientRelationshipCondition().name(name);
+ Object context = map.get("context");
+ if (context != null) {
+ condition.context(context);
+ }
+ return condition;
+ }
+ throw new IllegalArgumentException(
+ "A relationship tuple condition must be a Map with name and
context entries or a"
+ + " ClientRelationshipCondition,
but was " + raw.getClass().getName());
+ }
+
+ /**
+ * Projects a stored condition the server returned as a {@code Map} of
{@code name} and {@code context}, mirroring
+ * how {@code operation} is projected as a {@code String} rather than an
SDK type, so the read body marshals without
+ * a custom serializer and a route can round-trip it back into a write.
+ */
+ private static Map<String, Object> conditionAsMap(RelationshipCondition
condition) {
+ Map<String, Object> projected = new LinkedHashMap<>();
+ projected.put("name", condition.getName());
+ projected.put("context", condition.getContext());
Review Comment:
Not blocking: `conditionAsMap` is the read-side projection, and a condition
without a context is valid in OpenFGA (context is optional). `context: null` in
the map says exactly that, and it round-trips into a write as a condition with
no context. `operation` is projected the same way, null included.
_Claude Code on behalf of davsclaus_
##########
components/camel-openfga/src/main/java/org/apache/camel/component/openfga/OpenFgaProducer.java:
##########
@@ -586,7 +598,13 @@ private static void setContinuationToken(Exchange
exchange, String token) {
private void writeTuples(Exchange exchange, OpenFgaAuthorizer authorizer)
throws Exception {
List<ClientTupleKey> tuples = new ArrayList<>();
for (Tuple tuple : resolveTuples(exchange, authorizer)) {
- tuples.add(new
ClientTupleKey().user(tuple.user).relation(tuple.relation)._object(tuple.object));
+ ClientTupleKey key = new
ClientTupleKey().user(tuple.user).relation(tuple.relation)._object(tuple.object);
+ if (tuple.condition != null) {
+ // carry the relationship condition the input set; rebuilding
the tuple from its three identity parts
Review Comment:
A wording nit in a code comment ("carry the relationship condition the input
set" is missing a "from"). Not blocking; it can be fixed in a later commit.
_Claude Code on behalf of davsclaus_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]