Skip to content
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

HCMPRE-1576,1577,1578: Removed readme sheet, localised estimation sheet and added facility name #1314

Merged
merged 12 commits into from
Jan 8, 2025

Conversation

tanishi-egov
Copy link
Collaborator

@tanishi-egov tanishi-egov commented Jan 3, 2025

Summary by CodeRabbit

  • New Features

    • Added new utility classes for Excel processing and styling
    • Introduced methods for localizing Excel headers and adding facility names to sheets
    • Enhanced error handling and logging for Excel file processing
  • Chores

    • Updated constants and configuration settings
    • Improved utility methods for parsing and extracting data from JSON objects
  • Refactor

    • Restructured Excel parsing and enrichment utilities
    • Added more robust error handling and logging mechanisms

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces several enhancements to the health services resource generator module. New utility classes and modifications to existing classes focus on improving Excel file processing, localization, and data enrichment. The changes include adding a new OutputEstimationGenerationUtil for processing Excel workbooks, creating an ExcelStylingUtil for cell styling, and updating existing utilities like ParsingUtil and EnrichmentUtil with additional functionality for handling localization, facility mapping, and error handling.

Changes

File Change Summary
ServiceConstants.java Added new constants for JSON object error handling, facility names, and Excel styling (background color, cell freezing, column width)
ExcelParser.java Updated constructor and method signatures to include OutputEstimationGenerationUtil, enhanced error handling and logging
EnrichmentUtil.java Added logging statements for sheet enrichment methods
ExcelStylingUtil.java New utility class for styling Excel cells and converting HEX colors
OutputEstimationGenerationUtil.java New utility class for processing Excel workbooks, adding localized headers, and assigned facility names
ParsingUtil.java Added methods for sheet processing validation, JSON object field extraction, and updated constructor

Sequence Diagram

sequenceDiagram
    participant EP as ExcelParser
    participant OEG as OutputEstimationGenerationUtil
    participant ESU as ExcelStylingUtil
    participant PU as ParsingUtil

    EP->>OEG: processOutputFile
    OEG->>PU: isSheetAllowedToProcess
    OEG->>ESU: styleCell
    OEG-->>EP: Processed Workbook
Loading

Possibly related PRs

Suggested reviewers

  • sathishp-eGov
  • kavi-egov
  • shashwat-egov
  • Priyanka-eGov

Poem

🐰 Hop, hop, Excel's new dance!
Constants bloom, utilities prance
Styling cells with rabbit's flair
Localization beyond compare
Code hops forward with joyful glance! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tanishi-egov tanishi-egov changed the base branch from master to microplanning-v0.2 January 3, 2025 08:55
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

🔭 Outside diff range comments (1)
health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java (1)

Line range hint 203-227: Sheet-by-Sheet Processing

processSheets:

  • Relies on parsingUtil.isSheetAllowedToProcess.
  • Depending on the plan status, either enriches the sheet with census records, processes rows for calculations, or enriches plan estimates.
  • The logic is open for extension. Consider adding further validation or logging when skipping sheets.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dbb1d7 and dba50ac.

📒 Files selected for processing (6)
  • health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java (2 hunks)
  • health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java (8 hunks)
  • health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java (4 hunks)
  • health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java (1 hunks)
  • health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java (1 hunks)
  • health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java (5 hunks)
🔇 Additional comments (22)
health-services/resource-generator/src/main/java/org/egov/processor/util/ExcelStylingUtil.java (2)

38-41: Locking cells requires sheet protection.
Setting cellStyle.setLocked(true) only takes effect if the sheet is also protected. Otherwise, the locked property will not restrict edits. If the intent is to actually prevent edits, ensure the sheet is protected.


75-77: 🧹 Nitpick (assertive)

Confirm the necessity of runtime color transformation.
Increasing RGB components by 10% can alter brand or design guidelines. Verify that consuming modules and design teams are aware and approve of this runtime color shift.

health-services/resource-generator/src/main/java/org/egov/processor/util/OutputEstimationGenerationUtil.java (6)

1-9: Well-structured Class Declaration

The new class OutputEstimationGenerationUtil is neatly introduced with relevant imports and a clear @Component annotation. This promotes good Spring-based design, ensuring the utility is injectable where required.


32-37: Constructor Dependencies

The constructor correctly injects the required utilities (LocaleUtil, ParsingUtil, EnrichmentUtil, ExcelStylingUtil). This is a good pattern for maintaining testability and clear dependency management.


39-59: Localizing Headers in Sheets

The processOutputFile method:

  • Removes sheets not permitted by parsingUtil.isSheetAllowedToProcess.
  • Builds a localization map from the LocaleResponse.
  • Iterates through remaining sheets to localize header cells.

These steps show a cohesive approach to eliminating irrelevant sheets and localizing headers. The logic is clear and modular.


124-148: Boundary-Facility Mapping

getBoundaryCodeToFacilityMap efficiently:

  • Gathers boundary codes from all allowed sheets.
  • Fetches census data for these boundary codes.
  • Maps the relevant census record field to FACILITY_NAME.

