-
Notifications
You must be signed in to change notification settings - Fork 641
[ISSUE #4099]Refactor re-used constant's usage from dedicated file #4257
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
Conversation
| import io.cloudevents.SpecVersion; | ||
| import io.cloudevents.core.builder.CloudEventBuilder; | ||
|
|
||
| import static org.apache.eventmesh.storage.mongodb.constant.MongodbConstants.*; |
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.
checkstyle doesn't seem to support '. *' import.
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.
Thanks for the feedback,
Updated in my last commit.
| 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"; |
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.
| 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.
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.
Thanks for the feedback. Implement in latest commit.
| 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; |
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.
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.
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.
Thanks for clarifying again. Will definitely use this pattern in future for appropriate scenarios.
And implemented your feedback in the last commit.
…o cloud event util
Pil0tXia
left a comment
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.
LGTM
Codecov Report
@@ 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
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
mxsm
left a comment
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.
LGTM
…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
* 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]>
…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
* 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]>
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