-
Notifications
You must be signed in to change notification settings - Fork 5.2k
CAMEL-24373: Refactor camel-alibaba-eventbridge constants, headers and #25552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
82639d7
c8c2de0
ad9a973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import com.google.gson.Gson; | ||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.component.alibaba.common.OpenApiClientSupport; | ||
| import org.apache.camel.component.alibaba.eventbridge.constants.AlibabaEventBridgeConstants; | ||
| import org.apache.camel.component.alibaba.eventbridge.constants.AlibabaEventBridgeProperties; | ||
| import org.apache.camel.component.alibaba.eventbridge.models.ClientConfigurations; | ||
| import org.apache.camel.util.ObjectHelper; | ||
|
|
@@ -99,11 +100,13 @@ private static CloudEvent toCloudEvent(Object body, ClientConfigurations configu | |
| } | ||
|
|
||
| if (body instanceof Map<?, ?> mapBody) { | ||
| String eventBusName = stringValue(mapBody.get("eventBusName"), configuration.getEventBusName()); | ||
| String source = stringValue(mapBody.get("source"), configuration.getEventSource()); | ||
| String type = stringValue(mapBody.get("type"), configuration.getEventType()); | ||
| String subject = stringValue(mapBody.get("subject"), configuration.getEventSubject()); | ||
| String data = jsonDataValue(mapBody.get("data")); | ||
| String eventBusName | ||
| = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_BUS_NAME), configuration.getEventBusName()); | ||
| String source = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SOURCE), configuration.getEventSource()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Map body keys renamed — document this Previous Map keys were CloudEvents-short ( |
||
| String type = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_TYPE), configuration.getEventType()); | ||
| String subject | ||
| = stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SUBJECT), configuration.getEventSubject()); | ||
| String data = jsonDataValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_DATA)); | ||
|
|
||
| if (ObjectHelper.isEmpty(source) || ObjectHelper.isEmpty(type) || ObjectHelper.isEmpty(eventBusName)) { | ||
| throw new IllegalArgumentException("Event source, type and event bus name are required"); | ||
|
|
@@ -174,20 +177,21 @@ private static String jsonDataValue(Object value) { | |
|
|
||
| public static Map<String, Object> toPutEventsMap(PutEventsResponse response) { | ||
| Map<String, Object> map = new HashMap<>(); | ||
| map.put("requestId", response.getRequestId()); | ||
| map.put("resourceOwnerAccountId", response.getResourceOwnerAccountId()); | ||
| map.put("failedEntryCount", response.getFailedEntryCount()); | ||
| map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_REQUEST_IDENTIFIER, response.getRequestId()); | ||
| map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_RESOURCE_OWNER_ACCOUNT_IDENTIFIER, | ||
| response.getResourceOwnerAccountId()); | ||
| map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_FAILED_ENTRY_COUNT, response.getFailedEntryCount()); | ||
|
|
||
| if (response.getEntryList() != null) { | ||
| List<Map<String, Object>> entries = new ArrayList<>(); | ||
| for (PutEventsResponseEntry entry : response.getEntryList()) { | ||
| Map<String, Object> entryMap = new HashMap<>(); | ||
| entryMap.put("eventId", entry.getEventId()); | ||
| entryMap.put("errorCode", entry.getErrorCode()); | ||
| entryMap.put("errorMessage", entry.getErrorMessage()); | ||
| entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ID, entry.getEventId()); | ||
| entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ERROR_CODE, entry.getErrorCode()); | ||
| entryMap.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ERROR_MESSAGE, entry.getErrorMessage()); | ||
| entries.add(entryMap); | ||
| } | ||
| map.put("entryList", entries); | ||
| map.put(AlibabaEventBridgeConstants.EVENT_RESPONSE_ENTRY_LIST, entries); | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.alibaba.eventbridge.constants; | ||
|
|
||
| /** | ||
| * Constants for Alibaba EventBridge payload and response dictionary keys. | ||
| */ | ||
| public final class AlibabaEventBridgeConstants { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved — plain constants, no incorrect @metadata Good follow-up: payload and response dictionary keys are now plain |
||
|
|
||
| public static final String EVENT_BUS_NAME = "eventBusName"; | ||
| public static final String EVENT_SOURCE = "eventSource"; | ||
| public static final String EVENT_TYPE = "eventType"; | ||
| public static final String EVENT_SUBJECT = "eventSubject"; | ||
| public static final String EVENT_DATA = "eventData"; | ||
|
|
||
| public static final String EVENT_RESPONSE_REQUEST_IDENTIFIER = "requestId"; | ||
| public static final String EVENT_RESPONSE_RESOURCE_OWNER_ACCOUNT_IDENTIFIER = "resourceOwnerAccountId"; | ||
| public static final String EVENT_RESPONSE_FAILED_ENTRY_COUNT = "failedEntryCount"; | ||
| public static final String EVENT_RESPONSE_ID = "eventId"; | ||
| public static final String EVENT_RESPONSE_ERROR_CODE = "errorCode"; | ||
| public static final String EVENT_RESPONSE_ERROR_MESSAGE = "errorMessage"; | ||
| public static final String EVENT_RESPONSE_ENTRY_LIST = "entryList"; | ||
|
|
||
| private AlibabaEventBridgeConstants() { | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,23 +18,23 @@ | |
|
|
||
| import org.apache.camel.spi.Metadata; | ||
|
|
||
| public final class AlibabaEventBridgeHeaders { | ||
| public sealed class AlibabaEventBridgeHeaders permits AlibabaEventBridgeProperties { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sealed hierarchy — consider consistency Sealed |
||
|
|
||
| @Metadata(label = "producer", description = "Event bus name override", javaType = "String") | ||
| public static final String EVENT_BUS_NAME = AlibabaEventBridgeProperties.EVENT_BUS_NAME; | ||
| public static final String EVENT_BUS_NAME = "CamelAlibabaEventBridgeEventBusName"; | ||
|
|
||
| @Metadata(label = "producer", description = "Event source override", javaType = "String") | ||
| public static final String EVENT_SOURCE = AlibabaEventBridgeProperties.EVENT_SOURCE; | ||
| public static final String EVENT_SOURCE = "CamelAlibabaEventBridgeEventSource"; | ||
|
|
||
| @Metadata(label = "producer", description = "Event type override", javaType = "String") | ||
| public static final String EVENT_TYPE = AlibabaEventBridgeProperties.EVENT_TYPE; | ||
| public static final String EVENT_TYPE = "CamelAlibabaEventBridgeEventType"; | ||
|
|
||
| @Metadata(label = "producer", description = "Event subject override", javaType = "String") | ||
| public static final String EVENT_SUBJECT = AlibabaEventBridgeProperties.EVENT_SUBJECT; | ||
| public static final String EVENT_SUBJECT = "CamelAlibabaEventBridgeEventSubject"; | ||
|
|
||
| @Metadata(label = "producer", description = "Alibaba Cloud request id", javaType = "String") | ||
| public static final String REQUEST_ID = AlibabaEventBridgeProperties.REQUEST_ID; | ||
| public static final String REQUEST_ID = "CamelAlibabaEventBridgeRequestId"; | ||
|
|
||
| private AlibabaEventBridgeHeaders() { | ||
| AlibabaEventBridgeHeaders() { | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved — Map body schema documented
Input Map keys, response metadata structure, and String/JSON + Map + multi-event examples are all documented. Prior concern about the
source→eventSourcerename is mitigated since this is a Preview 4.23 component not yet released.