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

updated version for hcm v1.5 release #852

Merged
merged 4 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-dev-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 @@ -45,40 +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();

// Create a map of client reference ID to HouseholdMember entity for easy lookup
Map<String, HouseholdMember> map = entities.stream()
.filter(individual -> StringUtils.isEmpty(individual.getClientReferenceId()))
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity));
// Check if the client reference ID list is not empty
.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<String> existingClientReferenceIds =
householdMemberRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);
// For each existing entity, populate error details for uniqueness

// 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();
// 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 @@ -10,22 +10,21 @@
import org.egov.common.models.household.Household;
import org.egov.common.models.household.HouseholdBulkRequest;
import org.egov.common.models.household.HouseholdSearch;
import org.egov.common.models.individual.Individual;
import org.egov.common.validator.Validator;
import org.egov.household.repository.HouseholdRepository;
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 @@ -46,39 +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(individual -> StringUtils.isEmpty(individual.getClientReferenceId()))
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity));
.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<String> existingClientReferenceIds =
householdRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);
// For each existing entity, populate error details for uniqueness

// 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();
// 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-dev-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 @@ -17,14 +17,14 @@
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 @@ -45,41 +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(individual -> StringUtils.isEmpty(individual.getClientReferenceId()))
.collect(Collectors.toMap(entity -> entity.getClientReferenceId(), entity -> entity));
.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<String> existingClientReferenceIds =
individualRepository.validateClientReferenceIdsFromDB(clientReferenceIdList, Boolean.TRUE);
// For each existing entity, populate error details for uniqueness

// 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();
// 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;
}

}

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-dev-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
@@ -1,5 +1,11 @@
All notable changes to this module will be documented in this file.

## 1.0.21 - 2024-08-07
- Added UserActionEnum, UserAction Entities, TaskStatus enum
- Added isCascadingProjectDateUpdate in ProjectRequest model
- Removed status field from EgovModel


## 1.0.20 - 2024-05-29
- Added EgovModel, EgovSearchModel, EgovOfflineModel, EgovOfflineSearchModel
- Updated Lombok to 1.18.22 for SuperBuilder annotation support.
Expand Down
2 changes: 1 addition & 1 deletion health-services/libraries/health-services-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.egov.common</groupId>
<artifactId>health-services-models</artifactId>
<version>1.0.21-dev-SNAPSHOT</version>
<version>1.0.21-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,97 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* Enum representing the various possible statuses for a task.
* <p>
* Each status corresponds to a specific state of the task in the system.
* The status is stored as a string value and can be serialized/deserialized
* from JSON using Jackson annotations.
* </p>
*/
public enum TaskStatus {

/**
* Indicates that the task administration has failed.
* This status represents an error or issue encountered during
* the administrative process of the task.
*/
ADMINISTRATION_FAILED("ADMINISTRATION_FAILED"),

/**
* Indicates that the task administration was successful.
* This status signifies that the task has been processed correctly
* without any issues.
*/
ADMINISTRATION_SUCCESS("ADMINISTRATION_SUCCESS"),

/**
* Indicates that the beneficiary has refused the task.
* This status means that the individual or entity for whom the task
* was intended has declined to participate or accept it.
*/
BENEFICIARY_REFUSED("BENEFICIARY_REFUSED"),

/**
* Indicates that the household associated with the task has been closed.
* This status implies that the household is no longer active or
* relevant to the task, possibly due to its closure or other reasons.
*/
CLOSED_HOUSEHOLD("CLOSED_HOUSEHOLD"),

/**
* Indicates that the task has been delivered.
* This status shows that the task has been successfully completed
* and the deliverables have been provided.
*/
DELIVERED("DELIVERED"),

/**
* Indicates that the task has not been administered.
* This status signifies that the task has not been processed or
* handled yet.
*/
NOT_ADMINISTERED("NOT_ADMINISTERED");

// The string value associated with the task status.
private String value;

/**
* Constructor to initialize the TaskStatus with a specific string value.
*
* @param value The string value representing the task status.
*/
TaskStatus(String value) {
this.value = value;
}

/**
* Returns the string representation of the TaskStatus.
* This method is used for serialization of the enum value to JSON.
*
* @return The string value of the task status.
*/
@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}

/**
* Creates a TaskStatus enum from a string value.
* This method is used for deserialization of the enum value from JSON.
*
* @param text The string value representing the task status.
* @return The TaskStatus enum corresponding to the provided value,
* or null if no match is found.
*/
@JsonCreator
public static TaskStatus fromValue(String text) {
for (TaskStatus status : TaskStatus.values()) {
if (String.valueOf(status.value).equals(text)) {
return status;
}
}
return null;
return null; // Return null if no matching status is found
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UserAction extends EgovOfflineModel {
* It must be between 2 and 64 characters long and cannot be null.
*/
@JsonProperty("projectId")
@Size(min = 2, max = 64)
@Size(min = 2, max = 64, message = "Project ID must be between 2 and 64 characters")
@NotNull
private String projectId;

Expand Down
Loading
Loading