Skip to content

Conversation

rashmiangadi11
Copy link
Collaborator

@rashmiangadi11 rashmiangadi11 commented Sep 23, 2025

Describe your changes

Currently if the repository onboarded is a virus enabled one and if i try to upload a file with size greater than 400 MB it should throw an error but file is getting uploaded successfully because of chunking and this is not the behaviour in application option an error comes up .
Same has been done here, if file size greater than 400MB and virus scan enabled and skipVirusScanForLargeFile is false error is thrown.
If skipVirusScanForLargeFile is set to true and virus scan enabled is true the errr is not thrown file is uploaded as chunks

Any documentation

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I follow Java Development Guidelines for SAP
  • I have tested the functionality on my cloud environment.
  • I have provided sufficient automated/ unit tests for the code.
  • I have increased or maintained the test coverage.
  • I have ran integration tests on my cloud environment.
  • I have validated blackduck portal for any vulnerability after my commit.

Upload Screenshots/lists of the scenarios tested

  • I have Uploaded Screenshots or added lists of the scenarios tested in description
Screenshot 2025-09-23 at 4 30 11 PM

Scenarios tested

  1. Repo is version enabled : Upload not supported for versioned repo's error
    2)Repo is non versioned virus enabled and disableVirusScannerForLargeFile is false : Uploaded file greater than 400 M error message appears
    3)Repo is non versioned virus enabled true and disableVirusScannerForLargeFile is true : Uploaded file greater than 400 M file gets uploaded
    4)Repo is non versioned virus enabled true and disableVirusScannerForLargeFile is false : Uploaded file lesser than 400 MB upload is success
    5)Repo is non versioned virus enabled true and disableVirusScannerForLargeFile is true : Uploaded file lesser than 400 MB upload is success

Copy link
Contributor

Gemini Automated Review
Summary of Changes

This diff introduces significant changes to support virus scanning and versioning capabilities within a document repository. The RepoValue class is added to encapsulate repository metadata, including virus scan status, versioning status, and a large file exception flag. The CacheConfig class is updated to store RepoValue objects. The SDMService and related classes (SDMServiceImpl, SDMAttachmentsServiceHandler, SDMServiceGenericHandler) are modified to handle the new RepoValue object, fetching and using repository metadata appropriately. Unit tests are updated to reflect these changes.

Best Practices Review

  • Inconsistent Formatting: Potential inconsistencies may exist across files (not directly evident in the provided reviews). Thorough code formatting review is recommended.
  • Redundant Dependency (Potential): A full dependency analysis is needed to identify any redundant dependencies introduced.
  • Unused Property (Potential): Review RepoValue and other classes to ensure all properties are actively used.
  • Missing Version in dependency: Verify all external library versions are explicitly specified.
  • Lack of Comments: Insufficient comments in the test suite and potentially other modified classes. Comments describing the purpose and logic are needed.

Potential Bugs

  • SDMServiceImpl.fetchRepositoryData: Inadequate error handling for JSON parsing exceptions and missing/malformed JSON keys.
  • SDMAttachmentsServiceHandler.validateRepository: Missing null and empty checks for the content-length header, potentially leading to NumberFormatException.
  • SDMServiceImpl.fetchRepositoryData: Overly simplistic parsing of the extendedFeatures array, assuming a single element with the expected featureData.
  • Potential issues in production code due to incorrect handling of RepoValue object fields (Requires review of all code using RepoValue).

Recommendations

  • Prioritize Robust Error Handling: Implement comprehensive error handling in SDMServiceImpl.fetchRepositoryData using try-catch blocks to handle IOException, JSONException and NumberFormatException, and provide informative error messages. Add input validation for content-length. (See Code Snippet below).
  • Improve JSON Parsing: Refactor SDMServiceImpl.fetchRepositoryData to use a more robust JSON parsing approach, such as a dedicated JSON library or object mapping, to avoid relying on direct key access.
  • Enhance extendedFeatures Handling: Modify SDMServiceImpl.fetchRepositoryData to handle potential variations in the structure of the extendedFeatures array. Iterate and handle missing keys gracefully.
  • Add Logging: Implement logging in key methods for debugging and monitoring.
  • Add Comprehensive Comments: Add clear and concise comments to explain the purpose of code sections and complex logic.
  • Review Production Code: Thoroughly review all code that utilizes the RepoValue object to ensure correct and consistent handling of its fields. This is crucial given the significant changes to how repository data is represented.

