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 @@ -990,6 +990,8 @@ public String saveGeneratedBenIDToLocalServer(
logger.info("Number of unique benid imported to local server: " + i);
if (i > 0)
response.setResponse(i + " Unique benid imported to local server");
else if (!benIdImportDTOList.isEmpty())
response.setResponse("All benid already present in local server");
else {
response.setResponse("Empty or invalid data");
logger.error("Empty or invalid data. Data Size is : " + benIdImportDTOList.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ MBeneficiaryregidmapping findFirstByProviderServiceMapIDAndVehicalNoOrderByBenRe

Long countByProvisioned(Boolean isProvisioned);

/**
* Count of BenRegIds that can be given to a new registration: not provisioned
* and not claimed by a registration in progress.
*/
Long countByProvisionedAndReserved(Boolean isProvisioned, Boolean isReserved);

@Transactional
@Modifying
@Query("update MBeneficiaryregidmapping set providerServiceMapID = null , vehicalNo = null "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@

}

public int importBenIdToLocalServer(List<BenIdImportDTO> benIdImportDTOList) {

Check failure on line 2162 in src/main/java/com/iemr/common/identity/service/IdentityService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Identity-API&issues=AaE56u_RK5j0rxLulGA4&open=AaE56u_RK5j0rxLulGA4&pullRequest=206
logger.info("IdentityService.importBenIdToLocalServer - start");
logger.info("IdentityService.importBenIdToLocalServer - benIdImportDTOList size : "
+ (benIdImportDTOList == null ? "size:0" : benIdImportDTOList.size()));
Expand All @@ -2170,7 +2170,9 @@
jdbcTemplate = getJdbcTemplate();
List<Object[]> dataList = new ArrayList<>();
Object[] objArr;
String query = " INSERT INTO m_beneficiaryregidmapping(BenRegId, BeneficiaryID, "
// INSERT IGNORE: importing the same IDs again (retry after a failed or partial
// import) skips rows already present instead of failing the whole batch
String query = " INSERT IGNORE INTO m_beneficiaryregidmapping(BenRegId, BeneficiaryID, "
+ " Provisioned, CreatedDate, CreatedBy, Reserved, vanID) VALUES (?,?,?,?,?,?,?) ";
logger.info("query : " + query);
for (MBeneficiaryregidmapping obj : mBeneficiaryregidmappingList) {
Expand All @@ -2191,17 +2193,37 @@
logger.info("regid :" + obj.getBenRegId() + " - benid :" + obj.getBeneficiaryID());
}

// batched inserts do not report per-row results, so count the rows in this
// BenRegId range before and after to know how many were really added
java.math.BigInteger minId = null;
java.math.BigInteger maxId = null;
for (MBeneficiaryregidmapping obj : mBeneficiaryregidmappingList) {
java.math.BigInteger id = obj.getBenRegId();
if (id != null) {
minId = (minId == null || id.compareTo(minId) < 0) ? id : minId;
maxId = (maxId == null || id.compareTo(maxId) > 0) ? id : maxId;
}
}
String rangeCount = "SELECT COUNT(*) FROM m_beneficiaryregidmapping WHERE BenRegId BETWEEN ? AND ?";
Long before = minId == null ? 0L : jdbcTemplate.queryForObject(rangeCount, Long.class, minId, maxId);

int[] i = jdbcTemplate.batchUpdate(query, dataList);

return i.length;
Long after = minId == null ? 0L : jdbcTemplate.queryForObject(rangeCount, Long.class, minId, maxId);
int inserted = (int) (after - before);
logger.info("IdentityService.importBenIdToLocalServer - received " + i.length + ", newly inserted "
+ inserted + ", already present or skipped " + (i.length - inserted));

Check warning on line 2215 in src/main/java/com/iemr/common/identity/service/IdentityService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the built-in formatting to construct this argument.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Identity-API&issues=AaE56u_RK5j0rxLulGA3&open=AaE56u_RK5j0rxLulGA3&pullRequest=206

Check warning on line 2215 in src/main/java/com/iemr/common/identity/service/IdentityService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Identity-API&issues=AaE56u_RK5j0rxLulGA5&open=AaE56u_RK5j0rxLulGA5&pullRequest=206
return inserted;
} else {
return 0;
}

}

public Long checkBenIDAvailabilityLocal() {
return regIdRepo.countByProvisioned(false);
// Provisioned=false alone also counts rows claimed (Reserved=true) by a registration
// that never completed; those cannot be given to a new registration
return regIdRepo.countByProvisionedAndReserved(false, false);

}

Expand Down
Loading