This approach cleanly encapsulates the logic for building the boundary-to-facility relationship. The usage of streams for collecting to a map is concise and effective.


150-178: Populating Facility Column by Boundary Code

addFacilityNameToSheet creates and populates the new facility column for each row:

  • Retrieves the boundary code from the row.
  • Looks up the facility in the boundaryCodeToFacility.
  • Writes the facility name to the newly created column.

Ensure that you handle rows where the boundary code cell is blank or typed incorrectly, to avoid potential NullPointerExceptions (line 169). For example, add a null/empty check before calling getStringCellValue().


180-194: Creating the New Column

createAssignedFacilityColumn appends the new facility column to the header row:

  • Sets the column type to STRING.
  • Styles the header cell.
  • Returns the column index for subsequent population.

This is a neat and straightforward method, nicely separated from the logic that populates the column’s cells. Good job keeping the styling concerns isolated in excelStylingUtil.

health-services/resource-generator/src/main/java/org/egov/processor/util/ParsingUtil.java (6)

10-11: Importing Locale Classes

The addition of Locale imports aligns with the new locale-based checks in the utility. These imports ensure the class has the references needed to integrate localization data seamlessly.


20-20: Added BigDecimal Support

The import of java.math.BigDecimal suggests that numeric conversions in newly introduced methods now require high-precision arithmetic. This is a good approach to avoid floating-point imprecision.


28-28: New MDMS Field Constants

import static org.egov.processor.config.ServiceConstants.*;

Pulling in constants from ServiceConstants helps maintain consistent naming and reduce duplication for error codes, messages, and property field names across the codebase.


40-43: Constructor Expansion

Adding MdmsUtil mdmsUtil and ObjectMapper objectMapper extends the parsing capabilities, supporting dynamic MDMS data retrieval and JSON processing. This is a positive step toward scalability, as it cleanly injects additional dependencies.


324-324: Removing Static from isRowEmpty

Making isRowEmpty non-static enables the method to leverage instance-level dependencies if needed. However, ensure no external usage breaks from the signature change if the method was previously accessed in a static manner.


402-422: Sheet Eligibility Check for Processing

isSheetAllowedToProcess:

  • Fetches MDMS data for common constants.
  • Loops over locale messages and checks if the sheet name matches certain read-me or boundary data criteria.
  • Returns false to skip disallowed sheets.

This method centralizes “which sheets are valid” logic nicely, and it’s used consistently in other classes. Good approach!

health-services/resource-generator/src/main/java/org/egov/processor/service/ExcelParser.java (5)

63-64: Introducing OutputEstimationGenerationUtil

The new outputEstimationGenerationUtil dependency indicates a design choice to shift estimation logic out of ExcelParser. This fosters a single-responsibility approach and keeps the parser’s scope narrower.


Line range hint 67-81: Constructor Update

Expanding the constructor to accept multiple new parameters, including OutputEstimationGenerationUtil, ensures that the parser can delegate tasks like generating final output files and localizing them. This is consistent with good constructor-based dependency injection.


130-130: Uploading and Integrating Campaign

In processExcelFile, the method reference for uploadFileAndIntegrateCampaign is extended, reflecting a new workflow for generating final output files. This ensures a more unified approach to file and campaign processing.


Line range hint 155-180: Conditions for File Upload and Integration

Inside uploadFileAndIntegrateCampaign:

  • If the plan status requires “PlanEstimates,” the file is uploaded and the plan updated.
  • If the plan status is “UpdatePlanEstimatesIntoOutputFile” (line 165), the output file is integrated into the project factory, processed for facility assignment (lines 170-173), re-uploaded, and updated in the plan configuration.

This flow is thorough and ensures consistent data across the system. The transitions between statuses are well-defined and the logic is easy to follow.


227-227: Enriching with Approved Plan Estimates

Note that you’ve consistently used enrichmentUtil for different statuses. This is a nice example of the open/closed principle—logic can expand without rewriting the parser core. No major issues spotted here.

health-services/resource-generator/src/main/java/org/egov/processor/config/ServiceConstants.java (2)

42-44: Key-Not-Present Constants

PROVIDED_KEY_IS_NOT_PRESENT_IN_JSON_OBJECT_* constants clearly communicate the error scenario for missing JSON keys. This enhances maintainability and fosters consistent error handling in the code.


122-123: Facility Name Constants

FACILITY_NAME and HCM_MICROPLAN_SERVING_FACILITY are straightforward. They help avoid scattered string literals across the code. Great for clarity and avoiding typos.

health-services/resource-generator/src/main/java/org/egov/processor/util/EnrichmentUtil.java (1)

226-229: Plan Records for Enrichment

Querying plan records via getPlanRecordsForEnrichment and storing them in a map for quick lookups is consistent with how census records are handled. This symmetry improves maintainability.

@Priyanka-eGov Priyanka-eGov merged commit 656f733 into microplanning-v0.2 Jan 8, 2025
2 of 4 checks passed
@Priyanka-eGov Priyanka-eGov deleted the download-estimation-1578 branch January 8, 2025 07:05
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.

2 participants