Open
Conversation
Comment on lines
+30
to
+63
| public Engagement(String jsonConfig, Logger logger) { | ||
| if (jsonConfig == null || logger == null) { | ||
| throw new IllegalArgumentException("Neither jsonConfig nor logger can be null"); | ||
| } | ||
|
|
||
| try { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| EngagementConfig config = mapper.readValue(jsonConfig, EngagementConfig.class); | ||
| this.settings = createSettingsFromConfig(config); | ||
| this.logger = logger; | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Failed to parse engagement configuration: " + e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| // Constructor that accepts any object and logger | ||
| public Engagement(Object configObject, Logger logger) { | ||
| if (configObject == null || logger == null) { | ||
| throw new IllegalArgumentException("Neither configObject nor logger can be null"); | ||
| } | ||
|
|
||
| try { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| // First convert the object to a JSON string | ||
| String jsonString = mapper.writeValueAsString(configObject); | ||
| // Then convert it to our EngagementConfig class | ||
| EngagementConfig config = mapper.readValue(jsonString, EngagementConfig.class); | ||
|
|
||
| this.settings = createSettingsFromConfig(config); | ||
| this.logger = logger; | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Failed to convert object to engagement configuration: " + e.getMessage(), e); | ||
| } | ||
| } |
There was a problem hiding this comment.
Both constructors for Engagement (one taking a JSON string, one taking an object) repeat the same logic for mapping to EngagementConfig, creating settings, and assigning logger. Would it be more concise to extract the shared logic into a private method, reducing duplication and making future changes easier?
Suggested change
| public Engagement(String jsonConfig, Logger logger) { | |
| if (jsonConfig == null || logger == null) { | |
| throw new IllegalArgumentException("Neither jsonConfig nor logger can be null"); | |
| } | |
| try { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| EngagementConfig config = mapper.readValue(jsonConfig, EngagementConfig.class); | |
| this.settings = createSettingsFromConfig(config); | |
| this.logger = logger; | |
| } catch (IOException e) { | |
| throw new RuntimeException("Failed to parse engagement configuration: " + e.getMessage(), e); | |
| } | |
| } | |
| // Constructor that accepts any object and logger | |
| public Engagement(Object configObject, Logger logger) { | |
| if (configObject == null || logger == null) { | |
| throw new IllegalArgumentException("Neither configObject nor logger can be null"); | |
| } | |
| try { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| // First convert the object to a JSON string | |
| String jsonString = mapper.writeValueAsString(configObject); | |
| // Then convert it to our EngagementConfig class | |
| EngagementConfig config = mapper.readValue(jsonString, EngagementConfig.class); | |
| this.settings = createSettingsFromConfig(config); | |
| this.logger = logger; | |
| } catch (IOException e) { | |
| throw new RuntimeException("Failed to convert object to engagement configuration: " + e.getMessage(), e); | |
| } | |
| } | |
| // Constructor that accepts JSON string and logger | |
| public Engagement(String jsonConfig, Logger logger) { | |
| if (jsonConfig == null || logger == null) { | |
| throw new IllegalArgumentException("Neither jsonConfig nor logger can be null"); | |
| } | |
| try { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| EngagementConfig config = mapper.readValue(jsonConfig, EngagementConfig.class); | |
| initializeFromConfig(config, logger); | |
| } catch (IOException e) { | |
| throw new RuntimeException("Failed to parse engagement configuration: " + e.getMessage(), e); | |
| } | |
| } | |
| // Constructor that accepts any object and logger | |
| public Engagement(Object configObject, Logger logger) { | |
| if (configObject == null || logger == null) { | |
| throw new IllegalArgumentException("Neither configObject nor logger can be null"); | |
| } | |
| try { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| // First convert the object to a JSON string | |
| String jsonString = mapper.writeValueAsString(configObject); | |
| // Then convert it to our EngagementConfig class | |
| EngagementConfig config = mapper.readValue(jsonString, EngagementConfig.class); | |
| initializeFromConfig(config, logger); | |
| } catch (IOException e) { | |
| throw new RuntimeException("Failed to convert object to engagement configuration: " + e.getMessage(), e); | |
| } | |
| } | |
| // Helper method to initialize from config | |
| private void initializeFromConfig(EngagementConfig config, Logger logger) { | |
| this.settings = createSettingsFromConfig(config); | |
| this.logger = logger; | |
| } |
Finding type: Conciseness
Comment on lines
+28
to
+30
| DataFileStream<GenericRecord> dataFileReader = null; | ||
| try { | ||
| dataFileReader = engagement.getCustomerBatchById(batchNumber); |
There was a problem hiding this comment.
The DataFileStream is no longer in a try-with-resources block. This could lead to resource leaks if exceptions occur before the stream is properly closed.
Suggested change
| DataFileStream<GenericRecord> dataFileReader = null; | |
| try { | |
| dataFileReader = engagement.getCustomerBatchById(batchNumber); | |
| try (DataFileStream<GenericRecord> dataFileReader = engagement.getCustomerBatchById(batchNumber)) { |
Finding type: Logical Bugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated description
Below is a concise technical summary of the changes proposed in this PR:
graph LR main_("main"):::modified Engagement_Engagement_("Engagement.Engagement"):::added Engagement_getMetadata_("Engagement.getMetadata"):::modified StorageSingleton_getBlob_("StorageSingleton.getBlob"):::modified StorageSingleton_getInstance_("StorageSingleton.getInstance"):::modified getNumberOfBatches_("getNumberOfBatches"):::added main_ -- "Replaced constructor with JSON config for flexible initialization" --> Engagement_Engagement_ main_ -- "Fetches metadata blob using decryption key for security" --> Engagement_getMetadata_ Engagement_getMetadata_ -- "Added decryption key parameter to securely fetch blob" --> StorageSingleton_getBlob_ StorageSingleton_getBlob_ -- "Removed project ID setting in storage instance creation" --> StorageSingleton_getInstance_ main_ -- "Renamed method to reflect batch processing semantics" --> getNumberOfBatches_ classDef added stroke:#15AA7A classDef removed stroke:#CD5270 classDef modified stroke:#EDAC4C linkStyle default stroke:#CBD5E1,font-size:13pxIntroduce a new JSON-based configuration mechanism for the
EngagementSDK, allowing for more flexible initialization of theEngagementcomponent by parsing configuration details from a JSON string or object. Integrate the decryption key directly into Google Cloud Storage blob retrieval operations, enhancing secure data access, and update internal terminology from "files" to "batches" for clarity.Metadatamethods and example code.Modified files (4)
Latest Contributors(0)
Engagementclass that accept a JSON string or an object to configure the SDK, leveraging the newEngagementConfigclass for structured configuration, and pass the decryption key directly toStorageSingletonfor secure Google Cloud Storage blob retrieval.Modified files (7)
Latest Contributors(0)