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

Dev #1235

Merged
merged 21 commits into from
Dec 13, 2024
Merged

Dev #1235

Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0e1092f
Hlm 6385 irs changes (#841)
kanishq-egov Aug 5, 2024
948e75a
Hcmpre 240 (#846)
kanishq-egov Aug 8, 2024
852e041
HLM rowmapper issue in household, referral fixed (#848)
kanishq-egov Aug 8, 2024
b41383e
added logic for cascading project date updates (#834)
nitish-egov Aug 8, 2024
3bef90b
HLM fixed issues in useraction existent entity validator (#850)
kanishq-egov Aug 9, 2024
af4b8ed
updated version for hcm v1.5 release (#852)
kanishq-egov Aug 12, 2024
2705fed
Hcmpre 309 rebase (#857)
kanishq-egov Aug 19, 2024
f99475a
HCMPRE-169 code review comments (#835)
Priyanka-eGov Sep 5, 2024
1ed7c59
HCMPRE-218 adding validation for plan config name (#844)
Priyanka-eGov Sep 5, 2024
6498f88
HCMPRE-646: added changes (#897)
kanishq-egov Sep 23, 2024
958201f
Update CODEOWNERS (#924)
kavi-egov Sep 30, 2024
de909f1
Hcmpre 639 shashwat changes (#919)
kanishq-egov Sep 30, 2024
1a73719
Fixed multiple role search in individual service (#992)
shashwat-egov Oct 16, 2024
caaf707
Hcmpre 639 shashwat changes (#973)
Shashwat12-egov Nov 6, 2024
46751ca
HCMPRE-371: Added service definition update api (#996)
yashita-egov Nov 11, 2024
e1cefd6
Update ValidatorUtil.java (#1112)
Shashwat12-egov Nov 13, 2024
9bba4d0
added-search-criterias-project-service (#1169)
nitish-egov Nov 25, 2024
26763cf
Service additional field (#1146)
Shashwat12-egov Dec 4, 2024
ff4c11b
Hcmpre 469 pagination all (#891)
kanishq-egov Dec 9, 2024
7d3c4cb
PR to develop branch for Microplanning v0.1 (changes in plan-service,…
Priyanka-eGov Dec 12, 2024
4c2631f
Merge branch 'master' into dev
kavi-egov Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @kavi-egov @sathishp-eGov
* @kavi-egov @sathishp-eGov @shashwat-egov
13 changes: 10 additions & 3 deletions build/build-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,22 @@ config:
dockerfile: "build/17/maven/Dockerfile"
- work-dir: "health-services/plan-service/src/main/resources/db"
image-name: "plan-service-db"
- name: "builds/health-campaign-services/health-services/resource-estimation-service"
- name: "builds/health-campaign-services/health-services/resource-generator"
build:
- work-dir: "health-services/resource-estimation-service"
image-name: "resource-estimation-service"
- work-dir: "health-services/resource-generator"
image-name: "resource-generator"
dockerfile: "build/17/maven/Dockerfile"
- name: "builds/health-campaign-services/analytics/auth-proxy"
build:
- work-dir: "analytics/auth-proxy"
image-name: "auth-proxy"
- name: "builds/health-campaign-services/health-services/census-service"
build:
- work-dir: "health-services/census-service"
image-name: "census-service"
dockerfile: "build/17/maven/Dockerfile"
- work-dir: "health-services/census-service/src/main/resources/db"
image-name: "census-service-db"

# frontend
- name: builds/health-campaign-services/frontend/workbench-ui
Expand Down
2 changes: 1 addition & 1 deletion core-services/service-request/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>9.22.3</version>
<!-- <version>9.22.3</version>-->
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public MappingJackson2HttpMessageConverter jacksonConverter(ObjectMapper objectM
@Value("${egov.service.definition.create.topic}")
private String serviceDefinitionCreateTopic;

@Value("${egov.service.definition.update.topic}")
private String serviceDefinitionUpdateTopic;

@Value("${egov.service.create.topic}")
private String serviceCreateTopic;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.egov.servicerequest.error;

import org.springframework.stereotype.Component;
import org.apache.kafka.common.protocol.types.Field;

@Component
public class ErrorCode {
Expand Down Expand Up @@ -30,6 +31,8 @@ public class ErrorCode {

public static final String SERVICE_REQUEST_ATTRIBUTE_INVALID_MULTI_VALUE_LIST_VALUE_MSG = "Attribute Value provided against the attribute definition of type multi value list must be an instance of list";

public static final String SERVICE_REQUEST_ATTRIBUTE_INVALID_BOOLEAN_VALUE_MSG = "Attribute Value provided against the attribute definition of type boolean must be an instance of boolean";

public static final String INVALID_SIZE_OF_INPUT_CODE = "INVALID_SIZE_OF_INPUT_CODE";

public static final String INVALID_SIZE_OF_TEXT_MSG = "Text value cannot be of length greater than configured length ";
Expand Down Expand Up @@ -61,4 +64,17 @@ public class ErrorCode {
public static final String INVALID_REGEX_ERR_CODE = "INVALID_REGEX_ERR_CODE";

public static final String INVALID_REGEX_ERR_MSG = "The provided regex failed to compile for attribute definition with code - ";

public static final String SERVICE_DEFINITION_NOT_EXIST_ERR_CODE = "SERVICE_DEFINITION_NOT_EXIST_ERR_CODE";

public static final String SERVICE_DEFINITION_NOT_EXIST_ERR_MSG = "Provided tenantId and code unique combination does not exist";

public static final String VALID_SERVICE_EXIST_ERR_CODE = "VALID_SERVICE_EXIST_ERR_CODE";

public static final String VALID_SERVICE_EXIST_ERR_MSG = "Valid Service exists corresponding to Service Definition";

public static final String INACTIVE_SERVICE_DEFINITION_ERR_CODE = "INACTIVE_SERVICE_DEFINITION_ERR_CODE";

public static final String INACTIVE_SERVICE_DEFINITION_ERR_MSG = "Inactive Service Definition cannot be updated";

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public String getServiceDefinitionsIdsQuery(ServiceDefinitionSearchRequest servi
}

// Fetch service definitions which have NOT been soft deleted
addClauseIfRequired(query, preparedStmtList);
query.append(" sd.isActive = ? ");
preparedStmtList.add(Boolean.TRUE);
if(!serviceDefinitionSearchRequest.isIncludeDeleted()){
addClauseIfRequired(query, preparedStmtList);
query.append(" sd.isActive = ? ");
preparedStmtList.add(Boolean.TRUE);
}

// order service definitions based on their createdtime in latest first manner
query.append(ORDERBY_CREATEDTIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ public List<ServiceDefinition> searchServiceDefinition(ServiceDefinitionSearchRe

public ServiceDefinition updateServiceDefinition(ServiceDefinitionRequest serviceDefinitionRequest) {

// TO DO
ServiceDefinition serviceDefinition = serviceDefinitionRequest.getServiceDefinition();

//Validate incoming service definition request
ServiceDefinition definitionFromDb = serviceDefinitionRequestValidator.validateUpdateRequest(serviceDefinitionRequest);

//Enrich incoming service definition request
enrichmentService.enrichServiceDefinitionUpdateRequest(serviceDefinitionRequest, definitionFromDb);

// Producer statement to emit service definition to kafka for persisting
producer.push(config.getServiceDefinitionUpdateTopic(), serviceDefinitionRequest);

// Restore attribute values to the type in which it was sent in service definition request
enrichmentService.setAttributeDefinitionValuesBackToNativeState(serviceDefinition);

return serviceDefinitionRequest.getServiceDefinition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

@Component
public class ServiceRequestEnrichmentService {
Expand Down Expand Up @@ -110,4 +111,68 @@ public void setAttributeValuesBackToNativeState(ServiceRequest serviceRequest, M
attributeValue.setValue(attributeCodeVsValueMap.get(attributeValue.getAttributeCode()));
});
}

private void updateAttributeDefinition(AttributeDefinition attributeDefinition, AttributeDefinition existingAttributeDefinition, RequestInfo requestInfo){

attributeDefinition.setId(existingAttributeDefinition.getId());

attributeDefinition.setAuditDetails(existingAttributeDefinition.getAuditDetails());

attributeDefinition.setReferenceId(existingAttributeDefinition.getReferenceId());

attributeDefinition.getAuditDetails().setLastModifiedTime(System.currentTimeMillis());

attributeDefinition.getAuditDetails().setLastModifiedBy(requestInfo.getUserInfo().getUuid());

}
private void upsertAttributeDefinition(AttributeDefinition attributeDefinition, ServiceDefinitionRequest serviceDefinitionRequest){
RequestInfo requestInfo = serviceDefinitionRequest.getRequestInfo();

attributeDefinition.setId(UUID.randomUUID().toString());

attributeDefinition.setAuditDetails(
AuditDetails.builder()
.createdBy(requestInfo.getUserInfo().getUuid())
.createdTime(System.currentTimeMillis())
.lastModifiedBy(requestInfo.getUserInfo().getUuid())
.lastModifiedTime(System.currentTimeMillis())
.build()
);

attributeDefinition.setReferenceId(serviceDefinitionRequest.getServiceDefinition().getId());
}
public void enrichServiceDefinitionUpdateRequest(ServiceDefinitionRequest serviceDefinitionRequest, ServiceDefinition definitionFromDb) {
List<AttributeDefinition> attributeDefinitions = serviceDefinitionRequest.getServiceDefinition().getAttributes();

//For quick lookup of Attribute Definition with Code
Map<String,AttributeDefinition> existingAttributeCode = definitionFromDb
.getAttributes()
.stream()
.collect(Collectors.toMap(AttributeDefinition::getCode, a->a));

RequestInfo requestInfo = serviceDefinitionRequest.getRequestInfo();

ServiceDefinition serviceDefinition = serviceDefinitionRequest.getServiceDefinition();

serviceDefinition.setId(definitionFromDb.getId());
serviceDefinition.setAuditDetails(definitionFromDb.getAuditDetails());
serviceDefinition.getAuditDetails().setLastModifiedBy(requestInfo.getUserInfo().getUuid());
serviceDefinition.getAuditDetails().setLastModifiedTime(System.currentTimeMillis());

attributeDefinitions.forEach(attributeDefinition -> {
if(existingAttributeCode.containsKey(attributeDefinition.getCode())){
updateAttributeDefinition(attributeDefinition, existingAttributeCode.get(attributeDefinition.getCode()), requestInfo);
}
else{
upsertAttributeDefinition(attributeDefinition, serviceDefinitionRequest);
}

if(!(attributeDefinition.getDataType().equals(AttributeDefinition.DataTypeEnum.SINGLEVALUELIST) || attributeDefinition.getDataType().equals(AttributeDefinition.DataTypeEnum.MULTIVALUELIST))){
List<String> emptyStringList = new ArrayList<>();
emptyStringList.add("");
attributeDefinition.setValues(emptyStringList);
}
});

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.egov.servicerequest.validators;

import org.egov.servicerequest.repository.ServiceDefinitionRequestRepository;
import org.egov.servicerequest.web.models.AttributeDefinition;
import org.egov.servicerequest.web.models.ServiceDefinition;
import org.egov.servicerequest.web.models.ServiceDefinitionCriteria;
import org.egov.servicerequest.web.models.ServiceDefinitionRequest;
import org.egov.servicerequest.web.models.ServiceDefinitionSearchRequest;
import org.egov.servicerequest.repository.ServiceRequestRepository;
import org.egov.servicerequest.web.models.*;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -18,21 +15,18 @@
import java.util.Set;
import java.util.regex.Pattern;

import static org.egov.servicerequest.error.ErrorCode.ATTRIBUTE_CODE_UNIQUENESS_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.ATTRIBUTE_CODE_UNIQUENESS_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.INVALID_ATTRIBUTE_DEFINITION_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.INVALID_ATTRIBUTE_DEFINITION_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.INVALID_REGEX_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.INVALID_REGEX_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_DEFINITION_ALREADY_EXISTS_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_DEFINITION_ALREADY_EXISTS_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.*;

@Component
public class ServiceDefinitionRequestValidator {

@Autowired
private ServiceDefinitionRequestRepository serviceDefinitionRequestRepository;

@Autowired
private ServiceRequestRepository serviceRequestRepository;


public void validateServiceDefinitionRequest(ServiceDefinitionRequest serviceDefinitionRequest){
ServiceDefinition serviceDefinition = serviceDefinitionRequest.getServiceDefinition();

Expand Down Expand Up @@ -87,16 +81,57 @@ private void validateAttributeDefinitionUniqueness(ServiceDefinition serviceDefi
}

private void validateServiceDefinitionExistence(ServiceDefinition serviceDefinition) {
List<ServiceDefinition> serviceDefinitionList = serviceDefinitionRequestRepository.getServiceDefinitions(ServiceDefinitionSearchRequest.builder().serviceDefinitionCriteria(ServiceDefinitionCriteria.builder().tenantId(serviceDefinition.getTenantId()).code(Collections.singletonList(serviceDefinition.getCode())).build()).build());
List<ServiceDefinition> serviceDefinitionList = serviceDefinitionRequestRepository.getServiceDefinitions(ServiceDefinitionSearchRequest.builder().includeDeleted(true).serviceDefinitionCriteria(ServiceDefinitionCriteria.builder().tenantId(serviceDefinition.getTenantId()).code(Collections.singletonList(serviceDefinition.getCode())).build()).build());
if(!CollectionUtils.isEmpty(serviceDefinitionList)){
throw new CustomException(SERVICE_DEFINITION_ALREADY_EXISTS_ERR_CODE, SERVICE_DEFINITION_ALREADY_EXISTS_ERR_MSG);
}
}

public void validateUpdateRequest(ServiceDefinitionRequest serviceDefinitionRequest) {
private List<ServiceDefinition> validateExistence(ServiceDefinition serviceDefinition) {
List<ServiceDefinition> serviceDefinitionList = serviceDefinitionRequestRepository.
getServiceDefinitions(ServiceDefinitionSearchRequest.builder()
.includeDeleted(true)
.serviceDefinitionCriteria(ServiceDefinitionCriteria.builder().tenantId(serviceDefinition.getTenantId()).code(Collections.singletonList(serviceDefinition.getCode())).build()).build());

//Check if valid service definition exists
if (CollectionUtils.isEmpty(serviceDefinitionList)) {
throw new CustomException(SERVICE_DEFINITION_NOT_EXIST_ERR_CODE, SERVICE_DEFINITION_NOT_EXIST_ERR_MSG);
}

return serviceDefinitionList;
}

private void validateService(List<ServiceDefinition> serviceDefinition){
List<Service> service = serviceRequestRepository.getService(
ServiceSearchRequest.builder().serviceCriteria(
ServiceCriteria.builder().serviceDefIds(Collections.singletonList(serviceDefinition.get(0).getId())).build()
).build()
);
//already a service exists corresponding to service definition
if(!CollectionUtils.isEmpty(service)){
throw new CustomException(VALID_SERVICE_EXIST_ERR_CODE, VALID_SERVICE_EXIST_ERR_MSG);
}
}

public ServiceDefinition validateUpdateRequest(ServiceDefinitionRequest serviceDefinitionRequest) {
ServiceDefinition serviceDefinition = serviceDefinitionRequest.getServiceDefinition();

//Validate if a Service Definition exists
List<ServiceDefinition> serviceDefinitionList = validateExistence(serviceDefinition);

//Validate if a Service exists corresponding to this Service Definition
validateService(serviceDefinitionList);

// Validate if all attribute definitions provided as part of service definitions have unique code
validateAttributeDefinitionUniqueness(serviceDefinition);

// TO DO
// Validate values provided in attribute definitions as per data type
validateAttributeValuesAsPerDataType(serviceDefinition);

// Validate regex values provided in attribute definitions
validateRegex(serviceDefinition);

return serviceDefinitionList.get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,7 @@
import java.util.Map;
import java.util.Set;

import static org.egov.servicerequest.error.ErrorCode.INVALID_SIZE_OF_INPUT_CODE;
import static org.egov.servicerequest.error.ErrorCode.INVALID_SIZE_OF_TEXT_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_DATETIME_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_MULTI_VALUE_LIST_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_NUMBER_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_SINGLE_VALUE_LIST_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_STRING_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_TEXT_VALUE_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_VALUE_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_VALUE_MULTIVALUELIST_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_INVALID_VALUE_SINGLEVALUELIST_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_VALUES_UNIQUENESS_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_ATTRIBUTE_VALUES_UNIQUENESS_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_INVALID_SERVICE_DEF_ID_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_INVALID_SERVICE_DEF_ID_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_REQUIRED_ATTRIBUTE_NOT_PROVIDED_ERR_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_REQUIRED_ATTRIBUTE_NOT_PROVIDED_ERR_MSG;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_UNRECOGNIZED_ATTRIBUTE_CODE;
import static org.egov.servicerequest.error.ErrorCode.SERVICE_REQUEST_UNRECOGNIZED_ATTRIBUTE_MSG;
import static org.egov.servicerequest.error.ErrorCode.*;

@Slf4j
@Component
Expand Down Expand Up @@ -133,6 +115,10 @@ private void validateAttributeValuesAgainstServiceDefinition(ServiceDefinition s
if(!(attributeValue.getValue() instanceof List)){
throw new CustomException(SERVICE_REQUEST_ATTRIBUTE_INVALID_VALUE_CODE, SERVICE_REQUEST_ATTRIBUTE_INVALID_MULTI_VALUE_LIST_VALUE_MSG);
}
}else if(attributeCodeVsDataType.get(attributeValue.getAttributeCode()).equals(AttributeDefinition.DataTypeEnum.BOOLEAN)){
if(!(attributeValue.getValue() instanceof Boolean)){
throw new CustomException(SERVICE_REQUEST_ATTRIBUTE_INVALID_VALUE_CODE, SERVICE_REQUEST_ATTRIBUTE_INVALID_BOOLEAN_VALUE_MSG);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AttributeDefinition {

@JsonProperty("code")
@NotNull
@Size(min = 2, max = 64)
@Size(min = 2, max = 256)
private String code = null;

/**
Expand All @@ -50,6 +50,8 @@ public class AttributeDefinition {
public enum DataTypeEnum {
STRING("String"),

BOOLEAN("Boolean"),

NUMBER("Number"),

TEXT("Text"),
Expand Down Expand Up @@ -110,7 +112,7 @@ public static DataTypeEnum fromValue(String text) {
@Valid
private AuditDetails auditDetails = null;

@JsonProperty("additionalDetails")
@JsonProperty("additionalFields")
private Object additionalDetails = null;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AttributeValue {
@Valid
private AuditDetails auditDetails = null;

@JsonProperty("additionalDetails")
@JsonProperty("additionalFields")
private Object additionalDetails = null;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Service {
@Valid
private AuditDetails auditDetails = null;

@JsonProperty("additionalDetails")
@JsonProperty("additionalFields")
private Object additionalDetails = null;

@JsonProperty("accountId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ServiceDefinition {

@JsonProperty("code")
@NotNull
@Size(min = 2, max = 64)
@Size(min = 2, max = 256)
private String code = null;

@JsonProperty("isActive")
Expand All @@ -50,7 +50,7 @@ public class ServiceDefinition {
@Valid
private AuditDetails auditDetails = null;

@JsonProperty("additionalDetails")
@JsonProperty("additionalFields")
private Object additionalDetails = null;

@JsonProperty("clientId")
Expand Down
Loading