Skip to content

Conversation

@Ruhshan
Copy link
Contributor

@Ruhshan Ruhshan commented Jul 20, 2023

Fixes #4099.

Motivation

Mentioned file in the issue has some constants that are being used in two different methods. Refactoring was needed to ensure consistency.

Modifications

Added the constants in separate file and used as import in the file of interest.

Documentation

  • Does this pull request introduce a new feature? ( no)
  • If yes, how is the feature documented? (not applicable )
  • If a feature is not applicable for documentation, explain why? (it's a refactoring)
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

import io.cloudevents.SpecVersion;
import io.cloudevents.core.builder.CloudEventBuilder;

import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkstyle doesn't seem to support '. *' import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback,

Updated in my last commit.

Comment on lines 27 to 33
public static final String DOC_KEY_VERSION = "version";
public static final String DOC_KEY_DATA = "data";
public static final String DOC_KEY_ID = "id";
public static final String DOC_KEY_SOURCE = "source";
public static final String DOC_KEY_TYPE = "type";
public static final String DOC_KEY_DATA_CONTENT_TYPE = "datacontenttype";
public static final String DOC_KEY_SUBJECT = "subject";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static final String DOC_KEY_VERSION = "version";
public static final String DOC_KEY_DATA = "data";
public static final String DOC_KEY_ID = "id";
public static final String DOC_KEY_SOURCE = "source";
public static final String DOC_KEY_TYPE = "type";
public static final String DOC_KEY_DATA_CONTENT_TYPE = "datacontenttype";
public static final String DOC_KEY_SUBJECT = "subject";
public static final String CLOUD_EVENT_DOC_VERSION = "version";
public static final String CLOUD_EVENT_DOC_DATA = "data";
public static final String CLOUD_EVENT_DOC_ID = "id";
public static final String CLOUD_EVENT_DOC_SOURCE = "source";
public static final String CLOUD_EVENT_DOC_TYPE = "type";
public static final String CLOUD_EVENT_DOC_DATACONTENTTYPE = "datacontenttype";
public static final String CLOUD_EVENT_DOC_SUBJECT = "subject";

There is no need to add KEY_ in the middle of constants. Considering their usage in both convertToCloudEvent and convertToDocument methods, the suggested naming is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Implement in latest commit.

@Ruhshan Ruhshan requested review from Alonexc and Pil0tXia July 21, 2023 13:58
Comment on lines 32 to 38
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_DATA;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_DATACONTENTTYPE;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_ID;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_SOURCE;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_SUBJECT;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_TYPE;
import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.CLOUD_EVENT_DOC_VERSION;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest importing the MongodbConstants class only and using Constants.NAME to refer to the constant, which has the advantage of explicitness. Anyone reading the code can immediately understand that the constant NAME comes from the MongodbConstants class. This can reduce cognitive overhead and prevent confusion with constants of the same prefix in other classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying again. Will definitely use this pattern in future for appropriate scenarios.

And implemented your feedback in the last commit.

@Ruhshan Ruhshan requested a review from Pil0tXia July 21, 2023 18:22
Copy link
Member

@Pil0tXia Pil0tXia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov
Copy link

codecov bot commented Jul 22, 2023

Codecov Report

Merging #4257 (6f1add9) into master (4b994b0) will increase coverage by 0.10%.
The diff coverage is 70.00%.

❗ Current head 6f1add9 differs from pull request most recent head 3eb4d00. Consider uploading reports for the commit 3eb4d00 to get more accurate results

@@             Coverage Diff              @@
##             master    #4257      +/-   ##
============================================
+ Coverage     16.75%   16.86%   +0.10%     
- Complexity     1415     1426      +11     
============================================
  Files           592      593       +1     
  Lines         26029    26073      +44     
  Branches       2384     2401      +17     
============================================
+ Hits           4362     4398      +36     
- Misses        21230    21234       +4     
- Partials        437      441       +4     
Impacted Files Coverage Δ
...he/eventmesh/runtime/boot/EventMeshHTTPServer.java 0.52% <0.00%> (ø)
.../protocol/http/processor/CreateTopicProcessor.java 0.00% <0.00%> (ø)
.../protocol/http/processor/DeleteTopicProcessor.java 0.00% <0.00%> (ø)
...col/http/processor/QuerySubscriptionProcessor.java 0.00% <0.00%> (ø)
...ache/eventmesh/runtime/util/HttpResponseUtils.java 23.07% <0.00%> (+1.64%) ⬆️
...apache/eventmesh/runtime/util/ValueComparator.java 25.00% <ø> (ø)
...nt/tcp/impl/cloudevent/CloudEventTCPPubClient.java 6.06% <ø> (ø)
...nt/tcp/impl/cloudevent/CloudEventTCPSubClient.java 5.88% <ø> (ø)
...esh/storage/mongodb/constant/MongodbConstants.java 0.00% <ø> (ø)
...h/registry/nacos/service/NacosRegistryService.java 49.29% <74.28%> (+5.54%) ⬆️
... and 2 more

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@mxsm mxsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xwm1992 xwm1992 changed the title [ISSUE #4099]: Refactor re-used constant's usage from dedicated file [ISSUE #4099]Refactor re-used constant's usage from dedicated file Jul 25, 2023
@xwm1992 xwm1992 merged commit 984eacc into apache:master Jul 25, 2023
fabian4 pushed a commit to fabian4/eventmesh that referenced this pull request Jul 25, 2023
…ile (apache#4257)

* [ISSUE apache#4099]: Refactor re-used constant's usage from dedicated file

* [ISSUE apache#4099] Rename some constants for mongodb storage plugin

* [ISSUE apache#4099] Refactor constant imports in mongodb cloud event util

* [ISSUE apache#4099]: Replace contants imports to class import in mongo cloud event util
xwm1992 pushed a commit that referenced this pull request Jul 27, 2023
* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* [ISSUE #4023]Comparison using reference equality instead of value equality.[Operation] (#4276)

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

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE #4099]Refactor re-used constant's usage from dedicated file (#4257)

* [ISSUE #4099]: Refactor re-used constant's usage from dedicated file

* [ISSUE #4099] Rename some constants for mongodb storage plugin

* [ISSUE #4099] Refactor constant imports in mongodb cloud event util

* [ISSUE #4099]: Replace contants imports to class import in mongo cloud event util

* fix import order.

* fix import order.

* fix import order.

* fix import order.

---------

Co-authored-by: Fabian Bao <[email protected]>
Co-authored-by: kyooosukedn <[email protected]>
Co-authored-by: Sam V Jose <[email protected]>
Co-authored-by: ruhshan <[email protected]>
xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
…ile (apache#4257)

* [ISSUE apache#4099]: Refactor re-used constant's usage from dedicated file

* [ISSUE apache#4099] Rename some constants for mongodb storage plugin

* [ISSUE apache#4099] Refactor constant imports in mongodb cloud event util

* [ISSUE apache#4099]: Replace contants imports to class import in mongo cloud event util
xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* feat: add redis connector.

* [ISSUE apache#4023]Comparison using reference equality instead of value equality.[Operation] (apache#4276)

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor] (apache#4270)

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4269] Used switch to replace the if-else. [MeshMessageProtocolAdaptor]

* [ISSUE apache#4099]Refactor re-used constant's usage from dedicated file (apache#4257)

* [ISSUE apache#4099]: Refactor re-used constant's usage from dedicated file

* [ISSUE apache#4099] Rename some constants for mongodb storage plugin

* [ISSUE apache#4099] Refactor constant imports in mongodb cloud event util

* [ISSUE apache#4099]: Replace contants imports to class import in mongo cloud event util

* fix import order.

* fix import order.

* fix import order.

* fix import order.

---------

Co-authored-by: Fabian Bao <[email protected]>
Co-authored-by: kyooosukedn <[email protected]>
Co-authored-by: Sam V Jose <[email protected]>
Co-authored-by: ruhshan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Extracts re-used constants.

5 participants