Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.HashMap;

import org.json.JSONObject;
import org.slf4j.Logger;
Expand All @@ -40,11 +40,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.google.gson.Gson;
import com.iemr.mmu.data.syncActivity_syncLayer.MasterDownloadDataDigester;
Expand All @@ -56,8 +52,6 @@
import com.iemr.mmu.utils.RestTemplateUtil;
import com.iemr.mmu.utils.mapper.InputMapper;

import jakarta.servlet.http.HttpServletRequest;

@Service
@PropertySource("classpath:application.properties")
public class DownloadDataFromServerImpl implements DownloadDataFromServer {
Expand Down Expand Up @@ -335,11 +329,13 @@
// Rest template
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, ServerAuthorization,"datasync");
logger.info("request obj check="+requestOBJ);

Check notice

Code scanning / SonarCloud

Logging should not be vulnerable to injection attacks Low

Change this code to not log user-controlled data. See more on SonarQube Cloud
// Call rest-template to call central API to generate UNIQUE ID at central
ResponseEntity<String> response = restTemplate.exchange(benGenUrlCentral, HttpMethod.POST, request,
String.class);
logger.info("Authorization before calling local api="+Authorization);
logger.info("Import url="+benImportUrlLocal);
logger.info("Response from benGenUrlCentral: " + response.getBody());
if (response != null && response.hasBody()) {
JSONObject obj = new JSONObject(response.getBody());
if (obj != null && obj.has("data") && obj.has("statusCode") && obj.getInt("statusCode") == 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public int downloadTransactionalData(int vanID, String ServerAuthorization, Stri
}
indentRepo.saveAll(indentList);

int updateFlag = updateProcessedFlagToCentral("db_iemr_sync", "t_indent", ids, ServerAuthorization, token);
int updateFlag = updateProcessedFlagToCentral("db_iemr", "t_indent", ids, ServerAuthorization, token);
}

break;
Expand All @@ -136,7 +136,7 @@ public int downloadTransactionalData(int vanID, String ServerAuthorization, Stri
indentOrder.setProcessed("P");
}
indentOrderRepo.saveAll(indentOrderList);
int updateFlag = updateProcessedFlagToCentral("db_iemr_sync", "t_indentorder", ids, ServerAuthorization, token);
int updateFlag = updateProcessedFlagToCentral("db_iemr", "t_indentorder", ids, ServerAuthorization, token);
}
break;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public int downloadTransactionalData(int vanID, String ServerAuthorization, Stri
}
indentIssueRepo.saveAll(indentIssueList);

int updateFlag = updateProcessedFlagToCentral("db_iemr_sync", "t_indentissue", ids, ServerAuthorization, token);
int updateFlag = updateProcessedFlagToCentral("db_iemr", "t_indentissue", ids, ServerAuthorization, token);
}
break;
}
Expand All @@ -191,7 +191,7 @@ public int downloadTransactionalData(int vanID, String ServerAuthorization, Stri
}
stockTransferRepo.saveAll(stockTransferList);

int updateFlag = updateProcessedFlagToCentral("db_iemr_sync", "t_stocktransfer", ids,
int updateFlag = updateProcessedFlagToCentral("db_iemr", "t_stocktransfer", ids,
ServerAuthorization, token);
}
break;
Expand Down Expand Up @@ -219,7 +219,7 @@ public int downloadTransactionalData(int vanID, String ServerAuthorization, Stri
}
itemStockEntryRepo.saveAll(itemStockEntryList);

int updateFlag = updateProcessedFlagToCentral("db_iemr_sync", "t_itemstockentry", ids,
int updateFlag = updateProcessedFlagToCentral("db_iemr", "t_itemstockentry", ids,
ServerAuthorization, token);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public class UploadDataToServerImpl implements UploadDataToServer {
private SyncUtilityClassRepo syncutilityClassRepo;
@Autowired
private CookieUtil cookieUtil;
boolean criticalTableFailure = false; // Add this flag

/**
*
Expand Down Expand Up @@ -242,19 +243,22 @@ private String startDataSync(int vanID, String user, String Authorization, Strin
}
}

// Determine table status based on success/failure counts
String tableStatus;
if (successfulRecords == totalRecords && failedRecords == 0) {
tableStatus = "success";
} else if (failedRecords == totalRecords && successfulRecords == 0) {
tableStatus = "failed";
groupHasFailures = true;
} else if (successfulRecords > 0 && failedRecords > 0) {
tableStatus = "partial";
} else {
tableStatus = "failed"; // Default to failed if unclear
groupHasFailures = true;
}
String tableStatus;

if (successfulRecords == totalRecords && failedRecords == 0) {
tableStatus = "success";
} else if (failedRecords == totalRecords && successfulRecords == 0) {
tableStatus = "failed";
criticalTableFailure = true; // Only critical failures stop sync
groupHasFailures = true;
} else if (successfulRecords > 0 && failedRecords > 0) {
tableStatus = "partial";
groupHasFailures = true; // Group has issues but don't stop sync
} else {
tableStatus = "failed";
criticalTableFailure = true; // Complete failure is critical
groupHasFailures = true;
}

// Create detailed table info with failure reasons
Map<String, Object> tableDetails = new HashMap<>();
Expand Down Expand Up @@ -289,11 +293,10 @@ private String startDataSync(int vanID, String user, String Authorization, Strin
tableDetailsList.add(tableDetails);
}

// If this table had critical failures, stop processing this group
if (tableHasError) {
hasSyncFailed = true;
break;
}
if (criticalTableFailure) {
hasSyncFailed = true;
break;
}
}
// Determine overall group status
String groupStatus;
Expand Down Expand Up @@ -438,6 +441,7 @@ public Map<String, Object> syncDataToServer(int vanID, String schemaName, String

String requestOBJ = gson.toJson(dataMap);
HttpEntity<Object> request = RestTemplateUtil.createRequestEntity(requestOBJ, Authorization, "datasync");
logger.info("Request to sync data: " + requestOBJ);
ResponseEntity<String> response = restTemplate.exchange(dataSyncUploadUrl, HttpMethod.POST, request,
String.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private JdbcTemplate getJdbcTemplate() {
"t_ncdscreening", "t_ncdcare", "i_ben_flow_outreach", "t_covid19", "t_idrsdetails", "t_physicalactivity",
"t_phy_generalexam", "t_phy_headtotoe", "t_sys_obstetric", "t_sys_gastrointestinal", "t_sys_cardiovascular",
"t_sys_respiratory", "t_sys_centralnervous", "t_sys_musculoskeletalsystem", "t_sys_genitourinarysystem",
"t_ancdiagnosis", "t_ncddiagnosis", "t_pncdiagnosis", "t_benchefcomplaint", "t_benclinicalobservation",
"t_ancdiagnosis", "t_ncddiagnosis", "t_pncdiagnosis", "t_benchiefcomplaint", "t_benclinicalobservation",
"t_prescription", "t_prescribeddrug", "t_lab_testorder", "t_benreferdetails",
"t_lab_testresult", "t_physicalstockentry", "t_patientissue", "t_facilityconsumption", "t_itemstockentry",
"t_itemstockexit", "t_benmedhistory", "t_femaleobstetrichistory", "t_benmenstrualdetails",
Expand Down
Loading