You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "devCod3r (via GitHub)" <gi...@apache.org> on 2023/07/21 09:49:47 UTC

[PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

devCod3r opened a new pull request, #4270:
URL: https://github.com/apache/eventmesh/pull/4270

   <!--
   ### Contribution Checklist
   
     - Name the pull request in the form "[ISSUE #XXXX] Title of the pull request", 
       where *XXXX* should be replaced by the actual issue number.
       Skip *[ISSUE #XXXX]* if there is no associated github issue for this pull request.
   
     - Fill out the template below to describe the changes contributed by the pull request. 
       That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue. 
       Please do not mix up code from multiple issues.
     
     - Each commit in the pull request should have a meaningful commit message.
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, 
       leaving only the filled out template below.
   
   (The sections below can be removed for hotfixes of typos)
   -->
   
   <!--
   (If this PR fixes a GitHub issue, please add `Fixes #<XXX>` or `Closes #<XXX>`.)
   -->
   
   Fixes #4269
   
   ### Motivation
   
   Replaced the if-else conditions with switch cases.
   ISSUE #4269 
   
   
   
   ### Modifications
   
   *Describe the modifications you've done.*
   Replaced the if-else conditions with switch cases.
   
   
   ### Documentation
   
   - Does this pull request introduce a new feature? 
   - Ans: no
   - If a feature is not applicable for documentation, explain why?
   - Ans: Replaced the if-else conditions with switch cases.
   


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270950834


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   Like this:
   ```java
   map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT,
           new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET));
   ```
   Because `new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET)` is the second argument of `map.put`.
   
   `Put` method doesn't have three arguments; it's the original line breaks that make it look like it has three arguments .



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270950834


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   Like this:
   ```java
   map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT,
           new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET));
   ```
   Because `new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET)` is the second param of `map.put`.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270898530


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();

Review Comment:
   Reverted back the changes (Removed few white spaces).



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270661358


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +108,32 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8));

