Repository navigation
stop:647 Nikshay Workflow: Job Mertic Handling. #161
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,18 +33,21 @@ | |
| import org.springframework.format.annotation.DateTimeFormat; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.iemr.admin.data.nikshay.NikshayJobHistoryLog; | ||
| import com.iemr.admin.data.nikshay.NikshayJobRunDTO; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayFailureReason; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayJobHistoryLogService; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayPhase; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayTriggerType; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
|
|
||
| /** Read side of the Ni-kshay phase history: failed items and one beneficiary's history. */ | ||
| /** Read side of the Ni-kshay phase history: failed items, one beneficiary's history and the runs. */ | ||
| @RestController | ||
| @RequestMapping(value = "/nikshay/log", headers = "Authorization") | ||
| public class NikshayJobLogController { | ||
|
|
@@ -84,6 +87,46 @@ | |
| } | ||
| } | ||
|
|
||
| @Operation(summary = "Ni-kshay runs (the whole job, cron or manual, and manual phase runs), newest first, " | ||
| + "with their picked, succeeded, failed, notApplicable and waiting counts") | ||
| @GetMapping(value = "/runs") | ||
| public ResponseEntity<?> getRuns(@RequestParam(value = "triggerType", required = false) NikshayTriggerType triggerType, | ||
|
Check failure on line 93 in src/main/java/com/iemr/admin/controller/nikshayjoblog/NikshayJobLogController.java
|
||
| @RequestParam(value = "fromDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate, | ||
| @RequestParam(value = "toDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate toDate, | ||
| @RequestParam(value = "page", defaultValue = "0") int page, | ||
| @RequestParam(value = "size", defaultValue = "50") int size) { | ||
| if (page < 0 || size < 1 || size > MAX_PAGE_SIZE) { | ||
| return ResponseEntity.badRequest().body("page must be >= 0 and size between 1 and " + MAX_PAGE_SIZE); | ||
| } | ||
| try { | ||
| // Dates are whole days: toDate is included, so the query bound is the next day's start. | ||
| Page<NikshayJobRunDTO> runs = logService.getRuns(triggerType, | ||
| fromDate != null ? Timestamp.valueOf(fromDate.atStartOfDay()) : null, | ||
| toDate != null ? Timestamp.valueOf(toDate.plusDays(1).atStartOfDay()) : null, page, size); | ||
|
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Map<String, Object> body = new HashMap<>(); | ||
| body.put("runs", runs.getContent()); | ||
| body.put("totalElements", runs.getTotalElements()); | ||
| body.put("page", page); | ||
| body.put("size", size); | ||
| return ResponseEntity.ok(body); | ||
| } catch (Exception e) { | ||
| logger.error("Error reading Ni-kshay runs", e); | ||
| return ResponseEntity.status(500).body("Could not read the Ni-kshay runs"); | ||
| } | ||
| } | ||
|
|
||
| @Operation(summary = "One Ni-kshay run by its jobRunId, with its counts per phase") | ||
| @GetMapping(value = "/runs/{jobRunId}") | ||
| public ResponseEntity<?> getRun(@PathVariable("jobRunId") String jobRunId) { | ||
|
Check failure on line 120 in src/main/java/com/iemr/admin/controller/nikshayjoblog/NikshayJobLogController.java
|
||
| try { | ||
| NikshayJobRunDTO run = logService.getRun(jobRunId); | ||
| return run != null ? ResponseEntity.ok(run) : ResponseEntity.status(404).body("No Ni-kshay run " + jobRunId); | ||
| } catch (Exception e) { | ||
| logger.error("Error reading Ni-kshay run {}", jobRunId, e); | ||
| return ResponseEntity.status(500).body("Could not read the Ni-kshay run"); | ||
| } | ||
| } | ||
|
|
||
| @Operation(summary = "Every Ni-kshay phase entry of one beneficiary (benRegId), newest first") | ||
| @GetMapping(value = "/history") | ||
| public ResponseEntity<?> getHistory(@RequestParam("benId") Long benId) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * AMRIT β Accessible Medical Records via Integrated Technologies | ||
| * Integrated EHR (Electronic Health Records) Solution | ||
| * | ||
| * Copyright (C) "Piramal Swasthya Management and Research Institute" | ||
| * | ||
| * This file is part of AMRIT. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see https://www.gnu.org/licenses/. | ||
| */ | ||
| package com.iemr.admin.data.nikshay; | ||
|
|
||
| import java.sql.Timestamp; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayLogStatus; | ||
| import com.iemr.admin.service.nikshayjoblog.NikshayTriggerType; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * One Ni-kshay run (the whole job, or one manual phase run), from its JOB row in | ||
| * nikshay_worker_job_history_log. summary is the counts saved as JSON in the row's message; | ||
| * rows written before the counts were added have plain text, given in message instead. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| public class NikshayJobRunDTO { | ||
| private String jobRunId; | ||
| private NikshayTriggerType triggerType; | ||
| private String triggeredBy; | ||
| private NikshayLogStatus status; | ||
| // From the summary. For rows written before the times were added, startedAt is null and | ||
| // finishedAt is the row's created_at. | ||
| private Timestamp startedAt; | ||
| private Timestamp finishedAt; | ||
| private JsonNode summary; | ||
| private String message; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Script executed:
Repository: PSMRI/Admin-API
Length of output: 3926
Script executed:
Repository: PSMRI/Admin-API
Length of output: 5284
Reject empty Authorization values in the mobile-client branch of
JwtUserIdValidationFilter.In
src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java, a request with anokhttpUser-Agent and an emptyAuthorizationheader is forwarded without a session check.HTTPRequestInterceptorreturnstruefor an empty value. The new/nikshay/log/runsendpoints then returntriggeredByand legacymessagetext to that request. Non-empty values still need a valid session key. Keep the interceptor unchanged, because valid JWT requests reach it with an emptyAuthorizationvalue.Suggested fix
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.
Needs to be done as a separate fix since this is a existing logic for login.
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.
@chetansaroya Understood. The existing login logic can be addressed in a separate fix. The security concern remains unresolved.
Would you like me to open a follow-up GitHub issue for the
JwtUserIdValidationFilterfix?You are interacting with an AI system.