-
Notifications
You must be signed in to change notification settings - Fork 140
[MOSIP-27141] & [MOSIP-28564] Fixed the bulk upload issues #1263
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: release-1.3.x
Are you sure you want to change the base?
Changes from all commits
89d8921
d35ae69
b455f0f
3c4f314
f706346
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| import io.mosip.admin.packetstatusupdater.util.AuditUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.mosip.admin.packetstatusupdater.util.EventEnum; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.mosip.kernel.core.util.EmptyCheckUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.EntityManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.EntityManagerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.validation.Validator; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.batch.core.Job; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,11 +60,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.client.RestTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.web.multipart.MultipartFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.EntityManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.persistence.EntityManagerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.sql.DataSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import jakarta.validation.Validator; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.BufferedReader; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.InputStreamReader; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.sql.Timestamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDate; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -252,16 +253,30 @@ private BulkDataResponseDto importDataFromFile(String tableName, String operatio | |||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Is file empty ? {}, file-size :{}", file.isEmpty(), file.getSize()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (file.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setStatusCode("FAILED"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| updateBulkUploadTransaction(bulkUploadTranscation); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RequestException(BulkUploadErrorCode.EMPTY_FILE.getErrorCode(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| BulkUploadErrorCode.EMPTY_FILE.getErrorMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!file.getOriginalFilename().endsWith(".csv") && !file.getOriginalFilename().endsWith(".xls") && !file.getOriginalFilename().endsWith(".xlsx")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setStatusCode("FAILED"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| updateBulkUploadTransaction(bulkUploadTranscation); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RequestException(BulkUploadErrorCode.INVALID_FILE_FORMAT.getErrorCode(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| BulkUploadErrorCode.INVALID_FILE_FORMAT.getErrorMessage()); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Boolean isCSV = file.getOriginalFilename().endsWith(".csv"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| String firstLine = reader.readLine(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (firstLine != null && !firstLine.contains(lineDelimiter)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setStatusCode("FAILED"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| updateBulkUploadTransaction(bulkUploadTranscation); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RequestException(BulkUploadErrorCode.INVALID_DELIMITER.getErrorCode(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "Invalid delimiter used. Expected delimiter: " + lineDelimiter); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+276
to
+277
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. Minor: Error message deviates from enum message. Unlike other error handling in this method (lines 258-259, 265-266), this code appends additional context to the enum's error message. While the extra information about the expected delimiter is helpful for debugging, it's inconsistent with the established pattern. Consider either:
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
269
to
+279
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. Critical: Delimiter validation incorrectly applied to Excel files. The delimiter validation (lines 271-279) executes for ALL file types, including Excel (.xls, .xlsx), which don't use text delimiters. This contradicts the past review discussion where it was confirmed that delimiter checking is only for CSV files. Excel files will either:
Apply this diff to restrict validation to CSV files only: Boolean isCSV = file.getOriginalFilename().endsWith(".csv");
-
-try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
- String firstLine = reader.readLine();
- if (firstLine != null && !firstLine.contains(lineDelimiter)) {
- bulkUploadTranscation.setStatusCode("FAILED");
- updateBulkUploadTransaction(bulkUploadTranscation);
- throw new RequestException(BulkUploadErrorCode.INVALID_DELIMITER.getErrorCode(),
- "Invalid delimiter used. Expected delimiter: " + lineDelimiter);
- }
-}
+
+if (isCSV) {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
+ String firstLine = reader.readLine();
+ if (firstLine != null && !firstLine.contains(lineDelimiter)) {
+ bulkUploadTranscation.setStatusCode("FAILED");
+ updateBulkUploadTransaction(bulkUploadTranscation);
+ throw new RequestException(BulkUploadErrorCode.INVALID_DELIMITER.getErrorCode(),
+ "Invalid delimiter used. Expected delimiter: " + lineDelimiter);
+ }
+ }
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| auditUtil.setAuditRequestDto(EventEnum.getEventEnumWithValue(EventEnum.BULKDATA_UPLOAD_CSV, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| operation + " from " + file.getOriginalFilename()),null); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -318,7 +333,9 @@ public BulkDataResponseDto bulkDataOperation(String tableName, String operation, | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| private void updateBulkUploadTransaction(BulkUploadTranscation bulkUploadTranscation) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setStatusCode("COMPLETED"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (bulkUploadTranscation.getStatusCode() == null || !bulkUploadTranscation.getStatusCode().equalsIgnoreCase("FAILED")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setStatusCode("COMPLETED"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setUploadedDateTime(Timestamp.valueOf(LocalDateTime.now(ZoneId.of("UTC")))); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkUploadTranscation.setUpdatedBy("JOB"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bulkTranscationRepo.save(bulkUploadTranscation); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.