Review Comment:
    StandardCharsets.UTF_8 replace with  Constants.DEFAULT_CHARSET



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#issuecomment-1645735413

   ## [Codecov](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#4270](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (14b1cf8) into [master](https://app.codecov.io/gh/apache/eventmesh/commit/6c94d9deb1b24af946fa3ae3e92beaead72f5ffc?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (6c94d9d) will **decrease** coverage by `0.01%`.
   > The diff coverage is `0.00%`.
   
   > :exclamation: Current head 14b1cf8 differs from pull request most recent head 3732f92. Consider uploading reports for the commit 3732f92 to get more accurate results
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #4270      +/-   ##
   ============================================
   - Coverage     16.86%   16.86%   -0.01%     
     Complexity     1426     1426              
   ============================================
     Files           593      593              
     Lines         26073    26064       -9     
     Branches       2401     2382      -19     
   ============================================
   - Hits           4398     4395       -3     
   + Misses        21234    21229       -5     
   + Partials        441      440       -1     
   ```
   
   
   | [Impacted Files](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...otocol/meshmessage/MeshMessageProtocolAdaptor.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXByb3RvY29sLXBsdWdpbi9ldmVudG1lc2gtcHJvdG9jb2wtbWVzaG1lc3NhZ2Uvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9wcm90b2NvbC9tZXNobWVzc2FnZS9NZXNoTWVzc2FnZVByb3RvY29sQWRhcHRvci5qYXZh) | `4.34% <0.00%> (+0.42%)` | :arrow_up: |
   | [...he/eventmesh/runtime/boot/EventMeshHTTPServer.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2Jvb3QvRXZlbnRNZXNoSFRUUFNlcnZlci5qYXZh) | `0.52% <0.00%> (ø)` | |
   | [.../protocol/http/processor/CreateTopicProcessor.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvaHR0cC9wcm9jZXNzb3IvQ3JlYXRlVG9waWNQcm9jZXNzb3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [.../protocol/http/processor/DeleteTopicProcessor.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvaHR0cC9wcm9jZXNzb3IvRGVsZXRlVG9waWNQcm9jZXNzb3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...col/http/processor/QuerySubscriptionProcessor.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvaHR0cC9wcm9jZXNzb3IvUXVlcnlTdWJzY3JpcHRpb25Qcm9jZXNzb3IuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...nt/tcp/impl/cloudevent/CloudEventTCPPubClient.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXNka3MvZXZlbnRtZXNoLXNkay1qYXZhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY2xpZW50L3RjcC9pbXBsL2Nsb3VkZXZlbnQvQ2xvdWRFdmVudFRDUFB1YkNsaWVudC5qYXZh) | `6.06% <ø> (ø)` | |
   | [...nt/tcp/impl/cloudevent/CloudEventTCPSubClient.java](https://app.codecov.io/gh/apache/eventmesh/pull/4270?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXNka3MvZXZlbnRtZXNoLXNkay1qYXZhL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY2xpZW50L3RjcC9pbXBsL2Nsb3VkZXZlbnQvQ2xvdWRFdmVudFRDUFN1YkNsaWVudC5qYXZh) | `5.88% <ø> (ø)` | |
   
   ... and [7 files with indirect coverage changes](https://app.codecov.io/gh/apache/eventmesh/pull/4270/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270897135


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   The second argument is on the same line but when I tried to put all the 3 arguments in the same line, I got the warning as shown below:
   <img width="320" alt="image" src="https://github.com/apache/eventmesh/assets/124816912/acd33f5d-66eb-4e58-ac9b-dbe86cfece39">
   



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270899105


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -77,19 +75,20 @@ private CloudEvent deserializeTcpProtocol(Header header, String bodyJson) throws
     }
 
     private CloudEvent deserializeHttpProtocol(String requestCode,
-        org.apache.eventmesh.common.protocol.http.header.Header header,
-        Body body) throws ProtocolHandleException {
-
-        if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
+                                               org.apache.eventmesh.common.protocol.http.header.Header header,
+                                               Body body) throws ProtocolHandleException {
+
+        switch (RequestCode.valueOf(requestCode)) {
+            case MSG_BATCH_SEND:
+                return SendMessageBatchProtocolResolver.buildEvent(header, body);
+            case MSG_BATCH_SEND_V2:
+                return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
+            case MSG_SEND_SYNC:
+                return SendMessageRequestProtocolResolver.buildEvent(header, body);

Review Comment:
   Merged both the Cases.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1271435183


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   I have put the whole second argument in the next line as suggested, thank you for the info :)



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270836771


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -77,19 +75,20 @@ private CloudEvent deserializeTcpProtocol(Header header, String bodyJson) throws
     }
 
     private CloudEvent deserializeHttpProtocol(String requestCode,
-        org.apache.eventmesh.common.protocol.http.header.Header header,
-        Body body) throws ProtocolHandleException {
-
-        if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
+                                               org.apache.eventmesh.common.protocol.http.header.Header header,
+                                               Body body) throws ProtocolHandleException {
+
+        switch (RequestCode.valueOf(requestCode)) {
+            case MSG_BATCH_SEND:
+                return SendMessageBatchProtocolResolver.buildEvent(header, body);
+            case MSG_BATCH_SEND_V2:
+                return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
+            case MSG_SEND_SYNC:
+                return SendMessageRequestProtocolResolver.buildEvent(header, body);

Review Comment:
   Line 87 is redundant.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270884281


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   For this line CheckStyle gave me a warning saying there are more words in the same line, and the line needs to be separated.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "devCod3r (via GitHub)" <gi...@apache.org>.
devCod3r commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270884281


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   For this line CheckStyle gave me a warning saying there are more words in the same line, and the line needs to be separated.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "xwm1992 (via GitHub)" <gi...@apache.org>.
xwm1992 merged PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270950834


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   Like this:
   ```java
   map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT,
                  new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET));
   ```
   Because `new String(cloudEvent.getData().toBytes(), Constants.DEFAULT_CHARSET)` is the second param of `map.put`.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#discussion_r1270836771


##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -77,19 +75,20 @@ private CloudEvent deserializeTcpProtocol(Header header, String bodyJson) throws
     }
 
     private CloudEvent deserializeHttpProtocol(String requestCode,
-        org.apache.eventmesh.common.protocol.http.header.Header header,
-        Body body) throws ProtocolHandleException {
-
-        if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
+                                               org.apache.eventmesh.common.protocol.http.header.Header header,
+                                               Body body) throws ProtocolHandleException {
+
+        switch (RequestCode.valueOf(requestCode)) {
+            case MSG_BATCH_SEND:
+                return SendMessageBatchProtocolResolver.buildEvent(header, body);
+            case MSG_BATCH_SEND_V2:
+                return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
+            case MSG_SEND_SYNC:
+                return SendMessageRequestProtocolResolver.buildEvent(header, body);

Review Comment:
   This line is redundant.



##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();

Review Comment:
   No change needs to be made in this line.



##########
eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java:
##########
@@ -108,31 +107,33 @@ public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) thro
     public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
         validateCloudEvent(cloudEvent);
         String protocolDesc =
-            cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
-
-        if (StringUtils.equals(MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP, protocolDesc)) {
-            HttpCommand httpCommand = new HttpCommand();
-            Body body = new Body() {
-                final Map<String, Object> map = new HashMap<>();
-
-                @Override
-                public Map<String, Object> toMap() {
-                    if (cloudEvent.getData() == null) {
+                cloudEvent.getExtension(Constants.PROTOCOL_DESC) == null ? null : cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
+
+        switch (Objects.requireNonNull(protocolDesc)) {
+            case MeshMessageProtocolConstant.PROTOCOL_DESC_HTTP:
+                HttpCommand httpCommand = new HttpCommand();
+                Body body = new Body() {
+                    final Map<String, Object> map = new HashMap<>();
+
+                    @Override
+                    public Map<String, Object> toMap() {
+                        if (cloudEvent.getData() == null) {
+                            return map;
+                        }
+                        map.put(MeshMessageProtocolConstant.PROTOCOL_KEY_CONTENT, new String(cloudEvent.getData().toBytes(),
+                                Constants.DEFAULT_CHARSET));

Review Comment:
   Consider putting the second argument on the same line.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (eventmesh)

Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on PR #4270:
URL: https://github.com/apache/eventmesh/pull/4270#issuecomment-1646373181

   @devCod3r import code style , https://eventmesh.apache.org/community/contribute/contribute


-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org