gnodet-bot commented on code in PR #29744:
URL: https://github.com/apache/camel/pull/29744#discussion_r4554215751
##########
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:
⚠️ **Potential issue:** `conditionAsMap` unconditionally adds the
`"context"` key even when `condition.getContext()` returns `null`. Depending on
the OpenFGA server's behaviour when deserialising a `null` context, this could
produce unexpected results. Consider omitting the key when the context is
absent:
```suggestion
projected.put("name", condition.getName());
if (condition.getContext() != null) {
projected.put("context", condition.getContext());
}
```
##########
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:
📝 **Nit:** The comment reads *"carry the relationship condition the input
set"* — it appears to be missing a preposition, e.g. *"carry the relationship
condition **from** the input set"* or *"carry the relationship condition
**into** the input set"*, depending on the intended meaning.
--
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]