[ISSUE #4099]Refactor re-used constant's usage from dedicated file#4257
[ISSUE #4099]Refactor re-used constant's usage from dedicated file#4257xwm1992 merged 4 commits intoapache:masterfrom
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.
checkstyle doesn't seem to support '. *' import.
There was a problem hiding this comment.
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.
| 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.
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.
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.
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
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 |
…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 <fabian.bao@agfa.com> Co-authored-by: kyooosukedn <87076947+kyooosukedn@users.noreply.github.com> Co-authored-by: Sam V Jose <124816912+devCod3r@users.noreply.github.com> Co-authored-by: ruhshan <ruhshan.ahmed@gmail.com>
…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 <fabian.bao@agfa.com> Co-authored-by: kyooosukedn <87076947+kyooosukedn@users.noreply.github.com> Co-authored-by: Sam V Jose <124816912+devCod3r@users.noreply.github.com> Co-authored-by: ruhshan <ruhshan.ahmed@gmail.com>
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