-
Notifications
You must be signed in to change notification settings - Fork 28
Pass the token from controller to fix the issue in data sync #92
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
Conversation
WalkthroughThis change updates multiple controller and service methods across the codebase to accept and propagate a JWT token, typically extracted from HTTP request cookies. The JWT token is then included in REST calls by passing it to a revised utility method for HTTP request entity creation. Several method signatures are updated, and logging is slightly reduced. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller
participant Service
participant RestTemplateUtil
Client->>Controller: HTTP Request (with cookies)
Controller->>Controller: Extract JWT token from cookies
Controller->>Service: Call method(..., jwtToken)
Service->>RestTemplateUtil: createRequestEntity(..., jwtToken)
RestTemplateUtil-->>Service: HttpEntity with headers (JWT token as cookie)
Service-->>Controller: Response
Controller-->>Client: HTTP Response
Possibly related PRs
Suggested reviewers
Poem
π Recent review detailsConfiguration used: CodeRabbit UI π Files selected for processing (4)
π§ Files skipped from review as they are similar to previous changes (4)
β° Context from checks skipped due to timeout of 90000ms (2)
β¨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
π Outside diff range comments (2)
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java (2)
228-228
: Fix the incomplete statement causing syntax error.There's an incomplete statement with a hanging closing parenthesis that's likely causing the pipeline failure.
- objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response)); + logger.debug("Data sync failed with response: {}", + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));
168-170
: Add missing token parameter to syncDataToServer method call.This method call is missing the
token
parameter that the method signature expects, causing compilation errors.serverAcknowledgement = syncDataToServer(vanID, obj.getSchemaName(), obj.getTableName(), obj.getVanAutoIncColumnName(), obj.getServerColumnName(), syncDataBatch, user, - Authorization); + Authorization, token);
π§Ή Nitpick comments (2)
src/main/java/com/iemr/mmu/service/cancerScreening/CSCarestreamServiceImpl.java (1)
67-67
: Consider explicit token parameter for better token propagation.The method passes an empty string for the JWT token parameter, which causes
RestTemplateUtil.createRequestEntity
to fall back to extracting the token from the current request context. For consistency with the broader PR objective of explicit token propagation, consider updating the method signature to accept a token parameter and pass it through.Apply this diff to make token handling more explicit:
public int createMamographyRequest(ArrayList<Object[]> benDataForCareStream, long benRegID, long benVisitID, - String Authorization) { + String Authorization, String jwtToken) { int responseData = 0; RestTemplate restTemplate = new RestTemplate(); try { String requestOBJ = getOrderCreationRequestOBJ(benDataForCareStream, benRegID, benVisitID); - HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization, ""); + HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization, jwtToken);src/main/java/com/iemr/mmu/service/common/transaction/CommonDoctorServiceImpl.java (1)
910-910
: Consider explicit token parameter for consistency.Similar to other service methods in this PR, the method uses an empty string for the JWT token parameter, relying on fallback token extraction. For consistency with the explicit token propagation pattern, consider updating the method signature to accept a token parameter.
Apply this diff to align with the explicit token propagation pattern:
public int callTmForSpecialistSlotBook(TcSpecialistSlotBookingRequestOBJ tcSpecialistSlotBookingRequestOBJ, - String Authorization) { + String Authorization, String jwtToken) { int successFlag = 0; // OutputMapper outputMapper = new OutputMapper(); String requestOBJ = OutputMapper.gson().toJson(tcSpecialistSlotBookingRequestOBJ); RestTemplate restTemplate = new RestTemplate(); - HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization,""); + HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization, jwtToken);
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (13)
src/main/java/com/iemr/mmu/controller/dataSyncActivity/StartSyncActivity.java
(5 hunks)src/main/java/com/iemr/mmu/controller/registrar/main/RegistrarController.java
(6 hunks)src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java
(2 hunks)src/main/java/com/iemr/mmu/service/cancerScreening/CSCarestreamServiceImpl.java
(1 hunks)src/main/java/com/iemr/mmu/service/common/master/RegistrarServiceMasterDataImpl.java
(1 hunks)src/main/java/com/iemr/mmu/service/common/transaction/CommonDoctorServiceImpl.java
(1 hunks)src/main/java/com/iemr/mmu/service/common/transaction/CommonServiceImpl.java
(2 hunks)src/main/java/com/iemr/mmu/service/dataSyncActivity/DownloadDataFromServerImpl.java
(5 hunks)src/main/java/com/iemr/mmu/service/dataSyncActivity/DownloadDataFromServerTransactionalImpl.java
(8 hunks)src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java
(6 hunks)src/main/java/com/iemr/mmu/service/registrar/RegistrarServiceImpl.java
(4 hunks)src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java
(4 hunks)src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java
(1 hunks)
π§° Additional context used
𧬠Code Graph Analysis (9)
src/main/java/com/iemr/mmu/service/common/transaction/CommonDoctorServiceImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java (1)
src/main/java/com/iemr/mmu/utils/response/OutputResponse.java (1)
OutputResponse
(37-206)
src/main/java/com/iemr/mmu/service/common/master/RegistrarServiceMasterDataImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/cancerScreening/CSCarestreamServiceImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/dataSyncActivity/DownloadDataFromServerTransactionalImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/registrar/RegistrarServiceImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/common/transaction/CommonServiceImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java (1)
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
RestTemplateUtil
(12-45)
πͺ GitHub Actions: Build On Pull Request
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java
[error] 137-137: Maven Checkstyle Plugin failed during checkstyle configuration: IllegalStateException occurred while parsing file. Error at line 137, column 75: mismatched input '(' expecting ';' (InputMismatchException).
πͺ GitHub Actions: Call Checkstyle
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java
[error] 137-137: Maven Checkstyle plugin failed: IllegalStateException while parsing file. Error at line 137, column 75: mismatched input '(' expecting ';' (InputMismatchException).
πͺ GitHub Actions: Package
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java
[error] 137-137: Maven Checkstyle plugin failed: IllegalStateException while parsing file. Error at line 137, column 75: mismatched input '(' expecting ';' (InputMismatchException).
β° Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (java)
π Additional comments (13)
src/main/java/com/iemr/mmu/service/common/master/RegistrarServiceMasterDataImpl.java (1)
225-228
: Excellent implementation of explicit token propagation.The method signature correctly accepts a
token
parameter and properly passes it toRestTemplateUtil.createRequestEntity
. This implementation aligns perfectly with the PR objective of explicit JWT token propagation from controllers to service layers.src/main/java/com/iemr/mmu/controller/teleconsultation/TeleConsultationController.java (1)
74-81
: Proper controller-level token extraction and propagation.The implementation correctly follows the pattern established in this PR:
- Method signature updated to accept
HttpServletRequest
- JWT token extracted from cookies using
CookieUtil.getJwtTokenFromCookie
- Token properly passed to the service layer method
This aligns well with the PR objective of fixing data sync issues by ensuring proper token propagation.
src/main/java/com/iemr/mmu/service/dataSyncActivity/DownloadDataFromServerTransactionalImpl.java (1)
85-285
: Comprehensive and consistent token propagation implementation.The implementation thoroughly updates the entire service class for explicit JWT token propagation:
- Main public method
downloadTransactionalData
accepts token parameter- All internal method calls consistently pass the token parameter
- Both private helper methods
downloadDataFromCentral
andupdateProcessedFlagToCentral
properly accept and use the token- All
RestTemplateUtil.createRequestEntity
calls correctly include the token parameterThis comprehensive approach ensures proper token handling throughout the data synchronization workflow, directly addressing the PR objective of fixing data sync issues through proper token propagation.
src/main/java/com/iemr/mmu/utils/RestTemplateUtil.java (1)
24-35
: Excellent JWT token fallback implementation.The fallback logic to retrieve the JWT token from cookies when not explicitly provided is well-implemented with proper error handling and logging.
src/main/java/com/iemr/mmu/service/tele_consultation/TeleConsultationServiceImpl.java (2)
132-132
: Method signature correctly updated for JWT token propagation.The addition of the
token
parameter aligns with the broader pattern of explicitly passing JWT tokens through service layers.
168-200
: JWT token properly propagated through the call chain.The token parameter is correctly passed from
updateBeneficiaryStatusToCancelTCRequest
tocancelSlotForTCCancel
and then toRestTemplateUtil.createRequestEntity
, ensuring consistent authorization handling.src/main/java/com/iemr/mmu/service/registrar/RegistrarServiceImpl.java (1)
695-723
: JWT token propagation correctly implemented across beneficiary operations.All four methods (
registerBeneficiary
,updateBeneficiary
,beneficiaryQuickSearch
,beneficiaryAdvanceSearch
) have been consistently updated to accept and pass the JWT token toRestTemplateUtil.createRequestEntity
.src/main/java/com/iemr/mmu/service/dataSyncActivity/DownloadDataFromServerImpl.java (2)
101-130
: JWT token parameter correctly added to data download methods.The addition of the
jwtToken
parameter todownloadMasterDataFromServer
and its proper propagation todownloadDataFromServer
ensures consistent authentication handling for data synchronization operations.
183-189
: RestTemplateUtil.createRequestEntity call properly updated.The method call correctly includes the
jwtToken
parameter, maintaining consistency with the updated utility method signature fromsrc/main/java/com/iemr/mmu/utils/RestTemplateUtil.java
.src/main/java/com/iemr/mmu/service/common/transaction/CommonServiceImpl.java (1)
653-653
: JWT token correctly passed to restTemplatePost.The
getTmCaseSheet
method properly extracts the JWT token from cookies and passes it to therestTemplatePost
method call.src/main/java/com/iemr/mmu/controller/dataSyncActivity/StartSyncActivity.java (1)
41-44
: LGTM! Consistent JWT token extraction and propagation implemented correctly.The changes consistently implement the required JWT token extraction pattern across all controller methods:
- Add
HttpServletRequest
parameter to method signatures- Extract JWT token using
CookieUtil.getJwtTokenFromCookie(request)
- Pass the token to service layer methods
This aligns with the PR objective to fix data sync issues by ensuring JWT tokens are properly forwarded to server API calls.
Also applies to: 67-67, 70-71, 75-75, 114-114, 118-120, 124-125, 180-180, 183-183, 185-185, 204-204, 207-207, 211-211
src/main/java/com/iemr/mmu/controller/registrar/main/RegistrarController.java (1)
48-48
: LGTM! JWT token handling implemented consistently.The controller methods have been properly updated to extract JWT tokens from request cookies and pass them to the service layer. The pattern is consistent with other controllers and follows the established approach for token propagation.
Also applies to: 54-54, 232-232, 236-237, 255-255, 259-260, 308-308, 311-313, 387-387, 391-392, 484-484, 488-489
src/main/java/com/iemr/mmu/service/dataSyncActivity/UploadDataToServerImpl.java (1)
102-102
: LGTM! Service layer JWT token propagation implemented correctly.The service methods have been properly updated to accept and propagate the JWT token parameter through the call chain to
RestTemplateUtil.createRequestEntity
. This ensures the token is included in outbound REST requests as intended.Also applies to: 105-105, 115-115, 118-118, 130-130, 189-189, 342-342, 370-370
src/main/java/com/iemr/mmu/service/common/transaction/CommonServiceImpl.java
Show resolved
Hide resolved
src/main/java/com/iemr/mmu/service/common/transaction/CommonServiceImpl.java
Outdated
Show resolved
Hide resolved
|
π Description
JIRA ID:
AMM - 1688
Pass JWT token from controller to RestTemplate to ensure the token is included when calling the server API, fixing the data sync issue.
β Type of Change
Summary by CodeRabbit
New Features
Bug Fixes
Refactor