Code Snippet (Improved SDMServiceImpl.fetchRepositoryData):

try {
    JSONObject json = new JSONObject(jsonString); //jsonString is fetched from Repo
    RepoValue repoValue = new RepoValue(
        json.getBoolean("virusScanEnabled"),
        json.getBoolean("versionEnabled"),
        json.getBoolean("disableVirusScannerForLargeFile")
    );
    return repoValue;
} catch (JSONException e) {
    log.error("Error parsing JSON response: {}", e.getMessage(), e);
    throw new RuntimeException("Failed to fetch repository data", e); // Or more specific exception
} catch (NumberFormatException e) {
    log.error("Invalid number format in JSON response: {}", e.getMessage(), e);
    throw new RuntimeException("Invalid repository data format", e);
}

Quality Rating

6/10

Overall

The changes introduce valuable functionality but require further improvements to address potential bugs and best practices violations. The thorough testing in the provided diff is positive, but the potential for issues in production code interacting with the new RepoValue class necessitates a careful review. Addressing the recommendations above, especially the robust error handling, is crucial before merging.

Copy link
Contributor

Gemini Automated Review
Summary of Changes
This commit introduces significant changes to the SDM service to improve repository type handling and virus scanning. It involves refactoring several classes (CacheConfig.java, SDMConstants.java, SDMService.java, SDMServiceImpl.java, SDMAttachmentsServiceHandler.java, SDMServiceGenericHandler.java) and their corresponding unit tests (SDMServiceImplTest.java, SDMAttachmentsServiceHandlerTest.java, SDMServiceGenericHandlerTest.java). Key changes include the introduction of a RepoValue class to encapsulate repository information (including virus scan status and versioning), updates to caching mechanisms, and improved error handling (though further improvements are needed). Test cases have been adjusted to accommodate the changes.

Best Practices Review

  • Inconsistent Error Handling: Error handling is inconsistent, with some areas lacking robustness. Specifically, the fetchRepositoryData method lacks sufficient handling for missing or malformed JSON data.
  • Redundant Dependency (Potential): The review highlights the use of mockStatic for SDMUtils in tests. The necessity of this should be carefully reviewed to avoid unnecessary dependencies.
  • Unused Property (Potential): The versionedRepoCache property in CacheConfig.java may become unused after the renaming to repoCache with the updated type, warrants verification.
  • Missing Version in dependency (Potential): The review doesn't explicitly mention dependency versions but this is a best practice to ensure consistency.
  • Inconsistent Resource Handling: The use of try-with-resources is inconsistent in the test code. All auto-closable resources should be managed consistently.

Potential Bugs

  • Insufficient Error Handling in fetchRepositoryData: The fetchRepositoryData method may throw exceptions due to missing or malformed JSON data. Robust checks for key existence are crucial.
  • NullPointerExceptions: The use of RepoValue introduces the risk of NullPointerExceptions if the object is not properly populated. Thorough null checks are needed throughout the code.
  • Race Conditions: The caching mechanism may be susceptible to race conditions due to concurrent access. Appropriate synchronization mechanisms should be implemented.
  • Missing content-length validation: The code uses the content-length header without verifying its format, leading to potential errors.
  • Inconsistent Test Coverage: The updated tests may not adequately cover all aspects of the RepoValue object and its interactions, especially edge cases and error scenarios.

Recommendations

  • (High Priority) Implement robust error handling in fetchRepositoryData using appropriate try-catch blocks and checks for null or missing keys in the JSON data. Example:
