Skip to content
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

hcm v1.5 : dev to master #855

Merged
merged 6 commits into from
Aug 12, 2024
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
2 changes: 1 addition & 1 deletion health-services/household/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.egov.common</groupId>
<artifactId>health-services-common</artifactId>
<version>1.0.17-SNAPSHOT</version>
<version>1.0.18-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.egov.common</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface Constants {

String INDIVIDUAL_ALREADY_MEMBER_OF_HOUSEHOLD = "INDIVIDUAL_ALREADY_MEMBER_OF_HOUSEHOLD";

String INDIVIDUAL_ALREADY_MEMBER_OF_HOUSEHOLD_MESSAGE = "individual is already member od household";
String INDIVIDUAL_ALREADY_MEMBER_OF_HOUSEHOLD_MESSAGE = "individual is already member of household";

String INDIVIDUAL_NOT_FOUND = "INDIVIDUAL_NOT_FOUND";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import static org.egov.common.utils.CommonUtils.getIdFieldName;
import static org.egov.common.utils.CommonUtils.notHavingErrors;
import static org.egov.common.utils.CommonUtils.populateErrorDetails;
import static org.egov.common.utils.ValidatorUtils.getErrorForUniqueEntity;
Expand Down Expand Up @@ -45,39 +45,52 @@ public HmExistentEntityValidator(HouseholdMemberRepository householdMemberReposi

/**
* Validates the existence of entities with the given client reference IDs.
* This method checks if any of the HouseholdMember entities in the request already exist in the database,
* based on their client reference IDs. If an entity is found to exist, an error is added to the error details map.
*
* @param request The bulk request containing HouseholdMember entities.
* @return A map containing HouseholdMember entities and their associated error details.
* @return A map containing HouseholdMember entities and their associated error details, if any.
*/
@Override
public Map<HouseholdMember, List<Error>> validate(HouseholdMemberBulkRequest request) {
// Map to hold HouseholdMember entities and their error details
// Map to hold HouseholdMember entities and their associated error details
Map<HouseholdMember, List<Error>> errorDetailsMap = new HashMap<>();

// Get the list of HouseholdMember entities from the request
List<HouseholdMember> entities = request.getHouseholdMembers();
// Extract client reference IDs from HouseholdMember entities without errors

// Extract client reference IDs from HouseholdMember entities that do not have errors
List<String> clientReferenceIdList = entities.stream()
.filter(notHavingErrors())
.map(HouseholdMember::getClientReferenceId)
.collect(Collectors.toList());
.filter(notHavingErrors()) // Filter out entities that already have errors
.map(HouseholdMember::getClientReferenceId) // Map to client reference IDs
.collect(Collectors.toList()); // Collect the IDs into a list

// Create a search object for querying entities by client reference IDs
HouseholdMemberSearch householdSearch = HouseholdMemberSearch.builder()
.clientReferenceId(clientReferenceIdList)
.clientReferenceId(clientReferenceIdList) // Set the client reference IDs for the search
.build();
// Check if the client reference ID list is not empty

// Create a map of client reference ID to HouseholdMember entity for easy lookup
Map<String, HouseholdMember> map = entities.stream()
.filter(entity -> StringUtils.hasText(entity.getClientReferenceId())) // Ensure client reference ID is not empty
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity)); // Collect to a map

// Check if the client reference ID list is not empty before querying the database
if (!CollectionUtils.isEmpty(clientReferenceIdList)) {
// Query the repository to find existing entities by client reference IDs
List<HouseholdMember> existentEntities = householdMemberRepository.findById(
clientReferenceIdList,
getIdFieldName(householdSearch),
Boolean.FALSE).getResponse();
// For each existing entity, populate error details for uniqueness
existentEntities.forEach(entity -> {
List<String> existingClientReferenceIds =
householdMemberRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);

// For each existing client reference ID, populate error details for uniqueness
existingClientReferenceIds.forEach(clientReferenceId -> {
// Get a predefined error object for unique entity validation
Error error = getErrorForUniqueEntity();
populateErrorDetails(entity, error, errorDetailsMap);
// Populate error details for the HouseholdMember entity associated with the client reference ID
populateErrorDetails(map.get(clientReferenceId), error, errorDetailsMap);
});
}

// Return the map containing HouseholdMember entities and their associated error details
return errorDetailsMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import static org.egov.common.utils.CommonUtils.getIdFieldName;
import static org.egov.common.utils.CommonUtils.notHavingErrors;
import static org.egov.common.utils.CommonUtils.populateErrorDetails;
import static org.egov.common.utils.ValidatorUtils.getErrorForUniqueEntity;

/**
* Validator class for checking the existence of entities with the given client reference IDs.
* This validator checks if the provided household entities already exist in the database based on their client reference IDs.
*
* @author kanishq-egov
*/
@Component
Expand All @@ -44,38 +45,52 @@ public HExistentEntityValidator(HouseholdRepository householdRepository) {

/**
* Validates the existence of entities with the given client reference IDs.
* This method checks if any of the household entities in the request already exist in the database,
* based on their client reference IDs. If an entity is found to exist, an error is added to the error details map.
*
* @param request The bulk request containing household entities.
* @return A map containing household entities and their associated error details.
* @return A map containing household entities and their associated error details, if any.
*/
@Override
public Map<Household, List<Error>> validate(HouseholdBulkRequest request) {
// Map to hold household entities and their error details
// Map to hold household entities and their associated error details
Map<Household, List<Error>> errorDetailsMap = new HashMap<>();

// Get the list of household entities from the request
List<Household> entities = request.getHouseholds();
// Extract client reference IDs from household entities without errors

// Extract client reference IDs from household entities that do not have errors
List<String> clientReferenceIdList = entities.stream()
.filter(notHavingErrors())
.map(Household::getClientReferenceId)
.collect(Collectors.toList());
.filter(notHavingErrors()) // Filter out entities that already have errors
.map(Household::getClientReferenceId) // Map to client reference IDs
.collect(Collectors.toList()); // Collect the IDs into a list

// Create a map of client reference ID to Household entity for easy lookup
Map<String, Household> map = entities.stream()
.filter(entity -> StringUtils.hasText(entity.getClientReferenceId())) // Ensure client reference ID is not empty
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity)); // Collect to a map

// Create a search object for querying entities by client reference IDs
HouseholdSearch householdSearch = HouseholdSearch.builder()
.clientReferenceId(clientReferenceIdList)
.clientReferenceId(clientReferenceIdList) // Set the client reference IDs for the search
.build();
// Check if the client reference ID list is not empty

// Check if the client reference ID list is not empty before querying the database
if (!CollectionUtils.isEmpty(clientReferenceIdList)) {
// Query the repository to find existing entities by client reference IDs
List<Household> existentEntities = householdRepository.findById(
clientReferenceIdList,
getIdFieldName(householdSearch),
Boolean.FALSE).getResponse();
// For each existing entity, populate error details for uniqueness
existentEntities.forEach(entity -> {
List<String> existingClientReferenceIds =
householdRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);

// For each existing client reference ID, populate error details for uniqueness
existingClientReferenceIds.forEach(clientReferenceId -> {
// Get a predefined error object for unique entity validation
Error error = getErrorForUniqueEntity();
populateErrorDetails(entity, error, errorDetailsMap);
// Populate error details for the household entity associated with the client reference ID
populateErrorDetails(map.get(clientReferenceId), error, errorDetailsMap);
});
}

// Return the map containing household entities and their associated error details
return errorDetailsMap;
}

Expand Down
2 changes: 1 addition & 1 deletion health-services/individual/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>org.egov.common</groupId>
<artifactId>health-services-common</artifactId>
<version>1.0.17-SNAPSHOT</version>
<version>1.0.18-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.egov.common</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import static org.egov.common.utils.CommonUtils.getIdFieldName;
import static org.egov.common.utils.CommonUtils.notHavingErrors;
import static org.egov.common.utils.CommonUtils.populateErrorDetails;
import static org.egov.common.utils.ValidatorUtils.getErrorForUniqueEntity;

/**
* Validator class for checking the existence of entities with the given client reference IDs.
* This validator checks if the provided individual entities already exist in the database based on their client reference IDs.
*
* @author kanishq-egov
*/
@Component
Expand All @@ -44,40 +45,53 @@ public IExistentEntityValidator(IndividualRepository individualRepository) {

/**
* Validates the existence of entities with the given client reference IDs.
* This method checks if any of the individual entities in the request already exist in the database,
* based on their client reference IDs. If an entity is found to exist, an error is added to the error details map.
*
* @param request The bulk request containing individual entities.
* @return A map containing individual entities and their associated error details.
* @return A map containing individual entities and their associated error details, if any.
*/
@Override
public Map<Individual, List<Error>> validate(IndividualBulkRequest request) {
// Map to hold individual entities and their error details
// Map to hold individual entities and their associated error details
Map<Individual, List<Error>> errorDetailsMap = new HashMap<>();

// Get the list of individual entities from the request
List<Individual> entities = request.getIndividuals();
// Extract client reference IDs from individual entities without errors

// Extract client reference IDs from individual entities that do not have errors
List<String> clientReferenceIdList = entities.stream()
.filter(notHavingErrors())
.map(Individual::getClientReferenceId)
.collect(Collectors.toList());
.filter(notHavingErrors()) // Filter out entities that already have errors
.map(Individual::getClientReferenceId) // Map to client reference IDs
.collect(Collectors.toList()); // Collect the IDs into a list

// Create a map of client reference ID to Individual entity for easy lookup
Map<String, Individual> map = entities.stream()
.filter(entity -> StringUtils.hasText(entity.getClientReferenceId())) // Ensure client reference ID is not empty
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity)); // Collect to a map

// Create a search object for querying entities by client reference IDs
IndividualSearch individualSearch = IndividualSearch.builder()
.clientReferenceId(clientReferenceIdList)
.clientReferenceId(clientReferenceIdList) // Set the client reference IDs for the search
.build();
// Check if the client reference ID list is not empty

// Check if the client reference ID list is not empty before querying the database
if (!CollectionUtils.isEmpty(clientReferenceIdList)) {
// Query the repository to find existing entities by client reference IDs
List<Individual> existentEntities = individualRepository.findById(
clientReferenceIdList,
getIdFieldName(individualSearch),
Boolean.FALSE).getResponse();
// For each existing entity, populate error details for uniqueness
existentEntities.forEach(entity -> {
List<String> existingClientReferenceIds =
individualRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);

// For each existing client reference ID, populate error details for uniqueness
existingClientReferenceIds.forEach(clientReferenceId -> {
// Get a predefined error object for unique entity validation
Error error = getErrorForUniqueEntity();
populateErrorDetails(entity, error, errorDetailsMap);
// Populate error details for the individual entity associated with the client reference ID
populateErrorDetails(map.get(clientReferenceId), error, errorDetailsMap);
});
}

// Return the map containing individual entities and their associated error details
return errorDetailsMap;
}

}

67 changes: 0 additions & 67 deletions health-services/libraries/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
All notable changes to this module will be documented in this file.

## 1.0.18 - 2024-08-09
- Added validateClientReferenceIdsFromDB method to GenericRepository.

## 1.0.16 - 2024-05-29
- Introduced multiple reusable functions to streamline and simplify the codebase.
- Enhanced function modularity for better maintainability and readability.
Expand Down
2 changes: 1 addition & 1 deletion health-services/libraries/health-services-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>health-services-common</artifactId>
<packaging>jar</packaging>
<name>health-services-common</name>
<version>1.0.17-SNAPSHOT</version>
<version>1.0.18-SNAPSHOT</version>
<description>Shared classes among services</description>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,23 @@ public List<String> validateIds(List<String> idsToValidate, String columnName){
return validIds.stream().map((obj) -> (String) ReflectionUtils.invokeMethod(idMethod, obj))
.collect(Collectors.toList());
}

public List<String> validateClientReferenceIdsFromDB(List<String> clientReferenceIds, Boolean isDeletedKeyPresent) {
List<String> objFound = new ArrayList<>();

String query = null;

if(isDeletedKeyPresent) {
query = String.format("SELECT clientReferenceId FROM %s WHERE clientReferenceId IN (:ids) AND isDeleted = false", tableName);
} else {
query = String.format("SELECT clientReferenceId FROM %s WHERE clientReferenceId IN (:ids) ", tableName);
}

Map<String, Object> paramMap = new HashMap<>();
paramMap.put("ids", clientReferenceIds);

objFound.addAll(namedParameterJdbcTemplate.queryForList(query, paramMap, String.class));

return objFound;
}
}
Loading
Loading