davsclaus commented on code in PR #28353:
URL: https://github.com/apache/camel/pull/28353#discussion_r4366220287
##########
components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java:
##########
@@ -670,6 +677,63 @@ public static Message getMessageForResponse(final Exchange
exchange) {
return exchange.getMessage();
}
+ /**
+ * The instance type of the {@link AWS2EC2Constants#INSTANCE_TYPE} header:
an {@link InstanceType}, its AWS value
+ * (such as t2.micro), or the name of the constant (such as T2_MICRO).
+ */
+ private InstanceType getInstanceType(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE);
+ if (value instanceof InstanceType instanceType) {
+ return instanceType;
+ }
+ String text =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, String.class);
+ if (text != null) {
+ text = text.trim();
+ InstanceType instanceType = InstanceType.fromValue(text);
+ if (instanceType != null && instanceType !=
InstanceType.UNKNOWN_TO_SDK_VERSION) {
+ return instanceType;
+ }
+ for (InstanceType candidate : InstanceType.knownValues()) {
+ if (candidate.name().equals(text)) {
+ return candidate;
+ }
+ }
+ }
+ throw new IllegalArgumentException(
+ "Unknown instance type " + value + " in the " +
AWS2EC2Constants.INSTANCE_TYPE
+ + " header: expected an
InstanceType, such as t2.micro or T2_MICRO");
+ }
+
+ /**
+ * The instance ids of the {@link AWS2EC2Constants#INSTANCES_IDS} header:
a Collection of ids, or a String of ids
+ * separated by commas. Returns null when the header is not set.
+ */
+ private Collection<String> getInstanceIds(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS);
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof Collection<?> collection) {
+ List<String> ids = new ArrayList<>(collection.size());
+ for (Object id : collection) {
+ ids.add(id != null ? id.toString() : null);
Review Comment:
Already fixed in 5ffecf575cc8 (pushed after this review): null ids in the
list are skipped.
_Claude Code on behalf of davsclaus_
##########
components/camel-aws/camel-aws2-transcribe/src/main/java/org/apache/camel/component/aws2/transcribe/Transcribe2Producer.java:
##########
@@ -917,6 +910,32 @@ private void applyIfPresent(Exchange exchange, String
header, Consumer<String> s
}
}
+ /**
+ * Reads the phrases (or words of a vocabulary filter) header as a list of
strings. A single String is taken as a
+ * list of one phrase.
+ */
+ private List<String> getPhrases(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(Transcribe2Constants.VOCABULARY_PHRASES);
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof String phrase) {
+ return phrase.isBlank() ? null : List.of(phrase);
+ }
+ if (value instanceof Collection<?> collection) {
+ List<String> phrases = new ArrayList<>(collection.size());
+ for (Object phrase : collection) {
+ if (phrase != null) {
+ phrases.add(phrase.toString());
+ }
+ }
+ return phrases;
+ }
+ throw new IllegalArgumentException(
+ "The " + Transcribe2Constants.VOCABULARY_PHRASES + " header
must be a List<String> or a String, was: "
+ + value.getClass().getName());
Review Comment:
That layout is what the project's formatter (`mvn formatter:format`)
produces for this concatenation, and CI checks the formatting, so I left it.
_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]