RepoValue fetchRepositoryData(String repoId) {
    try {
        JSONObject repoInfo = getRepoInfo(repoId); // Assume this fetches JSON data
        if (repoInfo.has("virusScanner") && repoInfo.has("disableVirusScannerForLargeFile")) {
            boolean virusScanEnabled = repoInfo.getBoolean("virusScanner");
            boolean disableForLargeFiles = repoInfo.getBoolean("disableVirusScannerForLargeFile");
            // ... rest of the logic
        } else {
            // Handle missing keys appropriately, e.g., log a warning and return a default RepoValue
            log.warn("Missing virus scanner information in repository info for repoId: {}", repoId);
            return new RepoValue(false, false, false); // Or throw a custom exception
        }
    } catch (JSONException e) {
        log.error("Error parsing repository info for repoId: {}", repoId, e);
        // Handle exception, e.g., return a default RepoValue or throw a custom exception
        return new RepoValue(false, false, false);
    }
}
  • (High Priority) Add comprehensive null checks to all methods using RepoValue to prevent NullPointerExceptions.
  • (High Priority) Implement synchronization mechanisms (e.g., locks, atomic operations, or a concurrent caching solution) to handle potential race conditions in the caching logic.
  • (Medium Priority) Add validation for the content-length header to ensure it's a valid number format.
  • (Medium Priority) Add more comprehensive unit tests to cover edge cases, error scenarios, and potential null cases in the RepoValue object. Ensure tests cover all possible combinations of virusScanEnabled, versionEnabled, and disableVirusScannerForLargeFile.
  • (Medium Priority) Review and optimize dependencies to eliminate redundancies if possible.

Quality Rating
6/10

Overall
The changes are significant and address important aspects of the SDM service. However, the code requires further improvement regarding error handling, null checks, and concurrency to ensure robustness and stability. Additional unit testing is crucial to validate the changes fully and catch potential regressions. Before merging, the recommendations above must be addressed.

Copy link
Contributor

Gemini Automated Review
Summary of Changes

This commit introduces significant changes to enhance repository versioning and virus scanning within a document management system. Key changes include the addition of a RepoValue class to encapsulate repository properties, modifications to the CacheConfig and SDMService classes to handle the new RepoValue object, and updates to multiple service handlers and test classes to incorporate the new virus scanning and versioning logic. The SDMServiceImpl was updated to fetch and cache repository details, including virus scanning and versioning information, while the tests were updated to reflect these changes.

Best Practices Review

  • Inconsistent Formatting: Potential inconsistency in RepoValue initialization across tests.
  • Redundant Exclusion: Removal of obsolete isRepositoryVersioned function without explicit mention in commit message.
  • Missing Version in dependency: (Needs further investigation - not explicitly stated in partial reviews)
  • Redundant Dependency: (Needs further investigation - not explicitly stated in partial reviews)
  • Unused Property: (Needs further investigation - not explicitly stated in partial reviews)

Potential Bugs

  • Error Handling: The fetchRepositoryData method lacks explicit error handling for JSONException and other potential exceptions during JSON parsing.
  • Null Checks: Missing null checks for values retrieved from the JSON response in fetchRepositoryData could lead to NullPointerExceptions.
  • Inconsistency in RepoValue setup: Inconsistent initialization of RepoValue across different test methods, particularly concerning virusScanEnabled and setDisableVirusScannerForLargeFile.
  • Missing repoid in some checkRepositoryType mocks: Using anyString() for the repository ID in mocks reduces test precision and could mask issues.
  • Missing content-length handling: Assumes the existence of the content-length header without error handling.

Recommendations

  • Prioritize: Implement comprehensive error handling in fetchRepositoryData, including catching JSONException and other relevant exceptions. Handle null values gracefully, potentially using Optional. (Code example below)
  • Prioritize: Add null checks before accessing fields of JSONObject in fetchRepositoryData using .has().
  • Prioritize: Standardize RepoValue initialization across all test methods. Define clear semantics for virusScanEnabled and setDisableVirusScannerForLargeFile (e.g., using enums).
  • Prioritize: Replace anyString() with specific repository IDs in checkRepositoryType mocks for more robust tests.
  • Rename repoCache to repositoryInfoCache and getVersionedRepoCache to getRepositoryInfoCache for better readability.
  • Add error handling for missing content-length header.
  • Review and improve test coverage, possibly adding data-driven tests to reduce redundancy.
