in library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/ddb/Ddb2JsonInputType.java [86:146]
public void convert(Exchange exchange) {
if (exchange.getMessage().getHeaders().containsKey(Ddb2Constants.ITEM) ||
exchange.getMessage().getHeaders().containsKey(Ddb2Constants.KEY)) {
return;
}
JsonNode jsonBody = getBodyAsJsonNode(exchange);
String operation
= Optional.ofNullable(jsonBody.get("operation")).map(JsonNode::asText).orElse(Ddb2Operations.PutItem.name());
if (exchange.hasProperties() && exchange.getProperty("operation", String.class) != null) {
operation = exchange.getProperty("operation", String.class);
}
if (exchange.getIn().getHeaders().containsKey(Ddb2Constants.OPERATION)) {
operation = exchange.getIn().getHeader(Ddb2Constants.OPERATION, Ddb2Operations.class).name();
}
JsonNode key = jsonBody.get("key");
JsonNode item = jsonBody.get("item");
Map<String, Object> keyProps;
if (key != null) {
keyProps = dataFormat.getObjectMapper().convertValue(key, new TypeReference<Map<String, Object>>() {
});
} else {
keyProps = dataFormat.getObjectMapper().convertValue(jsonBody, new TypeReference<Map<String, Object>>() {
});
}
Map<String, Object> itemProps;
if (item != null) {
itemProps = dataFormat.getObjectMapper().convertValue(item, new TypeReference<Map<String, Object>>() {
});
} else {
itemProps = keyProps;
}
final Map<String, AttributeValue> keyMap = getAttributeValueMap(keyProps);
switch (Ddb2Operations.valueOf(operation)) {
case PutItem:
exchange.getMessage().setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem);
exchange.getMessage().setHeader(Ddb2Constants.ITEM, getAttributeValueMap(itemProps));
setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_OLD.toString(), exchange);
break;
case UpdateItem:
exchange.getMessage().setHeader(Ddb2Constants.OPERATION, Ddb2Operations.UpdateItem);
exchange.getMessage().setHeader(Ddb2Constants.KEY, keyMap);
exchange.getMessage().setHeader(Ddb2Constants.UPDATE_VALUES, getAttributeValueUpdateMap(itemProps));
setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_NEW.toString(), exchange);
break;
case DeleteItem:
exchange.getMessage().setHeader(Ddb2Constants.OPERATION, Ddb2Operations.DeleteItem);
exchange.getMessage().setHeader(Ddb2Constants.KEY, keyMap);
setHeaderIfNotPresent(Ddb2Constants.RETURN_VALUES, ReturnValue.ALL_OLD.toString(), exchange);
break;
default:
throw new UnsupportedOperationException(String.format("Unsupported operation '%s'", operation));
}
}