-
Notifications
You must be signed in to change notification settings - Fork 0
AB#238930 #19
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
base: dev
Are you sure you want to change the base?
AB#238930 #19
Conversation
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
| 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
| DataFileStream<GenericRecord> dataFileReader = null; | ||
| try { | ||
| dataFileReader = engagement.getCustomerBatchById(batchNumber); |
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.
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.
| DataFileStream<GenericRecord> dataFileReader = null; | |
| try { | |
| dataFileReader = engagement.getCustomerBatchById(batchNumber); | |
| try (DataFileStream<GenericRecord> dataFileReader = engagement.getCustomerBatchById(batchNumber)) { |
Finding type: Logical Bugs
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)