try {
    JSONObject json = new JSONObject(response);
    if (json.has("virusScanEnabled")) {
        boolean virusScanEnabled = json.getBoolean("virusScanEnabled");
        // ... use virusScanEnabled ...
    } else {
        // Handle missing key
        log.warn("Key 'virusScanEnabled' missing in JSON response.");
    }
    // ... similar handling for other keys
} catch (JSONException e) {
    log.error("Error parsing JSON response: ", e);
    // Handle the exception appropriately (e.g., throw a custom exception, return a default value)
}

Quality Rating

6/10

Overall

The code introduces valuable features, but requires significant improvements in error handling and test robustness before merging. Addressing the prioritized recommendations is crucial to ensure stability and reliability.

Copy link
Contributor

Gemini Automated Review
Summary of Changes
This diff introduces significant changes to the document management system's handling of repository information and virus scanning. Key changes include the introduction of a RepoValue class to encapsulate repository metadata (virus scan status, versioning status, large file handling), modifications to SDMService and its implementations to fetch and utilize this richer metadata, and updates to several handlers to incorporate the new logic and error handling around virus scanning and file size limits. Accompanying unit tests have been updated to reflect these changes.

Best Practices Review

  • Inconsistent Formatting: (Potentially) Inconsistent formatting across different files and classes might exist, although the specifics are not directly mentioned in the partial reviews.
  • Redundant Dependency: (Potential) A potential for redundant dependencies may exist if the JSON handling is already provided by another library.
  • Unused Property: (Potential) Some properties within the JSON response might be unused and should be identified and removed for cleaner code.
  • Redundant Exclusion: (Not applicable based on the partial reviews).
  • Version Mismatch: (Not applicable based on the partial reviews).
  • Missing Version in dependency: (Not applicable based on the partial reviews).

Potential Bugs

  • The fetchRepositoryData method lacks robust error handling for unexpected JSON structures or missing fields, potentially leading to unexpected behavior or crashes. (SDMServiceImpl)
  • The 400MB file size limit in SDMAttachmentsServiceHandler is hardcoded and should be configurable.
  • The caching mechanism in SDMServiceImpl might not be thread-safe or efficient.
  • NullPointerExceptions are possible in fetchRepositoryData if JSON objects or fields are null. (SDMServiceImpl)
  • Insufficient testing of the updated RepoValue functionality could lead to regressions. (SDMServiceGenericHandlerTest)

Recommendations

  • High Priority: Implement comprehensive error handling and input validation in fetchRepositoryData using a JSON schema validation library or by explicitly checking for the existence of all necessary fields. Handle exceptions gracefully and provide informative error messages.
// Example improved fetchRepositoryData method (Illustrative)
public RepoValue fetchRepositoryData(String repoUrl) {
    try {
        // ... existing code ...
        JSONObject json = JSON.parse(jsonString);  // Use a robust JSON library like Jackson
        if (json.has("virusScanEnabled") && json.has("versionEnabled") && json.has("largeFileHandling")) {
            return new RepoValue(json.getBoolean("virusScanEnabled"), json.getBoolean("versionEnabled"), json.getString("largeFileHandling"));
        } else {
            throw new JSONException("Missing required fields in repository data");
        }
    } catch (JSONException e) {
        log.error("Error parsing repository data: {}", e.getMessage());
        throw new ServiceException("Failed to fetch repository data", e); // Or a custom exception
    }
}
  • High Priority: Make the 400MB file size limit configurable via a properties file or environment variables.
  • High Priority: Improve the caching mechanism in SDMServiceImpl to handle concurrent requests efficiently and safely. Consider using a thread-safe caching library like Ehcache.
  • High Priority: Add thorough unit tests to cover edge cases and error handling scenarios for fetchRepositoryData and checkRepositoryType, including null values, missing keys, and unexpected JSON structures. Test boundary conditions.
  • Implement proper null checks using Optional or Lombok's @NonNull annotation to prevent NullPointerExceptions in fetchRepositoryData.
  • Add more comprehensive testing to validate the behavior changes introduced by the RepoValue class, ensuring complete regression test coverage.
  • Add comments explaining the purpose and the logic of the code in all files.
  • Evaluate the added content-length header and its value. If not required, remove it.

