Samer-Melhem-FOO commented on code in PR #6116:
URL: https://github.com/apache/fineract/pull/6116#discussion_r3710967987


##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java:
##########
@@ -73,13 +84,32 @@ private List<ClientData> readExcelFile(final Workbook 
workbook, final String loc
         for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
             Row row;
             row = clientSheet.getRow(rowIndex);
+            if (row != null) {

Review Comment:
   Done, dropped to debug level.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/client/ClientEntityImportHandler.java:
##########
@@ -73,13 +84,32 @@ private List<ClientData> readExcelFile(final Workbook 
workbook, final String loc
         for (int rowIndex = 1; rowIndex <= noOfEntries; rowIndex++) {
             Row row;
             row = clientSheet.getRow(rowIndex);
+            if (row != null) {
+                LOG.info("Processing bulk upload row {} with {} cells", 
row.getRowNum(), row.getLastCellNum());
+            }
             if (ImportHandlerUtils.isNotImported(row, 
ClientEntityConstants.STATUS_COL)) {
                 clients.add(readClient(workbook, row, locale, dateFormat));
             }
         }
         return clients;
     }
 
+    /**
+     * Extracts the code value ID out of a "Name (id)" formatted dropdown 
cell, as written by
+     * {@link 
org.apache.fineract.infrastructure.bulkimport.populator.client.ClientEntityWorkbookPopulator}.
+     */
+    private Long parseIdFromDisplayValue(final String displayValue, final 
String fieldName) {
+        if (displayValue == null) {
+            return null;
+        }
+        String idPart = SearchUtil.extractIdFromDisplayValue(displayValue);
+        if (idPart != null && idPart.matches("\\d+")) {
+            return Long.valueOf(idPart);
+        }
+        LOG.error("Bulk upload error: Could not extract ID from {}. Row data: 
{}", fieldName, displayValue);

Review Comment:
   Fair point, not a hard failure since it returns null and processing 
continues. Changed to warn.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/service/BulkImportWorkbookPopulatorServiceImpl.java:
##########
@@ -237,21 +251,60 @@ private WorkbookPopulator populateClientWorkbook(final 
String entityType, final
         List<CodeValueData> addressTypesCodeValues = 
fetchCodeValuesByCodeName("ADDRESS_TYPE");
         List<CodeValueData> stateProvinceCodeValues = 
fetchCodeValuesByCodeName("STATE");
         List<CodeValueData> countryCodeValues = 
fetchCodeValuesByCodeName("COUNTRY");
+
+        // Fetch required datatables for CLIENT entity with CREATE status
+        String entitySubtype = null;
+        if 
(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString()))
 {
+            entitySubtype = "Person";
+        } else if 
(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_ENTITY.toString()))
 {
+            entitySubtype = "Entity";
+        }
+        List<DatatableData> requiredDatatables = 
fetchRequiredDatatables(entitySubtype);
+
         if 
(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_PERSON.toString()))
 {
             List<CodeValueData> genderCodeValues = 
fetchCodeValuesByCodeName("Gender");
             return new ClientPersonWorkbookPopulator(new 
OfficeSheetPopulator(offices), new PersonnelSheetPopulator(staff, offices),
                     clientTypeCodeValues, genderCodeValues, 
clientClassification, addressTypesCodeValues, stateProvinceCodeValues,
-                    countryCodeValues);
+                    countryCodeValues, requiredDatatables);
         } else if 
(entityType.trim().equalsIgnoreCase(GlobalEntityType.CLIENTS_ENTITY.toString()))
 {
             List<CodeValueData> constitutionCodeValues = 
fetchCodeValuesByCodeName("Constitution");
             List<CodeValueData> mainBusinessline = 
fetchCodeValuesByCodeName("Main Business Line");
             return new ClientEntityWorkbookPopulator(new 
OfficeSheetPopulator(offices), new PersonnelSheetPopulator(staff, offices),
                     clientTypeCodeValues, constitutionCodeValues, 
mainBusinessline, clientClassification, addressTypesCodeValues,
-                    stateProvinceCodeValues, countryCodeValues);
+                    stateProvinceCodeValues, countryCodeValues, 
requiredDatatables);
         }
         return null;
     }
 
+    private List<DatatableData> fetchRequiredDatatables(final String 
entitySubtype) {
+        List<DatatableData> requiredDatatables = new ArrayList<>();
+        try {
+            // Get required datatables for CLIENT entity with CREATE status
+            List<EntityDatatableChecks> entityDatatableChecks;
+            if (entitySubtype != null) {
+                // Filter by entity subtype
+                entityDatatableChecks = 
entityDatatableChecksRepository.findByEntityAndStatusAndSubtype(EntityTables.CLIENT.getName(),
+                        StatusEnum.CREATE.getValue(), entitySubtype);
+            } else {
+                // Get all required datatables regardless of subtype
+                entityDatatableChecks = 
entityDatatableChecksRepository.findByEntityAndStatus(EntityTables.CLIENT.getName(),
+                        StatusEnum.CREATE.getValue());
+            }
+
+            // Convert EntityDatatableChecks to DatatableData
+            for (EntityDatatableChecks check : entityDatatableChecks) {
+                DatatableData datatable = 
datatableReadService.retrieveDatatable(check.getDatatableName());
+                if (datatable != null) {
+                    requiredDatatables.add(datatable);
+                }
+            }
+        } catch (Exception e) {
+            LOG.warn("Error fetching required datatables for bulk import 
template", e);
+            // Continue without datatables if there's an error

Review Comment:
   No, agreed — silently continuing without the datatables would reintroduce 
the exact bug this PR fixes (missing mandatory datatable columns), just less 
visibly. Removed the try/catch so it propagates, consistent with the other 
populate*Workbook helpers in this class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to