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

Hcmpre 171: Save as draft for plan configuration #903

Merged
merged 14 commits into from
Oct 10, 2024
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package digit.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.egov.tracer.config.TracerConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
shashwat-egov marked this conversation as resolved.
Show resolved Hide resolved
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

@Component
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ public class ServiceConstants {
public static final String PROCESS_INSTANCE_NOT_FOUND_CODE = "PROCESS_INSTANCE_NOT_FOUND";
public static final String PROCESS_INSTANCE_NOT_FOUND_MESSAGE = "No process instance found with businessId: ";

public static final String FILES_NOT_FOUND_CODE = "FILES_NOT_FOUND";
public static final String FILES_NOT_FOUND_MESSAGE = "Files are not present in Plan Configuration.";

public static final String RESOURCE_MAPPING_NOT_FOUND_CODE = "RESOURCE_MAPPING_NOT_FOUND";
public static final String RESOURCE_MAPPING_NOT_FOUND_MESSAGE = "Resource mapping is not present in Plan Configuration.";

public static final String ASSUMPTIONS_NOT_FOUND_CODE = "ASSUMPTIONS_NOT_FOUND";
public static final String ASSUMPTIONS_NOT_FOUND_MESSAGE = "Assumptions are not present in Plan Configuration.";

public static final String OPERATIONS_NOT_FOUND_CODE = "OPERATIONS_NOT_FOUND";
public static final String OPERATIONS_NOT_FOUND_MESSAGE = "Operations are not present in Plan Configuration.";

//mdms constants
public static final String MDMS_PLAN_MODULE_NAME = "hcm-microplanning";
public static final String MDMS_ADMIN_CONSOLE_MODULE_NAME = "HCM-ADMIN-CONSOLE";
Expand Down Expand Up @@ -254,6 +266,8 @@ public class ServiceConstants {

public static final String DRAFT_STATUS = "DRAFT";

public static final String SETUP_COMPLETED_STATUS = "SETUP_COMPLETED";

//Query constants
public static final String PERCENTAGE_WILDCARD = "%";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ private String getPaginatedQuery(String query, PlanConfigurationSearchCriteria p

public void addActiveWhereClause(StringBuilder builder, List<Object> preparedStmtList) {
addClauseIfRequired(preparedStmtList, builder);
builder.append(" pcf.active = ?");
builder.append(" ( pcf.active = ? OR pcf.active IS NULL )");
tanishi-egov marked this conversation as resolved.
Show resolved Hide resolved
preparedStmtList.add(Boolean.TRUE);

addClauseIfRequired(preparedStmtList, builder);
builder.append(" pca.active = ?");
builder.append(" ( pca.active = ? OR pca.active IS NULL )");
preparedStmtList.add(Boolean.TRUE);

addClauseIfRequired(preparedStmtList, builder);
builder.append(" pco.active = ?");
builder.append(" ( pco.active = ? OR pco.active IS NULL )");
preparedStmtList.add(Boolean.TRUE);

addClauseIfRequired(preparedStmtList, builder);
builder.append(" pcm.active = ?");
builder.append(" ( pcm.active = ? OR pcm.active IS NULL )");
preparedStmtList.add(Boolean.TRUE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<PlanConfiguration> extractData(ResultSet rs) throws SQLException, Da
planConfigEntry.setTenantId(rs.getString("plan_configuration_tenant_id"));
planConfigEntry.setName(rs.getString("plan_configuration_name"));
planConfigEntry.setCampaignId(rs.getString("plan_configuration_campaign_id"));
planConfigEntry.setStatus(PlanConfiguration.StatusEnum.valueOf(rs.getString("plan_configuration_status").toUpperCase()));
planConfigEntry.setStatus(rs.getString("plan_configuration_status").toUpperCase());
planConfigEntry.setAdditionalDetails(queryUtil.getAdditionalDetail((PGobject) rs.getObject("plan_configuration_additional_details")));
planConfigEntry.setAuditDetails(auditDetails);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package digit.repository.rowmapper;

import digit.util.CommonUtil;
import digit.util.QueryUtil;
import digit.web.models.*;
import org.egov.common.contract.models.AuditDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package digit.service;

import digit.config.Configuration;
import digit.kafka.Producer;
import digit.repository.PlanConfigurationRepository;
import digit.service.enrichment.EnrichmentService;
import digit.service.validator.PlanConfigurationValidator;
Expand All @@ -10,7 +8,9 @@
import digit.web.models.PlanConfigurationRequest;
import digit.web.models.PlanConfigurationResponse;
import digit.web.models.PlanConfigurationSearchRequest;

import java.util.Collections;

import lombok.extern.slf4j.Slf4j;
import org.egov.common.utils.ResponseInfoUtil;
import org.springframework.stereotype.Service;
Expand All @@ -19,12 +19,8 @@
@Slf4j
public class PlanConfigurationService {

private Producer producer;

private EnrichmentService enrichmentService;

private Configuration config;

private PlanConfigurationValidator validator;

private PlanConfigurationRepository repository;
Expand All @@ -33,11 +29,8 @@ public class PlanConfigurationService {

private WorkflowService workflowService;

public PlanConfigurationService(Producer producer, EnrichmentService enrichmentService, Configuration config
, PlanConfigurationValidator validator, PlanConfigurationRepository repository, ResponseInfoFactory responseInfoFactory, WorkflowService workflowService) {
this.producer = producer;
public PlanConfigurationService(EnrichmentService enrichmentService, PlanConfigurationValidator validator, PlanConfigurationRepository repository, ResponseInfoFactory responseInfoFactory, WorkflowService workflowService) {
this.enrichmentService = enrichmentService;
this.config = config;
this.validator = validator;
this.repository = repository;
this.responseInfoFactory = responseInfoFactory;
Expand All @@ -46,6 +39,7 @@ public PlanConfigurationService(Producer producer, EnrichmentService enrichmentS

/**
* Creates a new plan configuration based on the provided request.
*
* @param request The request containing the plan configuration details.
* @return The created plan configuration request.
*/
Expand All @@ -54,32 +48,32 @@ public PlanConfigurationResponse create(PlanConfigurationRequest request) {
validator.validateCreate(request);
enrichmentService.enrichCreate(request);
repository.create(request);
PlanConfigurationResponse response = PlanConfigurationResponse.builder()

return PlanConfigurationResponse.builder()
.planConfiguration(Collections.singletonList(request.getPlanConfiguration()))
.responseInfo(responseInfoFactory
.createResponseInfoFromRequestInfo(request.getRequestInfo(), true))
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(request.getRequestInfo(), true))
.build();
return response;
}

/**
* Searches for plan configurations based on the provided search criteria.
*
* @param request The search request containing the criteria.
* @return A list of plan configurations that match the search criteria.
*/
public PlanConfigurationResponse search(PlanConfigurationSearchRequest request) {
validator.validateSearchRequest(request);
PlanConfigurationResponse response = PlanConfigurationResponse.builder().

return PlanConfigurationResponse.builder().
responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(request.getRequestInfo(), true))
.planConfiguration(repository.search(request.getPlanConfigurationSearchCriteria()))
.totalCount(repository.count(request.getPlanConfigurationSearchCriteria()))
.build();

return response;
}

/**
* Updates an existing plan configuration based on the provided request.
*
* @param request The request containing the updated plan configuration details.
* @return The response containing the updated plan configuration.
*/
Expand All @@ -89,7 +83,6 @@ public PlanConfigurationResponse update(PlanConfigurationRequest request) {
workflowService.invokeWorkflowForStatusUpdate(request);
repository.update(request);

// Build and return response back to controller
return PlanConfigurationResponse.builder()
.responseInfo(ResponseInfoUtil.createResponseInfoFromRequestInfo(request.getRequestInfo(), Boolean.TRUE))
.planConfiguration(Collections.singletonList(request.getPlanConfiguration()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private void validateActivitiesUuidUniqueness(PlanRequest request) {
/**
* This method validates if the plan id provided in the update request exists
*
* @param request
* @param request the PlanRequest containing the plan
*/
private void validatePlanExistence(PlanRequest request) {
// If plan id provided is invalid, throw an exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;

import static digit.config.ServiceConstants.DRAFT_STATUS;
import org.springframework.util.CollectionUtils;
import static org.egov.common.utils.AuditDetailsEnrichmentUtil.prepareAuditDetails;

import org.springframework.util.ObjectUtils;
Expand All @@ -30,6 +31,7 @@ public EnrichmentService(Configuration config) {
* Enriches the PlanConfigurationRequest for creating a new plan configuration.
* Enriches the given plan configuration with generated IDs for plan, files, assumptions, operations, and resource mappings,
* validates user information, and enriches audit details for create operation.
*
* @param request The PlanConfigurationRequest to be enriched.
* @throws CustomException if user information is missing in the request.
*/
Expand All @@ -44,69 +46,86 @@ public void enrichCreate(PlanConfigurationRequest request) {
UUIDEnrichmentUtil.enrichRandomUuid(planConfiguration, "id");

// Generate id for files
planConfiguration.getFiles().forEach(file -> {
UUIDEnrichmentUtil.enrichRandomUuid(file, "id");
enrichActiveForResourceMapping(file, planConfiguration.getResourceMapping());
});

if (!CollectionUtils.isEmpty(planConfiguration.getFiles())) {
planConfiguration.getFiles().forEach(file -> {
UUIDEnrichmentUtil.enrichRandomUuid(file, "id");
enrichActiveForResourceMapping(file, planConfiguration.getResourceMapping());
});
}

// Generate id for assumptions
planConfiguration.getAssumptions().forEach(assumption -> UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id"));
if (!CollectionUtils.isEmpty(planConfiguration.getAssumptions())) {
planConfiguration.getAssumptions().forEach(assumption -> UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id"));
}


// Generate id for operations
planConfiguration.getOperations().forEach(operation -> UUIDEnrichmentUtil.enrichRandomUuid(operation, "id"));
if (!CollectionUtils.isEmpty(planConfiguration.getOperations())) {
planConfiguration.getOperations().forEach(operation -> UUIDEnrichmentUtil.enrichRandomUuid(operation, "id"));
}

// Generate id for resource mappings
planConfiguration.getResourceMapping().forEach(resourceMapping -> UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id"));
if (!CollectionUtils.isEmpty(planConfiguration.getResourceMapping())) {
planConfiguration.getResourceMapping().forEach(resourceMapping -> UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id"));
}

planConfiguration.setAuditDetails(prepareAuditDetails(planConfiguration.getAuditDetails(), request.getRequestInfo(), Boolean.TRUE));
}

/**
* Enriches the PlanConfigurationRequest for updating an existing plan configuration.
* This method enriches the plan configuration for update, validates user information, and enriches audit details for update operation.
*
* @param request The PlanConfigurationRequest to be enriched.
* @throws CustomException if user information is missing in the request.
*/
public void enrichUpdate(PlanConfigurationRequest request) {
PlanConfiguration planConfiguration = request.getPlanConfiguration();

// Generate id for Files
planConfiguration.getFiles().forEach(file -> {
if (ObjectUtils.isEmpty(file.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(file, "id");
}
enrichActiveForResourceMapping(file, request.getPlanConfiguration().getResourceMapping());
});
if (!CollectionUtils.isEmpty(planConfiguration.getFiles())) {
planConfiguration.getFiles().forEach(file -> {
if (ObjectUtils.isEmpty(file.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(file, "id");
}
enrichActiveForResourceMapping(file, request.getPlanConfiguration().getResourceMapping());
});
}

// Generate id for Assumptions
planConfiguration.getAssumptions().forEach(assumption -> {
if (ObjectUtils.isEmpty(assumption.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id");
}
});
if (!CollectionUtils.isEmpty(planConfiguration.getAssumptions())) {
planConfiguration.getAssumptions().forEach(assumption -> {
if (ObjectUtils.isEmpty(assumption.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(assumption, "id");
}
});
}

// Generate id for Operations
planConfiguration.getOperations().forEach(operation -> {
if (ObjectUtils.isEmpty(operation.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(operation, "id");
}
});
if (!CollectionUtils.isEmpty(planConfiguration.getOperations())) {
planConfiguration.getOperations().forEach(operation -> {
if (ObjectUtils.isEmpty(operation.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(operation, "id");
}
});
}

// Generate id for ResourceMappings
planConfiguration.getResourceMapping().forEach(resourceMapping -> {
if (ObjectUtils.isEmpty(resourceMapping.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id");
}
});
if (!CollectionUtils.isEmpty(planConfiguration.getResourceMapping())) {
planConfiguration.getResourceMapping().forEach(resourceMapping -> {
if (ObjectUtils.isEmpty(resourceMapping.getId())) {
UUIDEnrichmentUtil.enrichRandomUuid(resourceMapping, "id");
}
});
}

planConfiguration.setAuditDetails(prepareAuditDetails(request.getPlanConfiguration().getAuditDetails(), request.getRequestInfo(), Boolean.FALSE));
}

/**
* Sets all corresponding resource mappings to inactive if the given file is inactive.
*
* @param file the file object which may be inactive
* @param file the file object which may be inactive
* @param resourceMappings the list of resource mappings to update
*/
public void enrichActiveForResourceMapping(File file, List<ResourceMapping> resourceMappings) {
Expand All @@ -125,34 +144,41 @@ public void enrichActiveForResourceMapping(File file, List<ResourceMapping> reso
*
* @param request the plan configuration request containing the plan configuration to be enriched
*/
public void enrichPlanConfigurationBeforeValidation(PlanConfigurationRequest request)
{
public void enrichPlanConfigurationBeforeValidation(PlanConfigurationRequest request) {
PlanConfiguration planConfiguration = request.getPlanConfiguration();

// For Files, Operations, Assumptions and Resource Mappings override active to be True
planConfiguration.getFiles().forEach(file -> {
if (ObjectUtils.isEmpty(file.getId())) {
file.setActive(Boolean.TRUE);
}
});

planConfiguration.getOperations().forEach(operation -> {
if (ObjectUtils.isEmpty(operation.getId())) {
operation.setActive(Boolean.TRUE);
}
});

planConfiguration.getAssumptions().forEach(assumption -> {
if (ObjectUtils.isEmpty(assumption.getId())) {
assumption.setActive(Boolean.TRUE);
}
});

planConfiguration.getResourceMapping().forEach(resourceMapping -> {
if (ObjectUtils.isEmpty(resourceMapping.getId())) {
resourceMapping.setActive(Boolean.TRUE);
}
});
if (!CollectionUtils.isEmpty(planConfiguration.getFiles())) {
planConfiguration.getFiles().forEach(file -> {
if (ObjectUtils.isEmpty(file.getId())) {
file.setActive(Boolean.TRUE);
}
});
}

if (!CollectionUtils.isEmpty(planConfiguration.getOperations())) {
planConfiguration.getOperations().forEach(operation -> {
if (ObjectUtils.isEmpty(operation.getId())) {
operation.setActive(Boolean.TRUE);
}
});
}

if (!CollectionUtils.isEmpty(planConfiguration.getAssumptions())) {
planConfiguration.getAssumptions().forEach(assumption -> {
if (ObjectUtils.isEmpty(assumption.getId())) {
assumption.setActive(Boolean.TRUE);
}
});
}

if (!CollectionUtils.isEmpty(planConfiguration.getResourceMapping())) {
planConfiguration.getResourceMapping().forEach(resourceMapping -> {
if (ObjectUtils.isEmpty(resourceMapping.getId())) {
resourceMapping.setActive(Boolean.TRUE);
}
});
}
}

}
Loading