Quality Rating
5/10

Overall
The code introduces a significant improvement to repository metadata handling, but lacks robust error handling, input validation, and comprehensive testing. Addressing the high-priority recommendations is crucial before merging. The current state has considerable risk of introducing instability and runtime errors.

Copy link
Contributor

Gemini Automated Review
Summary of Changes
This code introduces a RepoValue class to encapsulate repository properties (virus scan, versioning, large file handling), updating various services (SDMService, SDMAttachmentsServiceHandler, SDMServiceGenericHandler) and their unit tests to use this richer data structure. The CacheConfig class is modified to store RepoValue objects, and error handling constants are added to SDMConstants. A fetchRepositoryData helper method is added for JSON parsing. The checkRepositoryType method's return type is changed to RepoValue.

Best Practices Review

  • Inconsistent Error Handling: Error handling is inconsistent across methods, particularly in fetchRepositoryData.
  • Missing Null Checks: Several methods lack crucial null checks.
  • Redundant Dependency (Potential): The use of org.json should be evaluated; better alternatives exist.
  • Missing Cache Invalidation: No mechanism exists to invalidate stale cache entries.
  • Hardcoded Limit: The 400MB large file limit in SDMAttachmentsServiceHandler is hardcoded.
  • Missing Version in dependency (Potential): Dependency versions are not explicitly stated in the provided context.

Potential Bugs

  • fetchRepositoryData: Lacks explicit error handling for malformed JSON or missing fields.
  • fetchRepositoryData: Missing null checks for potentially null repository information.
  • Cache: Stale cached data due to lack of invalidation mechanism.
  • SDMAttachmentsServiceHandler: Assumes the content-length header always exists and is valid; lacks error handling for its absence or invalid data.
  • General: The absence of logging makes debugging difficult.

Recommendations

  • (High Priority) Implement robust error handling and null checks in fetchRepositoryData: This is crucial to prevent crashes and unexpected behavior. Example:
RepoValue fetchRepositoryData(String repoId) {
    try {
        // ... existing code ...
    } catch (JSONException e) {
        log.error("Error parsing repository data for {}: {}", repoId, e.getMessage());
        return null; // Or throw a custom exception
    } catch (IOException e){
        log.error("IO error fetching repository data for {}: {}", repoId, e.getMessage());
        return null; // Or throw a custom exception
    }
}
  • (High Priority) Implement cache invalidation: Consider using time-based expiration or a last-modified timestamp check.
  • (Medium Priority) Make the large file size limit configurable: Move the 400MB limit to a configuration setting.
  • (Medium Priority) Improve error handling in SDMAttachmentsServiceHandler for content-length: Handle NullPointerException and NumberFormatException.
  • (Low Priority) Add comprehensive logging: Log successful fetches, cache hits/misses, and errors.
  • (Low Priority) Evaluate and replace org.json: Consider using Jackson or Gson for better JSON handling.

Quality Rating
6/10

Overall
The changes are conceptually sound, improving the code's structure and data handling. However, critical issues related to error handling, null checks, and cache management need to be addressed before merging. The recommendations above, particularly the high-priority ones, must be implemented to ensure stability and reliability.

Copy link
Contributor

An error occurred while generating the final review. Partial reviews are below:

Error: Could not generate review for this chunk due to: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [404 Not Found] Publisher Model projects/generativelanguage-ga/locations/us-central1/publishers/google/models/gemini-1.5-flash-002 was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions


Error: Could not generate review for this chunk due to: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [404 Not Found] Publisher Model projects/generativelanguage-ga/locations/us-central1/publishers/google/models/gemini-1.5-flash-002 was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions

Copy link
Contributor

An error occurred while generating the final review. Partial reviews are below:

Error: Could not generate review for this chunk due to: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [404 Not Found] Publisher Model projects/generativelanguage-ga/locations/us-central1/publishers/google/models/gemini-1.5-flash-002 was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions


Error: Could not generate review for this chunk due to: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [404 Not Found] Publisher Model projects/generativelanguage-ga/locations/us-central1/publishers/google/models/gemini-1.5-flash-002 was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions

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.

1 participant